Skip to main content
This how-to guide will show you how to filter search results to include only specific sources. This is implemented by leveraging both the search and knowledge_graph services. Below is a step by step example to search for content mentioning Amazon, but only focussing on sources from the United States with the highest source quality and a retention period higher than 1 year. First, let’s import the required dependencies and prepare the client:
Import required dependencies and prepare the client
Then, we need to query for a list of sources that match our criteria. In this case, we want sources from the United States, with a rank of RANK_1 (highest quality), and a retention period greater than 1 year. We can use the find_sources method to retrieve these sources:
Find the relevant sources based on the criteria
Once we have the sources, we can prepare a filter that matches any of the sources by joining them using the | operator.
Prepare the source filter for the query
Then we need to create the final query that matches the entity of Amazon and (&) the source filter we just created:
Prepare the final filter for the query
Finally, run the query to get the results (limited to 5 results for demonstration purposes):
Run the desired query
Output