Constructing a Search Query

Search Query Elements

A search query consists of the following elements:

Terms

Terms are the words that you want your search results to include or exclude. A term could be one word (eg Electrician), or it can be a phrase (eg "Fitter and Turner"). When searching for phrases, you need to surround the group of words in double quotes. Omitting the double quotes, means that your search will return results that include ANY of the words in the phrase. The following search term examples illustrate this concept:

Every search query must include at least one term.

Fields

Fields are the 'columns' in the search index definition. Specifying a field in your search query lets you search a specific 'column' in the search index definition. To specify a field, type the field name followed by a colon (:), and then the term you are looking for. For example, if you want to search the 'Name' field for all documents that contain 'John', use the following search query:

Keep in mind that the field is only valid for the term that follows the colon. If you want to search a field for a phrase, be sure to include the group of words in double quotes.

Fields are optional.

Operators

Operators are used to combine or exclude terms to form more complex search queries. On Key Search supports the following search operators:

Operator

Description Example

AND

Used to return results that contain all of the specified terms. Example 1: To search for all documents that contain 'John' and 'Black', use the following search query:
  • John AND Black

Example 2: To search for all documents that contain 'John' in the Name field, and 'fitter and turner' in the Trade field, use the following search query:

  • Name:John AND Trade:"fitter and turner"

OR

Used to return results that contain any of the specified terms.
  
This is the default search operator. If you do not specify an operator between search terms, the OR operator will be used by default.
Example 1: To search for all documents that contain either 'John' or 'Black', use the following search query:
  • John Black

Example 2: To search for all documents that contain either 'John' in the Name field, or 'fitter and turner' in the Trade field, use the following search query:

  • Name:John Trade:"fitter and turner"

NOT

Used to exclude results that contain the specified terms. Example 1: To search for all documents that do not contain  'John', use the following search query:
  • NOT John

Example 2: To search for all documents that do not contain 'fitter and turner' in the Trade field, use the following search query:

  • NOT Trade:"fitter and turner"

+

Used to specify terms that the search results must contain. Example 1: To search for all documents that must contain 'John', use the following search query:
  • +John

Example 2: To search for all documents that must contain 'fitter and turner' in the Trade field, use the following search query:

  • +Trade:"fitter and turner"

-

Used to specify terms that the search results must not contain. Example 1: To search for all documents that do not contain 'John', use the following search query:
  • -John

Example 2: To search for all documents that do not contain 'fitter and turner' in the Trade field, use the following search query:

  • -Trade:"fitter and turner"

Grouping

 

On Key Search allows you to group terms and operators into clauses using parenthesis. This enables you to control the boolean logic in search queries that have multiple operators. For example, to search for either 'John' or 'Jack' and 'Electrician', use the following search query:

Search Term Modifiers

On Key Search supports the following search term modifiers:

Modifier Description Example

Wildcard

Used to substitute one or more characters in a single search term.
 
To substitute a single character, use the '?' wildcard. To substitute multiple characters, use the '*' wildcard.
Single character example: To search for documents that contain 'test' or 'text', use the following search query:
  • te?t

Multiple character example: To search for documents that contain 'test', 'tests', 'tester', or 'testing', use the following search query:

  • test*
Fuzzy Used to search for documents that contain values that are similar to the specified terms.
 
Fuzzy searches are based on the Levenshtein Distance, or Edit Distance algorithm.
To search for documents that contain terms that are similar in spelling to 'roam', use the following search query:
  • roam~
Proximity Used to search for two words that appear within a set amount of words from each other. To search for documents that contain 'this is a new test', 'this was the new test', or 'this will be new test', use the following search query:
  • "this test"~3
Range Used to return results where the values in a specific field are between specified upper and lower bounds.
 
Range searches can be inclusive or exclusive.
Inclusive example: To search for records where the value in the Quantity field is between and including 3 and 9, use the following search query:
  • Quantity:[3 TO 9]

Exclusive example: To search for records where the value in the Quantity field is between but excluding 3 and 9, use the following search query:

  • Quantity:{3 TO 9}
Boosting Used to increase the relevance of certain terms in a search query. Use the ^ symbol along with the boost factor next to the term.
 
The default boost factor is 1.
To search for records that contain 'John' or 'fitter and turner', and place more emphasis on the trade, use the following search query:
  • John "fitter and turner"^5