class SearchQuery implements JsonSerializable (View source)

Represents full text search query

Constants

HIGHLIGHT_HTML

HIGHLIGHT_ANSI

HIGHLIGHT_SIMPLE

Methods

boolean()

Prepare boolean search query

dateRange()

Prepare date range search query

numericRange()

Prepare numeric range search query

termRange()

Prepare term range search query

booleanField(bool $value)

Prepare boolean field search query

conjuncts(SearchQueryPart ...$queries)

Prepare compound conjunction search query

disjuncts(SearchQueryPart ...$queries)

Prepare compound disjunction search query

docId(string ...$documentIds)

Prepare document ID search query

match(string $match)

Prepare match search query

matchAll()

Prepare match all search query

matchNone()

Prepare match non search query

matchPhrase(string ...$terms)

Prepare phrase search query

prefix(string $prefix)

Prepare prefix search query

queryString(string $queryString)

Prepare query string search query

regexp(string $regexp)

Prepare regexp search query

static TermSearchQuery
term(string $term)

Prepare term search query

wildcard(string $wildcard)

Prepare wildcard search query

geoDistance(float $longitude, float $latitude, string $distance)

Prepare geo distance search query

geoBoundingBox(float $topLeftLongitude, float $topLeftLatitude, float $bottomRightLongitude, float $bottomRightLatitude)

Prepare geo bounding box search query

static TermSearchFacet
termFacet(string $field, int $limit)

Prepare term search facet

dateRangeFacet(string $field, int $limit)

Prepare date range search facet

numericRangeFacet(string $field, int $limit)

Prepare numeric range search facet

__construct(string $indexName, SearchQueryPart $queryPart)

Prepare an FTS SearchQuery on an index.

mixed
jsonSerialize()

No description

limit(int $limit)

Add a limit to the query on the number of hits it can return

skip(int $skip)

Set the number of hits to skip (eg. for pagination).

explain(bool $explain)

Activates the explanation of each result hit in the response

serverSideTimeout(int $serverSideTimeout)

Sets the server side timeout in milliseconds

consistentWith(MutationState $state)

Sets the consistency to consider for this FTS query to AT_PLUS and uses the MutationState to parameterize the consistency.

fields(string ...$fields)

Configures the list of fields for which the whole value should be included in the response.

highlight(string $style, string ...$fields)

Configures the highlighting of matches in the response

sort(mixed ...$sort)

Configures the list of fields (including special fields) which are used for sorting purposes.

addFacet(string $name, SearchFacet $facet)

Adds one SearchFacet to the query

Details

static BooleanSearchQuery boolean()

Prepare boolean search query

Return Value

BooleanSearchQuery

static DateRangeSearchQuery dateRange()

Prepare date range search query

Return Value

DateRangeSearchQuery

static NumericRangeSearchQuery numericRange()

Prepare numeric range search query

static TermRangeSearchQuery termRange()

Prepare term range search query

Return Value

TermRangeSearchQuery

static BooleanFieldSearchQuery booleanField(bool $value)

Prepare boolean field search query

Parameters

bool $value

Return Value

BooleanFieldSearchQuery

static ConjunctionSearchQuery conjuncts(SearchQueryPart ...$queries)

Prepare compound conjunction search query

Parameters

SearchQueryPart ...$queries

list of inner query parts

Return Value

ConjunctionSearchQuery

static DisjunctionSearchQuery disjuncts(SearchQueryPart ...$queries)

Prepare compound disjunction search query

Parameters

SearchQueryPart ...$queries

list of inner query parts

Return Value

DisjunctionSearchQuery

static DocIdSearchQuery docId(string ...$documentIds)

Prepare document ID search query

Parameters

string ...$documentIds

Return Value

DocIdSearchQuery

static MatchSearchQuery match(string $match)

Prepare match search query

Parameters

string $match

Return Value

MatchSearchQuery

static MatchAllSearchQuery matchAll()

Prepare match all search query

Return Value

MatchAllSearchQuery

static MatchNoneSearchQuery matchNone()

Prepare match non search query

Return Value

MatchNoneSearchQuery

static MatchPhraseSearchQuery matchPhrase(string ...$terms)

Prepare phrase search query

Parameters

string ...$terms

Return Value

MatchPhraseSearchQuery

static PrefixSearchQuery prefix(string $prefix)

Prepare prefix search query

Parameters

string $prefix

Return Value

PrefixSearchQuery

static QueryStringSearchQuery queryString(string $queryString)

Prepare query string search query

Parameters

string $queryString

Return Value

QueryStringSearchQuery

static RegexpSearchQuery regexp(string $regexp)

Prepare regexp search query

Parameters

string $regexp

Return Value

RegexpSearchQuery

