Text Search Syntax
From n² wiki
Nearby: Platform API, Contentbox, Store Facet Service
Contents |
[edit] Terminology
A query is broken up into terms and operators. There are two types of terms: Single Terms and Phrases.
A Single Term is a single word such as test or hello
A Phrase is a group of words surrounded by double quotes such as "hello dolly".
Multiple terms can be combined together with Boolean operators to form a more complex query (see below).
[edit] Fielded and Unfielded Queries
The search api includes the concept of a QueryProfile. Each index has a default profile that is applied to unfielded queries. For example, Store A's default index may include Fields named title and publisher. It is possible to for queries to address these fields directly like so:
title:sleep publisher:vintage
This query will search for the value "sleep" in title field and the value "vintage" in publisher field. Unfielded terms can be directed at the index fields according to the default query profile. So, in the previous example, the default profile may include both title and publisher fields. In this case, a search like:
sleep vintage
would equate to one like this:
title:sleep title:vintage publisher:sleep publisher:
A field is only valid for the term that it directly precedes, so the query
title:Big Sleep
Will only find "Big" in the title field. It will use the query profile to determine how to direct the other terms in the query. In the example above, this would resolve to a query like:
title:Big title:Sleep publisher:Sleep
[edit] Wildcard Searches
The query syntax currently supports both multiple and single character wildcard searches.
To perform a single character wildcard search use the "?" symbol.
To perform a multiple character wildcard search use the "*" symbol.
The single character wildcard search looks for terms that match that with the single character replaced. For example, to search for "text" or "test" you can use the search:
te?t
Multiple character wildcard searches looks for 0 or more characters. For example, to search for test, tests or tester, you can use the search:
test*
You can also use the wildcard searches in the middle of a term.
test*
Note: You cannot use a * or ? symbol as the first character of a term. In addition, placing a wildcard too close to the start of a term may result in an a query error due to the current implementation of wildcard searches. If this happens, and where possible, make your query more specific by moving the wildcard further down the term.
[edit] Boolean Operators
Boolean operators allow terms to be combined. AND, "&&", "+", OR, "||", NOT and "-" are supported as Boolean operators.
[edit] OR, ||
title:"The Big Sleep" OR publisher:vintage
is equivalent to
publisher:vintage || title:"The Big Sleep"
[edit] AND, &&
AND is the default conjunction operator, meaning that queries with multiple terms are AND queries by default. The symbol && can be used in place of the word AND.
title:sleep AND author:Chandler
is equivalent to
title:sleep && author:Chandler
[edit] +
The "+" or required operator requires that the term after the "+" symbol exist somewhere
For example the query:
+title:big title:sleep
searches for items where the title must contain the term "big" and may contain the term "sleep"
[edit] NOT
The NOT operator excludes items that contain the term after NOT. The symbol ! can be used in place of the word NOT.
The query:
title:sleep NOT author:nolan
searches for items with the term "sleep" in the title field, excluding items with the term "nolan" in the author field
Note: The NOT operator cannot be used with just one term. For example, the following search will return no results:
NOT title:sharks
[edit] -
The "-" can also be used to exclude items that contain the term after the "-" symbol.
To search for items that contain (according to the store's default query profile) "sleep" but not "sharks" use the query:
"sleep" -"sharks"
[edit] Grouping
Query clauses can be grouped in order to control boolean logic and form sub queries.
(sleep OR goodbye) AND chandler
[edit] Escaping Special Characters
The current list special characters are
+ - && || ! ( ) " * ? : \
To escape these characters use the \ before the character. For example to search for http://example.com/things?id=foo:bar use the query:
http\://example.com/things\?id=foo\:bar

