Kentico CMS 7.0 Developer's Guide

Search syntax

Search syntax

Previous topic Next topic Mail us feedback on this topic!  

Search syntax

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

A detailed description of Lucene query parser syntax can be found at http://lucene.apache.org/core/old_versioned_docs/versions/2_9_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 restrictions as described below:

 

Basic - all Lucene search query syntax (as described on the page linked above) are recognized except for field searching.

None - no query syntax is recognized. All text entered by users is processed as a part of the searched for expression.

Full - all search query syntax is processed, including field searching.

 

 

InfoBox_Note

 

Search syntax errors

 

If special search expressions are allowed by the Search options property, a parsing error occurs if a user enters the query syntax incorrectly.

 

By default, the standard "no results" message is shown to the user in this case, and the error is entered into the application's Event log. If you wish to have syntax errors displayed in place of the results directly on the live site, you can enable the Show parsing errors property of the given smart search results web part.

 

Field search

 

Field searching may be used to define additional conditions in search expressions. 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.

 

Keep in mind that only fields set as Searchable in the field configuration of the given object type may be included in field searches. If there is no field name specified before a value in the expression (such as the word network in the example above), the system will search the index fields marked as Content. Information about the search field configuration of objects can be found in the Settings for particular object types topic.

 

Additionally, field searches will only be processed correctly if the search dialog web part has its Search mode set to Any words.

 

Unless the web part used to display the search results has its Block field-only search property enabled, it is also possible to perform direct field searches without any standard content keywords. This allows users to find records simply by entering an exact field value:

 

DocumentNodeID:(int)17 - returns the document with a nodeID equal to 17.

NewsTitle:"New features" - returns the news document titled New features.

SKUDepartmentID:(int)4 - returns all products that belong to the department that has 4 as its ID.

 

Using field search queries provides a great deal of flexibility, but it is not very convenient for regular website visitors. If you wish to allow users to limit the scope of searches through conditions on the live site, it is recommended to prepare appropriate Smart search filters.

 

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]