SearchRequest


requesting

Selects the specified number of results. If you do not use this method, a maximum of 10 results is returned.

Syntax

search_request requesting(int number)
search_requestthe modified search request

Example

requesting:
entity_type("foo").requesting(100) --> maximum 100 results

Example

requesting association chain:
subject.association1.requesting(5).association2.requesting(20) --> maximum 20 results

requesting_per_entity_type

Selects the specified number of results searched for the preceding entity type in this search request. Applies when multiple entity types or an association is specified. If only one entity type is specified in the search request, this method is ignored. If an association request is specified and you do not use this method, each association segment searches a maximum of 250 entities per association segment.

Syntax

search_request requesting_per_entity_type(int number)
search_requestthe modified search request

Example

requesting per entity type:
entity_types(["foo", "bar"]).requesting_per_entity_type(50) -> maximum of 50 for both "foo" and 50 "bar" searched

Example

requesting per entity type associations:
subject.association1.association2.requesting_per_entity_type(50) -> maximum of 250 for association1 (default) and maximum of 50 for association2 entity types searched

starting_at

Selects results starting at the specified position in the result set. The parameter must be a number greater than or equal to 0. If you do not use this method, the default position is 0.

Syntax

search_request starting_at(int number)
search_requestthe modified search request

Example

starting at:
entity_type("foo").starting_at(30) --> results are from 30 to 40 (if requesting is default 10)

where

Selects results according to the subsequent filters specified by the query parameter. The parameter can either be a string or a query expression.

Syntax

search_request where(query/data_method/string query)

Example

where string:
entity_type("foo").where("bar") --> returns entities of type "foo" with "bar" in it

Example

where query:
entity_type("foo").where(field("bar").contains_regex("a.+")) --> returns entities of type "foo" with values of field "bar" matching the regex

with_filter_query

Selects a specified set of results by running the query parameter before running the main query. This query will not affect relevance of actual results. Multiple calls to this method are equivalent to combining queries with AND. The parameter can either be a string or a query expression.

Syntax

search_request with_filter_query(query/data_method/string query)

Example

simple filter query:
entity_type("foo").with_filter_query(field("bar").exists) --> returns entities of type "foo" with a "bar" field without affecting result relevancy

set_query

Selects results according to the query parameter, which overrides previous queries in this search request. The parameter can either be a string or a query expression.

Syntax

search_request set_query(query/data_method/string query)

Example

set query:
entity_type("foo").where("foo").set_query("bar") --> returns entities of type "foo" that match "bar" ("foo" is ignored)

clustered

Enables clustering of the returned results. The clustered results can be retrieved from the faceting configuration. If you do not use this method, results will not be clustered in the faceting configuration.

Syntax

search_request clustered

Example

clustered:
entity_type("foo").clustered --> allows retrieval of a facet id "%clustering%" from the faceting configuration

filter_duplicates

Enables filtering of duplicate entities. If you do not use this method, all results are returned, including duplicates.

Syntax

search_request filter_duplicates

Example

filter duplicates:
entity_type("foo").filter_duplicates --> returns entities of type "foo" without duplicates

faceted_by

Specifies a faceting configuration. The parameter is a faceting expression.

Syntax

search_request faceted_by(facet_by/data_method facet_by)

Example

faceting by field:
entity_type("foo").faceted_by( field("bar").then( sum("baz" ) ) ) --> allows the faceting configuration to contain results grouped by value of "bar" each with the sum of "baz"

sorted_by

Specifies a sorting expression. The parameter is a sorting expression. Default order is by relevancy. Use sorted_by( field("last_name").then( field("first_name") ) to combine multiple sorting conditions. Order of calls corresponds to sorting precedence.

Syntax

search_request sorted_by(sort_by/data_method sort_by)

Example

sort in descending order:
entity_type("foo").sorted_by(field("bar").in_descending_order) --> results sorted by value of "bar" in reverse order

Example

sort by multiple:
entity_type("foo").sorted_by( field( "last_name" ).then( field( "first_name" ) ) ) --> results sorted by value of "last_name" then by "first_name"

selecting_fields

Specifies named fields to return. Fields specified here overwrite (replace) fields specified in previous calls to selecting_fields method. If you do not use this method, all fields are returned.

Syntax

search_request selecting_fields(array fields_array)

Example

select fields:
entity_type("foo").selecting_fields( [ "bar", "baz" ] ) --> contains only "bar" and "baz" fields in the results

generate_snippets

Generate snippets with this request. Search results will have "snippet" field containing a short excerpt from the text of the entity.

Syntax

search_request generate_snippets

Example

generate snippets:
entity_type("foo").generate_snippets --> entities returned have an additional field called "snippet" available

bold

Embolden fields and snippets based on query. Search results will have HTML tags surrounding matching portions of the query. This method has no effect unless used with a filtering method like the where method.

Syntax

search_request bold

Example

bold matches:
entity_type("foo").where("bar").bold --> entities returned have HTML tags surrounding "bar" in fields of the entity

with_relevance_formula

Specify a default sort using XPath to the last step of the query. A formula specified here overwrites (replaces) formulae specified in previous calls to the method with_relevance_formula(xpath).

Syntax

search_request with_relevance_formula(string xpath)

Example

relevance formula:
entity_type("foo").with_relevance_formula("-$score") --> reverses the order of the results

to_s

(Ruby method) Returns a string representing the search request.

Syntax

string to_s

to_json

(Rails method) Returns a JSON respresentation of the search request.

Syntax

string to_json

to_xml

(Rails method) Returns an XML respresentation of the search request.

Syntax

string to_xml

each

(Ruby method) Calls the given block once for each result in the search results passing that result as a parameter. An Enumerator is returned if no block is given.


first

(Ruby method) Returns the first search result. If the results are empty, returns nil.

Syntax

search_result first

empty?

(Ruby method) Returns true if the search request returns no results.

Syntax

boolean empty?

total_results

Returns the total number of results. If that cannot be calculated, the actual number of results returned.

Syntax

int total_results

Example

total results:
entity_type("foo").total_results --> integer that represents total results, not results returned

total_results_without_duplicates

Returns the total number of results after removing duplicates. If the total number cannot be calculated, the actual number of results is returned. The returned value is usually only meaningful when the filter_duplicates method is called. The returned value is likely to be an approximation unless it is lower than the rank of the last result requested.

Syntax

int total_results_without_duplicates

Example

total results without duplicates:
entity_type("foo").filter_duplicates.total_results_without_duplicates --> integer that represents total results without duplicates

size

Returns the number of results that are actually returned in this request. Is less than or equal to the number set by the requesting method.

Syntax

int size

faceting

Returns a faceting configuration that represents the grouping done on the request.

Syntax

faceting faceting

Example

faceting configuration:
entity_type("foo").faceted_by( field("bar") ).faceting --> returns faceting configuration with "bar" as a facet