private function ContentHubSearch::getQueryFromString in Acquia Content Hub 8
Breaks the query string into individual alphanumeric components.
This deals with uuids, so that each component of a uuid is AND'd it also deals with any other characters in the search query that are not alphanumeric and treats them as delimeters - ignoring them.
Parameters
string $queryString: The search value to be passed to the query.
Return value
array An Elastic Search query segment that can be inserted into the main query
1 call to ContentHubSearch::getQueryFromString()
- ContentHubSearch::getElasticSearchQueryResponse in src/
ContentHubSearch.php - Builds Search query for given search terms..
File
- src/
ContentHubSearch.php, line 304
Class
- ContentHubSearch
- Perform queries to the Content Hub "_search" endpoint [Elasticsearch].
Namespace
Drupal\acquia_contenthubCode
private function getQueryFromString($queryString) {
$query = [
'bool' => [
'must' => [],
],
];
// Explode the search term into parts, ignore any that are null/empty.
$queryStringTokens = preg_split("/[^a-zA-Z\\d:]+/", $queryString);
foreach ($queryStringTokens as $token) {
if (strlen($token) != 0) {
$query['bool']['must'][] = [
'match' => [
'_all' => "*{$token}*",
],
];
}
}
return $query;
}