Hide menu Last updated: Oct 31 2016
Area: Episerver Find Applies to versions: 12 and higher
Other versions:

Free text search

This topic describes how free text search works in Episerver Find, how to perform queries against fields, and how to work with stemming in free text search.

How it works

You typically use the For method to search for phrases or keywords in indexed documents. For instance, to search for blog posts that contain car, use the code in the following examples.

Typically, a search query is fetched from user input.

Searching fields

By default, a search query using the For method is performed against a field named _all. The field is generated when an object is indexed, and it is made up of all of the document's fields combined.

Search queries should specify fields using the InField, AndInField and InFields methods. These methods expect a lambda expression, which retrieves the field name. For example, this code searches the Title field of blog posts.

To also search the Content field, add a second InField method.

Alternatively, you can use the InFields method or the AndInField method. Their usage is demonstrated below.

If one or more fields are specified using methods described above, the search is no longer performed against the All field. However, you can explicitly request the search to use the InAllField method.

Stemming

Stemming is the process of reducing a word to its root form. When using stemming in free text search, words with similar meanings, such as car and cars, match.

Stemming is language dependent, so you need to tell the search engine the language in which you are searching. To do this, pass an instance of the language class to the Clients Search method. Instances of the Language class that match all supported languages are available as static properties on the Language class.

Note: Search with the All field cannot use stemming. This means that, for the language parameter to have any effect, you must specify search fields (such as InField) using methods described above. Below is a sample search request for cars that matches blog posts titled car or A blue car.

Often, you want to search a number of known fields with stemming but also match text that is not in those fields. Although the All field does not support stemming, you can still search it when using stemming. So, for example, to search the Title and Content fields for blog posts and still match blog posts that do not contain the word cars in their Title or Content fields but do contain the word in another field (such as tags), you can use the following code.

Comments