C# Node.JS
Article For
3.0 3.5

Session: Querying: How to Use Search

More complex text searching can be achieved by using the search method. This method allows you to pass one or more search terms that will be used in the searching process for a particular field (or fields).


IDocumentQuery<T> search(String fieldName, String searchTerms);
IDocumentQuery<T> search(String fieldName, String searchTerms, SearchOperator operator);
IDocumentQuery<T> boost(double boost);
fieldName String Points index field that should be used for querying.
searchTerms String Space separated terms e.g. 'John Adam' means that we will look in selected field for 'John' or 'Adam'. Wildcards can be specified.
boost double Boost value. Default: 1.
operator SearchOperator Explicitly set relation between each Search function. One of the following: OR, AND.

Example I - Dynamic Query

List<User> users = session
    .search("Name", "a*")
from Users 
where search(Name, 'a*')

Example II - Query Using Static Index

List<User> users = session.query(User.class, Users_ByNameAndHobbies.class)
    .search("Name", "Adam")
    .search("Hobbies", "sport")
from index 'Users/ByNameAndHobbies' 
where search(Name, 'Adam') or search(Hobbies, 'sport')

Example III - Boosting Usage

List<User> users = session
    .query(User.class, index("Users/ByHobbies"))
    .search("Hobbies", "I love sport")
    .search("Hobbies", "but also like reading books")
from index 'Users/ByHobbies' 
where boost(search(Hobbies, 'I love sport'), 10) or boost(search(Hobbies, 'but also like reading books'), 5)


To leverage the searching capabilities with the usage of static indexes, please remember to enable full-text search in field settings of the index definition.