Session: Querying: How to use search?

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

Syntax

IRavenQueryable<T> Search<T>(
	this IQueryable<T> self,
	Expression<Func<T, object>> fieldSelector,
	string searchTerms,
	decimal boost = 1,
	SearchOptions options = SearchOptions.Guess,
	EscapeQueryOptions escapeQueryOptions = EscapeQueryOptions.EscapeAll) { ... }
Parameters
fieldSelector Expression<Func<TResult>> Expression marking a field in which terms should be looked for.
searchTerms string Space separated terms e.g. 'John Adam' means that we will look in selected field for 'John' or 'Adam'.
boost decimal Boost value. Default: 1.
options SearchOptions Explicitly set relation between each Search functions. One of the following: Or, And, Not, Guess. Default: SearchOptions.Guess.
escapeQueryOptions EscapeQueryOptions Terms escaping strategy. One of the following: EscapeAll, AllowPostfixWildcard, AllowAllWildcards, RawQuery. Default: EscapeQueryOptions.EscapeAll.
Return Value
IRavenQueryable Instance implementing IRavenQueryable interface containing additional query methods and extensions.

Example I

List<User> users = session
	.Query<User>("Users/ByNameAndHobbies")
	.Search(x => x.Name, "Adam")
	.Search(x => x.Hobbies, "sport")
	.ToList();

Example II

List<User> users = session
	.Query<User>("Users/ByHobbies")
	.Search(x => x.Hobbies, "I love sport", boost: 10)
	.Search(x => x.Hobbies, "but also like reading books", boost: 5)
	.ToList();