static TermSearchQuery term(string $term)

Prepare term search query

Parameters

string $term

Return Value

TermSearchQuery

static WildcardSearchQuery wildcard(string $wildcard)

Prepare wildcard search query

Parameters

string $wildcard

Return Value

WildcardSearchQuery

static GeoDistanceSearchQuery geoDistance(float $longitude, float $latitude, string $distance)

Prepare geo distance search query

Parameters

float $longitude
float $latitude
string $distance

e.g. "10mi"

Return Value

GeoDistanceSearchQuery

static GeoBoundingBoxSearchQuery geoBoundingBox(float $topLeftLongitude, float $topLeftLatitude, float $bottomRightLongitude, float $bottomRightLatitude)

Prepare geo bounding box search query

Parameters

float $topLeftLongitude
float $topLeftLatitude
float $bottomRightLongitude
float $bottomRightLatitude

Return Value

GeoBoundingBoxSearchQuery

static TermSearchFacet termFacet(string $field, int $limit)

Prepare term search facet

Parameters

string $field
int $limit

Return Value

TermSearchFacet

static DateRangeSearchFacet dateRangeFacet(string $field, int $limit)

Prepare date range search facet

Parameters

string $field
int $limit

Return Value

DateRangeSearchFacet

static NumericRangeSearchFacet numericRangeFacet(string $field, int $limit)

Prepare numeric range search facet

Parameters

string $field
int $limit

Return Value

NumericRangeSearchFacet

__construct(string $indexName, SearchQueryPart $queryPart)

Prepare an FTS SearchQuery on an index.

Top level query parameters can be set after that by using the fluent API.

Parameters

string $indexName

the FTS index to search in

SearchQueryPart $queryPart

the body of the FTS query (e.g. a match phrase query)

mixed jsonSerialize()

No description

Return Value

mixed

data which can be serialized by json_encode, which is a value of any type other than a resource.

SearchQuery limit(int $limit)

Add a limit to the query on the number of hits it can return

Parameters

int $limit

the maximum number of hits to return

Return Value

SearchQuery

SearchQuery skip(int $skip)

Set the number of hits to skip (eg. for pagination).

Parameters

int $skip

the number of results to skip

Return Value

SearchQuery

SearchQuery explain(bool $explain)

Activates the explanation of each result hit in the response

Parameters

bool $explain

Return Value

SearchQuery

SearchQuery serverSideTimeout(int $serverSideTimeout)

Sets the server side timeout in milliseconds

Parameters

int $serverSideTimeout

the server side timeout to apply

Return Value

SearchQuery

SearchQuery consistentWith(MutationState $state)

Sets the consistency to consider for this FTS query to AT_PLUS and uses the MutationState to parameterize the consistency.

This replaces any consistency tuning previously set.

Parameters

MutationState $state

the mutation state information to work with

Return Value

SearchQuery

SearchQuery fields(string ...$fields)

Configures the list of fields for which the whole value should be included in the response.

If empty, no field values are included. This drives the inclusion of the fields in each hit. Note that to be highlighted, the fields must be stored in the FTS index.

Parameters

string ...$fields

Return Value

SearchQuery

SearchQuery highlight(string $style, string ...$fields)

Configures the highlighting of matches in the response

Parameters

string $style

highlight style to apply. Use constants HIGHLIGHT_HTML, HIGHLIGHT_ANSI, HIGHLIGHT_SIMPLE.

string ...$fields

the optional fields on which to highlight. If none, all fields where there is a match are highlighted.

Return Value

SearchQuery

See also

SearchQuery::HIGHLIGHT_HTML
SearchQuery::HIGHLIGHT_ANSI
SearchQuery::HIGHLIGHT_SIMPLE

SearchQuery sort(mixed ...$sort)

Configures the list of fields (including special fields) which are used for sorting purposes.

If empty, the default sorting (descending by score) is used by the server.

The list of sort fields can include actual fields (like "firstname" but then they must be stored in the index, configured in the server side mapping). Fields provided first are considered first and in a "tie" case the next sort field is considered. So sorting by "firstname" and then "lastname" will first sort ascending by the firstname and if the names are equal then sort ascending by lastname. Special fields like "_id" and "_score" can also be used. If prefixed with "-" the sort order is set to descending.

If no sort is provided, it is equal to sort("-_score"), since the server will sort it by score in descending order.

Parameters

mixed ...$sort

the fields that should take part in the sorting.

Return Value

SearchQuery

SearchQuery addFacet(string $name, SearchFacet $facet)

Adds one SearchFacet to the query

This is an additive operation (the given facets are added to any facet previously requested), but if an existing facet has the same name it will be replaced.

Note that to be faceted, a field's value must be stored in the FTS index.