Comparison Operators
DQL supports many of the standard comparison operators found in most languages.
Contains (Colon)
The colon/contains operator matches one or more words to a field. For instance, this query will return articles whose title
contains the word "Apple":
This operator is case-insensitive, so title:"Apple"
can match "apple". In addition, this operator can match any part of the value, so title:"Apple"
can match "Apple Records". To perform a case-sensitive search that matches the entire value only, see the strict
operator.
You can repeat the field in your query to search for multiple words in the same field. For instance, name:"Apple" name:"Inc"
can match "Apple Inc", "Inc Apple", and "Apple and Google Inc".
To narrow the results, you can use "Apple Inc" as a phrase:
type:Article title:"Apple Inc"
This is an approximate phrase search that allows for up to one additional word between each consecutive pair of words. So the query above will match "Apple Inc" as well as "Apple Computer Inc", but it won't match "Inc Apple" or "Apple and Google Inc".
This operator also expands queries targeting the field name
to allNames
. For instance, the query below will perform a โcontainsโ search against all names (allNames
) associated with an organization.
type:Organization name:"Facebook"
Try Regex for a much more flexible search operator
String fields are tokenized for efficient search. In some cases, your substring in a
contains
operator may not work. For these cases, try the Regex Operator.
Not Equals
The Not Equals operator !=
specifies that entities matching a particular field value should be omitted from the results.
This query returns all Organization entities in San Francisco, except for those companies whose name is "San Francisco State University":
This query returns all Organizations located in the city of San Francisco that are not local businesses:
type:Organization location.city.name:"San Francisco" types!="LocalBusiness"
The Not Equals operator can also be used with the regex operator. This query returns all Organizations whose name does not begin with "University":
type:Organization re:name!="University.*"
To exclude entities compiled from one or more data sources, i.e. origins, specify:
type:Organization origins!="wikidata.org" origins!="en.wikipedia.org"
The above example excludes all Organizations whose origins do not include Wikipedia or Wikidata.
Greater / Less Than (or Equal To)
We can apply the >
(greater than), <
(less than), >=
(greater than or equal to) and <=
(less than or equal to) operators to specify that the value of a field should fall within a particular range.
This query will match all Articles published to โ*.nytimes.*โ since Mar 1, 2022:
type:Article date>='2022-03-01' pageUrl:"nytimes" sortBy:date
This query will match companies who have between 500 and 1000 employees:
type:Organization nbEmployees>=500 nbEmployees<=1000
Strict Operator (Equals)
The strict operator modifies a text search on a field, so that the field value must be exactly equal to the search string in order for a match to occur.
We have seen in all of the examples above how the colon operator (:
) is used to match a field with a value, similar to the equals operator in most programming languages. It is important to note that the colon does not perform an exact match. It will account for a single missing word in the result. To perform an exact match you must apply the strict operator.
For example: To match only Facebook, and not Facebook affiliates:
Updated 8 months ago