Query syntax

Example dataset

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"
}
					

Basic Queries

There are two types of basic queries: Terms and Phrases. A Term is a single word such as "hello" or "world".

For example:

hello
					

will match:

documentA
					

and

world
					

will match:

documentA, documentC
					

Notice that documentB does not match, even when the field "author" contains world. See Specifying fields for queries for an explanation.

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 wold"
					

will match:

documentA
					

and

"default field"
					

will match:

documentA, documentB, documentC
					

Specifying fields for queries

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:world
					

will match:

documentB
					

and

author:"power coder"
					

will match:

documentA, documentC
					

Boolean Operators

You can combine basic queries with Boolean operators to form a more complex query. Boolean operators define the relationships between Terms or Phrases. IndexTank supports the following Boolean operators: AND, "+", OR, NOT and "-". Please note that Boolean operators must be all uppercase.

AND

This is the default operator. It will be used if there is no Boolean operator between two terms.

For example:

default document
					

is the same as

default AND document
					

and will match:

documentB, documentC
					

OR

This operator makes its surrounding terms optional, but at least one must match the document.

For example:

hello OR last
					

will match:

documentA, documentC
					

NOT

The NOT operator excludes documents that contain the term (or phrase) after NOT.

For example:

world NOT content
					

will match:

documentC
					

and

world NOT "default field"
					

will match:

documentA
					

You can use the NOT operator several times in the same query.

For example:

world NOT content NOT bye
					

will not match any document.

# no documents matching
					

IndexTank DOES NOT support queries that ONLY have NOT terms.

Precedence

The order in which you enter search terms does not effect your results. AND and OR operators have the same precedence and group from left to right.

For example:

hello OR last
					

is the same as

last OR hello
					

and will match the same documents,

documentA, documentC
					

If you need to modify precedence for complex queries, you can use parentheses.

For example:

(good AND world) OR author:power
					

will match:

documentA, documentC
					

and

good AND (world OR author:power)
					

will match:

documentC
					

Field Grouping

You can also use parentheses to specify the field only once.

For example:

author:(world class)
					

is the same as:

author:world author:class
					

and will match:

documentB
					

Fields Weights (caret operator)

You can boost fields in a query by appending the caret operator at the end of terms.

For example:

author:world^2 OR city:san^10
					

This will match all documents, and documentC will be the first result.

Fuzzy search (quorum operator)

With quorum operator you could match those documents that pass a given threshold of given words.

For example:

"the world is a wonderful place"/3
					

This will match all documents that have at least 3 of the 6 specified words.


Real Time Web Analytics