Skip to content

Commit c946108

Browse files
committed
FEATURE: Make fulltext options configurable
In order to configure the query_string query, for example to set the default_operator to AND you can now pass additional options to the fulltext eel operation
1 parent d8db3df commit c946108

5 files changed

Lines changed: 13 additions & 15 deletions

File tree

Classes/Driver/QueryInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ public function size($size);
6969
public function from($size);
7070

7171
/**
72-
* Match the searchword against the fulltext index
72+
* Match the search word against the fulltext index
7373
*
7474
* @param string $searchWord
75+
* @param array|null $options Options to configure the query_string
7576
* @return void
7677
* @api
7778
*/
78-
public function fulltext($searchWord);
79+
public function fulltext(string $searchWord, array $options = []);
7980

8081
/**
8182
* Configure Result Highlighting. Only makes sense in combination with fulltext(). By default, highlighting is enabled.

Classes/Driver/Version1/Query/FilteredQuery.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ public function from($size)
5353
/**
5454
* {@inheritdoc}
5555
*/
56-
public function fulltext($searchWord)
56+
public function fulltext(string $searchWord, ?array $options = [])
5757
{
5858
$this->appendAtPath('query.filtered.query.bool.must', [
59-
'query_string' => [
60-
'query' => $searchWord
61-
]
59+
'query_string' => array_merge($options, ['query' => $searchWord])
6260
]);
6361
}
6462

Classes/Driver/Version5/Query/FilteredQuery.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ class FilteredQuery extends Version1\Query\FilteredQuery
2323
/**
2424
* {@inheritdoc}
2525
*/
26-
public function fulltext($searchWord)
26+
public function fulltext(string $searchWord, ?array $options = [])
2727
{
2828
$this->appendAtPath('query.bool.must', [
29-
'query_string' => [
30-
'query' => $searchWord
31-
]
29+
'query_string' => array_merge($options, ['query' => $searchWord])
3230
]);
3331
}
3432

Classes/Eel/ElasticSearchQueryBuilder.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,13 +617,14 @@ public function count()
617617
* Match the searchword against the fulltext index
618618
*
619619
* @param string $searchWord
620+
* @param array|null $options Options to configure the query_string, see https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-query-string-query.html
620621
* @return QueryBuilderInterface
621622
* @api
622623
*/
623-
public function fulltext($searchWord)
624+
public function fulltext($searchWord, ?array $options = [])
624625
{
625626
// We automatically enable result highlighting when doing fulltext searches. It is up to the user to use this information or not use it.
626-
$this->request->fulltext(trim(json_encode($searchWord), '"'));
627+
$this->request->fulltext(trim(json_encode($searchWord), '"'), $options);
627628
$this->request->highlight(150, 2);
628629

629630
return $this;

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ search underneath the current site node (like in the example above).
128128

129129
Furthermore, the following operators are supported:
130130

131-
* `nodeType("Your.Node:Type")`
132-
* `exactMatch('propertyName', value)`; supports simple types: `exactMatch('tag', 'foo')`, or node references: `exactMatch('author', authorNode)`
131+
* `nodeType('Your.Node:Type')`
132+
* `exactMatch('propertyName', value)` -- supports simple types: `exactMatch('tag', 'foo')`, or node references: `exactMatch('author', authorNode)`
133133
* `greaterThan('propertyName', value)` -- range filter with property values greater than the given value
134134
* `greaterThanOrEqual('propertyName', value)` -- range filter with property values greater than or equal to the given value
135135
* `lessThan('propertyName', value)` -- range filter with property values less than the given value
@@ -138,7 +138,7 @@ Furthermore, the following operators are supported:
138138
will first sort by tag ascending, and then by date descending.
139139
* `limit(5)` -- only return five results. If not specified, the default limit by Elasticsearch applies (which is at 10 by default)
140140
* `from(5)` -- return the results starting from the 6th one
141-
* `fulltext(...)` -- do a query_string query on the Fulltext Index
141+
* `fulltext('searchWord', options)` -- do a query_string query on the Fulltext index using the searchword and additional [options](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/query-dsl-query-string-query.html) to the query_string
142142

143143
Furthermore, there is a more low-level operator which can be used to add arbitrary Elasticsearch filters:
144144

0 commit comments

Comments
 (0)