A guide to understanding Searchify's supported query format
All the examples in this page use an index composed of the following documents:
documentA = { "text" : "Hello world. I'm the content of the 'text' field. It's the default field for queries.", "city" : "San Francisco, CA", "author" : "Java Power Coder" } documentB = { "text" : "Good morning! The default field of this document contains 'tea'.", "city" : "London, UK", "author" : "World Class Developer" } documentC = { "text" : "Goodbye world. This is the default field of the last document.", "city" : "San Diego, CA", "author" : "PHP Power Coder" }
There are two types of basic queries: Terms and Phrases. A Term is a single word such as "hello" or "world". For example:
hellowill match:
documentAand
worldwill match:
documentA, documentC
A Phrase is a group of words by double quotes such as "hello world". Documents matching phrase queries will contain the exact phrase.
For example:"hello world"will match:
documentAand
"default field"will match:
documentA, documentB, documentC
By default, all basic queries are executed against the text field of the indexed documents. It's possible to select a different field, by prefixing a basic query with a field name.
For example:author:worldwill match:
documentBand
author:"power coder"will match:
documentA, documentC
You can combine basic queries with Boolean operators to form a more complex query. Boolean operators define the relationships between Terms or Phrases. Searchify supports the following Boolean operators: AND, "+", OR, NOT and "-". Please note that Boolean operators must be all uppercase.
This is the default operator. It will be used if there is no Boolean operator between two terms. For example:
default documentis the same as
default AND documentand will match:
documentB, documentC
This operator makes its surrounding terms optional, but at least one must match the document. For example:
hello OR lastwill match:
documentA, documentC
The NOT operator excludes documents that contain the term (or phrase) after NOT. For example:
world NOT contentwill match:
documentCand
world NOT "default field"will match:
documentAYou can use the NOT operator several times in the same query. For example:
world NOT content NOT author:coderwill not match any document.
# no documents matching
hello OR lastis the same as
last OR helloand will match the same documents,
documentA, documentCIf you need to modify precedence for complex queries, you can use parentheses. For example:
(good AND world) OR author:powerwill match:
documentA, documentCand
good AND (world OR author:power)will match:
documentC
You can also use parentheses to specify the field only once.
For example:author:(world class)is the same as:
author:world author:classand will match:
documentB
You can boost terms in a query by appending the caret operator at the end of a term. Example:
author:world^2 OR city:san^10This will match all documents, and documentC will be the last result.
You can perform "wildcard" or "prefix" queries using the '*' operator. For example:
text:goo*
This query will match all documents containing words beginning with the prefix 'goo' in the 'text' field. In this example, this query matches documentB and documentC, because documentB contains the word "Good" and documentC contains the word "Goodbye".