protected function SearchApiElasticsearchAbstractService::flattenKeys in Search API Elasticsearch 7
Return a full text search query.
TODO: better handling of parse modes.
2 calls to SearchApiElasticsearchAbstractService::flattenKeys()
- SearchApiElasticsearchElastica::buildSpellcheckQuery in modules/
elastica/ includes/ SearchApiElasticsearchElastica.inc - buildSpellcheckQuery
- SearchApiElasticsearchElastica::getSearchQueryOptions in modules/
elastica/ includes/ SearchApiElasticsearchElastica.inc - Helper function return associative array with query options.
File
- includes/
SearchApiElasticsearchAbstractService.inc, line 909 - Provides a Elasticsearch-based service class for the Search API.
Class
- SearchApiElasticsearchAbstractService
- Elasticsearch service abstract class.
Code
protected function flattenKeys($keys, $parse_mode = '', $full_text_fields = array()) {
$conjunction = isset($keys['#conjunction']) ? $keys['#conjunction'] : 'AND';
$negation = !empty($keys['#negation']);
$values = array();
foreach (element_children($keys) as $key) {
$value = $keys[$key];
if (empty($value)) {
continue;
}
if (is_array($value)) {
$values[] = $this
->flattenKeys($value);
}
elseif (is_string($value)) {
// If parse mode is not "direct": quote the keyword.
if ($parse_mode !== 'direct') {
$value = '"' . $value . '"';
}
$values[] = $value;
}
}
if (!empty($values)) {
return ($negation === TRUE ? 'NOT ' : '') . '(' . implode(" {$conjunction} ", $values) . ')';
}
else {
return '';
}
}