Search syntax

  Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic! Mail us feedback on this topic!  

A detailed description of Lucene query parser syntax can be found at http://lucene.apache.org/java/2_1_0/queryparsersyntax.html.

 

Based on the level of allowed syntax specified by the Search options property of Smart search dialog with results or Smart search results web parts, users can enter search queries with restriction as described below:

 

Basic - all Lucene search query syntax (as described on the page linked above) will be recognized except for field searching.
None - no query syntax will be recognized. All text entered by users will be processed as a part of the searched for expression.
Full - all search query syntax will be processed, including field searching.

 

Field search

 

By default, field searching can only be used to define an additional condition in a search expression. All conditions must start with either the + or - symbol. The + symbol indicates that only results which fulfill the field condition should be returned. The - symbol has the opposite meaning, only results that do not contain the specified value in the given field will be retrieved.

 

For example:

 

network +NewsReleaseDate:[20080101 TO 20091231]

 

When searching for this expression using a document index, only news documents containing the word network, released in the year 2008 or 2009 will be returned.

 

If you wish to allow direct field searches, you must add the following key into the /configuration/appSettings section of your web.config file:

 

<add key="CMSSearchOnlyWhenContentPresent" value="false" />

 

Once this is done, expressions containing only search syntax can be used. This allows users to find records directly by entering an exact field value:

 

DocumentNodeID:(int)17 - the document with a nodeID equal to 17 will be returned.
NewsTitle:"New features" - the news document titled New features will be returned.

 

Keep in mind that only fields that are set as Searchable in the field configuration of the given object type may be included in field searches. Information about the search field configuration of objects can be found in the Settings for particular object types topic.

 

Searching numeric fields

 

When performing field searches, the values specified are understood as strings by default. If you know that you are searching in integer or double fields, you will need to specify the type of the field the following way:

 

NewsID:(int)22
SKUPrice:(double)255.0
DocumentNodeID:[(int)1 TO (int)100]

 

Searching date and time fields

 

Due to the same reason, search in DateTime fields also requires special syntax in format <field name>:yyyymmddhhmm. So for example:

 

DocumentCreatedWhen:200812230101
DocumentCreatedWhen:[200902020101 TO 200906020101]

 

If you need to specify date and time using a macro, you will need to use the (tosearchdatetime) parameter to convert the returned value to a format suitable for Lucene.

 

{%CurrentDateTime|(tosearchdatetime)%}

 

You can also use the (add) parameter, which adds the specified amount of minutes to the value.

 

{%CurrentDateTime|(add)-1440|(tosearchdatetime)%}

 

Field search with Stop and Simple analyzers

 

Indexes created by Stop and Simple analyzers cannot be searched using the standard field search format. This is by design, but you can use a workaround with a range query containing identical boundaries:

 

newsid:[(int)22 TO (int)22]

 

Page url: http://devnet.kentico.com/docs/5_5r2/devguide/index.html?smart_search_search_syntax.htm