public function AdvancedHelpSearch::execute in Advanced Help 8
Executes the search.
Return value
array A structured list of search results.
Overrides SearchInterface::execute
File
- src/
Plugin/ Search/ AdvancedHelpSearch.php, line 147
Class
- AdvancedHelpSearch
- Executes a keyword search for Advanced Help against the {advanced_help} topic pages.
Namespace
Drupal\advanced_help\Plugin\SearchCode
public function execute() {
if ($this
->isSearchExecutable()) {
$keys = $this->keywords;
// Build matching conditions.
$query = $this->database
->select('search_index', 'i', [
'target' => 'replica',
])
->extend('Drupal\\search\\SearchQuery')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
$query
->join('advanced_help_index', 'ahi', 'ahi.sid = i.sid');
$query
->join('search_dataset', 'sd', "ahi.sid = sd.sid AND sd.type = '{$this->pluginId}'");
$query
->searchExpression($keys, $this
->getPluginId());
$find = $query
->fields('i', [
'langcode',
])
->fields('ahi', [
'module',
'topic',
])
->fields('sd', [
'data',
])
->groupBy('i.langcode, ahi.module, ahi.topic, sd.data')
->limit(10)
->execute();
$results = [];
foreach ($find as $key => $item) {
$result = [
'link' => '/help/ah/' . $item->module . '/' . $item->topic,
'title' => $item->topic,
'score' => $item->calculated_score,
'snippet' => search_excerpt($keys, $item->data, $item->langcode),
'langcode' => $item->langcode,
];
$results[] = $result;
}
return $results;
}
return [];
}