protected function SearchBuilder::flattenKeys in Elasticsearch Connector 8.5
Same name and namespace in other branches
- 8.7 src/ElasticSearch/Parameters/Builder/SearchBuilder.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Builder\SearchBuilder::flattenKeys()
- 8.2 src/ElasticSearch/Parameters/Builder/SearchBuilder.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Builder\SearchBuilder::flattenKeys()
- 8.6 src/ElasticSearch/Parameters/Builder/SearchBuilder.php \Drupal\elasticsearch_connector\ElasticSearch\Parameters\Builder\SearchBuilder::flattenKeys()
Turn the given search keys into a lucene object structure.
Parameters
array $keys: Search keys, in the format described by \Drupal\search_api\ParseMode\ParseModeInterface::parseInput().
\Drupal\search_api\ParseMode\ParseModeInterface $parse_mode: Search API parse mode.
bool $fuzzy: Enable fuzzy support or not.
Return value
\MakinaCorpus\Lucene\AbstractQuery Return a lucene query object.
1 call to SearchBuilder::flattenKeys()
- SearchBuilder::getSearchQueryOptions in src/
ElasticSearch/ Parameters/ Builder/ SearchBuilder.php - Helper function to return associative array with query options.
File
- src/
ElasticSearch/ Parameters/ Builder/ SearchBuilder.php, line 285
Class
- SearchBuilder
- Class SearchBuilder.
Namespace
Drupal\elasticsearch_connector\ElasticSearch\Parameters\BuilderCode
protected function flattenKeys(array $keys, ParseModeInterface $parse_mode = NULL, $fuzzy = TRUE) {
// Grab the conjunction and negation properties if present.
$conjunction = isset($keys['#conjunction']) ? $keys['#conjunction'] : 'AND';
$negation = !empty($keys['#negation']);
// Create a top level query.
$query = (new TermCollectionQuery())
->setOperator($conjunction);
if ($negation) {
$query
->setExclusion(Query::OP_PROHIBIT);
}
// Filter out top level properties beginning with '#'.
$keys = array_filter($keys, function ($key) {
return $key[0] !== '#';
}, ARRAY_FILTER_USE_KEY);
// Loop over the keys.
foreach ($keys as $key) {
$element = NULL;
if (is_array($key)) {
$element = $this
->luceneFlattenKeys($key, $parse_mode);
}
elseif (is_string($key)) {
$element = (new TermQuery())
->setValue($key);
if ($fuzzy) {
$element
->setFuzzyness($fuzzy);
}
}
if (isset($element)) {
$query
->add($element);
}
}
return $query;
}