FEATURE: Provide new feature to configure fields to search in

This enables you to search only in some fields.
Also if some fields contain mapping, you can add them in addition to
e.g. `_all`.
This commit is contained in:
Daniel Siepmann 2017-11-29 18:57:09 +01:00
parent 689d8f0c53
commit 02ef86b67b
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 26 additions and 11 deletions

View file

@ -99,20 +99,18 @@ class QueryFactory
return; return;
} }
$query = ArrayUtility::setValueByPath( $matchExpression = [
$query, 'type' => 'most_fields',
'query.bool.must.0.match._all.query', 'query' => $searchRequest->getSearchTerm(),
$searchRequest->getSearchTerm() 'fields' => GeneralUtility::trimExplode(',', $this->configuration->get('searching.fields.query')),
); ];
$minimumShouldMatch = $this->configuration->getIfExists('searching.minimumShouldMatch'); $minimumShouldMatch = $this->configuration->getIfExists('searching.minimumShouldMatch');
if ($minimumShouldMatch) { if ($minimumShouldMatch) {
$query = ArrayUtility::setValueByPath( $matchExpression['minimum_should_match'] = $minimumShouldMatch;
$query,
'query.bool.must.0.match._all.minimum_should_match',
$minimumShouldMatch
);
} }
$query = ArrayUtility::setValueByPath($query, 'query.bool.must.0.multi_match', $matchExpression);
} }
protected function addBoosts(SearchRequestInterface $searchRequest, array &$query) protected function addBoosts(SearchRequestInterface $searchRequest, array &$query)

View file

@ -21,6 +21,12 @@ plugin {
abstractFields = {$plugin.tx_searchcore.settings.indexing.pages.abstractFields} abstractFields = {$plugin.tx_searchcore.settings.indexing.pages.abstractFields}
} }
} }
searching {
fields {
query = _all
}
}
} }
} }
} }

View file

@ -151,7 +151,18 @@ filtering. This way you can use arbitrary filter names and map them to existing
fields fields
------ ------
Defines the fields to fetch from elasticsearch. Two sub entries exist: Defines the fields to fetch and search from elasticsearch. With the following sub keys:
``query`` defines the fields to search in. Default is ``_all`` from 5.x times of elasticsearch.
Configure a comma separated list of fields to search in. This is necessary if you have configured
special mapping for some fields, or just want to search some fields.
The most hits get ranked highest. The following is an example configuration::
fields {
query = _all, city
}
The following sub properties configure the fields to fetch from elasticsearch:
First ``stored_fields`` which is a list of comma separated fields which actually exist and will be First ``stored_fields`` which is a list of comma separated fields which actually exist and will be
added. Typically you will use ``_source`` to fetch the whole indexed fields. added. Typically you will use ``_source`` to fetch the whole indexed fields.