You can use Elastic\ScoutDriverPlus\Support\Query::matchAll()
to build a query that
matches all documents:
$query = Query::matchAll();
$searchResult = Book::searchQuery($query)->execute();
You can use Elastic\ScoutDriverPlus\Support\Query::matchNone()
to build a query that
matches no documents:
$query = Query::matchNone();
$searchResult = Book::searchQuery($query)->execute();
You can use Elastic\ScoutDriverPlus\Support\Query::matchPhrasePrefix()
to build a query that matches documents, which
contain the words of a provided text
in the same order as provided:
$query = Query::matchPhrasePrefix()
->field('title')
->query('My boo');
$searchResult = Book::searchQuery($query)->execute();
Available methods:
analyzer
is used to convert the query
text into tokens:
$query = Query::matchPhrasePrefix()
->field('title')
->query('My boo')
->analyzer('english');
$searchResult = Book::searchQuery($query)->execute();
Use field
to specify the field you wish to search:
$query = Query::matchPhrasePrefix()
->field('title')
->query('My boo');
$searchResult = Book::searchQuery($query)->execute();
You can use maxExpansions
to specify maximum number of terms to which the last provided term of the query
value will expand:
$query = Query::matchPhrasePrefix()
->field('title')
->query('My boo')
->maxExpansions(50);
$searchResult = Book::searchQuery($query)->execute();
Use query
to set the text you wish to find in the provided field
:
$query = Query::matchPhrasePrefix()
->field('title')
->query('My boo');
$searchResult = Book::searchQuery($query)->execute();
Use slop
to define the maximum number of positions allowed between matching tokens:
$query = Query::matchPhrasePrefix()
->field('title')
->query('My boo')
->slop(0);
$searchResult = Book::searchQuery($query)->execute();
You can define what to return in case analyzer
removes all tokens
using zeroTermsQuery
:
$query = Query::matchPhrasePrefix()
->field('title')
->query('My boo')
->zeroTermsQuery('none');
$searchResult = Book::searchQuery($query)->execute();
You can use Elastic\ScoutDriverPlus\Support\Query::matchPhrase()
to build a query that matches documents, which
contain the given phrase:
$query = Query::matchPhrase()
->field('title')
->query('My book');
$searchResult = Book::searchQuery($query)->execute();
Available methods:
analyzer
is used to convert the query
text into tokens:
$query = Query::matchPhrase()
->field('title')
->query('My book')
->analyzer('english');
$searchResult = Book::searchQuery($query)->execute();
Use field
to specify the field you wish to search:
$query = Query::matchPhrase()
->field('title')
->query('My book');
$searchResult = Book::searchQuery($query)->execute();
Use query
to set the text you wish to find in the provided field
:
$query = Query::matchPhrase()
->field('title')
->query('My book');
$searchResult = Book::searchQuery($query)->execute();
Use slop
to define the maximum number of positions allowed between matching tokens:
$query = Query::matchPhrase()
->field('title')
->query('My book')
->slop(0);
$searchResult = Book::searchQuery($query)->execute();
You can define what to return in case analyzer
removes all tokens with zeroTermsQuery
:
$query = Query::matchPhrase()
->field('title')
->query('My book')
->zeroTermsQuery('none');
$searchResult = Book::searchQuery($query)->execute();
You can use Elastic\ScoutDriverPlus\Support\Query::match()
to build a query that matches documents, which
contain a provided text, number, date or boolean value:
$query = Query::match()
->field('title')
->query('My book');
$searchResult = Book::searchQuery($query)->execute();
Available methods:
- analyzer
- autoGenerateSynonymsPhraseQuery
- boost
- field
- fuzziness
- fuzzyRewrite
- fuzzyTranspositions
- lenient
- maxExpansions
- minimumShouldMatch
- operator
- prefixLength
- query
- zeroTermsQuery
analyzer
is used to convert the query
text into tokens:
$query = Query::match()
->field('title')
->query('My book')
->analyzer('english');
$searchResult = Book::searchQuery($query)->execute();
autoGenerateSynonymsPhraseQuery
allows you to define if match phrase queries have to be automatically created
for multi-term synonyms:
$query = Query::match()
->field('title')
->query('My book')
->autoGenerateSynonymsPhraseQuery(true);
$searchResult = Book::searchQuery($query)->execute();
boost
method allows you to decrease or increase the relevance scores of the query:
$query = Query::match()
->field('title')
->query('My book')
->boost(2);
$searchResult = Book::searchQuery($query)->execute();
Use field
to specify the field you wish to search:
$query = Query::match()
->field('title')
->query('My book');
$searchResult = Book::searchQuery($query)->execute();
fuzziness
controls maximum edit distance allowed for matching:
$query = Query::match()
->field('title')
->query('My book')
->fuzziness('AUTO');
$searchResult = Book::searchQuery($query)->execute();
fuzzyRewrite
is used to rewrite the query:
$query = Query::match()
->field('title')
->query('My book')
->fuzzyRewrite('constant_score');
$searchResult = Book::searchQuery($query)->execute();
Use fuzzyTranspositions
to allow transpositions for two adjacent characters:
$query = Query::match()
->field('title')
->query('My book')
->fuzziness('AUTO')
->fuzzyTranspositions(true);
$searchResult = Book::searchQuery($query)->execute();
Use lenient
to ignore format-based errors:
$query = Query::match()
->field('price')
->query('My book')
->lenient(true);
$searchResult = Book::searchQuery($query)->execute();
You can use maxExpansions
to specify maximum number of terms to which the query will expand:
$query = Query::match()
->field('title')
->query('My book')
->maxExpansions(50);
$searchResult = Book::searchQuery($query)->execute();
minimumShouldMatch
defines minimum number of clauses that must match for a document to be returned:
$query = Query::match()
->field('title')
->query('My book')
->operator('OR')
->minimumShouldMatch(1);
$searchResult = Book::searchQuery($query)->execute();
Use operator
to define the boolean logic used to interpret the query
text:
$query = Query::match()
->field('title')
->query('My book')
->operator('OR');
$searchResult = Book::searchQuery($query)->execute();
prefixLength
is used to determine the number of beginning characters left unchanged for fuzzy matching:
$query = Query::match()
->field('title')
->query('My book')
->fuzziness('AUTO')
->prefixLength(0);
$searchResult = Book::searchQuery($query)->execute();
Use query
to set the text you wish to find in the provided field
:
$query = Query::match()
->field('title')
->query('My book');
$searchResult = Book::searchQuery($query)->execute();
You can define what to return in case analyzer
removes all tokens
with zeroTermsQuery
:
$query = Query::match()
->field('title')
->query('My book')
->zeroTermsQuery('none');
$searchResult = Book::searchQuery($query)->execute();
You can use Elastic\ScoutDriverPlus\Support\Query::multiMatch()
to build a query that matches documents, which
contain a provided text, number, date or boolean value in multiple fields:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book');
$searchResult = Book::searchQuery($query)->execute();
Available methods:
- analyzer
- autoGenerateSynonymsPhraseQuery
- boost
- fields
- fuzziness
- fuzzyRewrite
- fuzzyTranspositions
- lenient
- maxExpansions
- minimumShouldMatch
- operator
- prefixLength
- query
- slop
- tieBreaker
- type
- zeroTermsQuery
analyzer
is used to convert the query
text into tokens:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->analyzer('english');
$searchResult = Book::searchQuery($query)->execute();
autoGenerateSynonymsPhraseQuery
allows you to define, if match phrase queries have to be automatically created
for multi-term synonyms:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->autoGenerateSynonymsPhraseQuery(true);
$searchResult = Book::searchQuery($query)->execute();
boost
method allows you to decrease or increase the relevance scores of a query:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->boost(2);
$searchResult = Book::searchQuery($query)->execute();
Use fields
to define the fields you wish to search in:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book');
$searchResult = Book::searchQuery($query)->execute();
fuzziness
controls maximum edit distance allowed for matching:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->fuzziness('AUTO');
$searchResult = Book::searchQuery($query)->execute();
fuzzyRewrite
is used to rewrite the query:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->fuzzyRewrite('constant_score');
$searchResult = Book::searchQuery($query)->execute();
Use fuzzyTranspositions
to allow transpositions for two adjacent characters:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->fuzziness('AUTO')
->fuzzyTranspositions(true);
$searchResult = Book::searchQuery($query)->execute();
Use lenient
to ignore format-based errors:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->lenient(true);
$searchResult = Book::searchQuery($query)->execute();
You can use maxExpansions
to specify maximum number of terms to which the query will expand:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->maxExpansions(50);
$searchResult = Book::searchQuery($query)->execute();
minimumShouldMatch
defines minimum number of clauses that must match for a document to be returned:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->operator('OR')
->minimumShouldMatch(1);
$searchResult = Book::searchQuery($query)->execute();
Use operator
to define the boolean logic used to interpret the query
text:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->operator('OR');
$searchResult = Book::searchQuery($query)->execute();
prefixLength
is used to determine the number of beginning characters left unchanged for fuzzy matching:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->fuzziness('AUTO')
->prefixLength(0);
$searchResult = Book::searchQuery($query)->execute();
Use query
to set the text you wish to find in the provided fields
:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book');
$searchResult = Book::searchQuery($query)->execute();
Use slop
to define the maximum number of positions allowed between matching tokens:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->slop(0);
$searchResult = Book::searchQuery($query)->execute();
tieBreaker
is used to increase the relevance scores
of documents matching the query:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->tieBreaker(0.3);
$searchResult = Book::searchQuery($query)->execute();
Use type
to define how the query must be executed:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->type('best_fields');
$searchResult = Book::searchQuery($query)->execute();
Note that not all available methods make sense with every type. Read the documentation carefully.
You can define what to return in case analyzer
removes all tokens with zeroTermsQuery
:
$query = Query::multiMatch()
->fields(['title', 'description'])
->query('My book')
->zeroTermsQuery('none');
$searchResult = Book::searchQuery($query)->execute();