You are here

private function AdvancedHelpSearch::getSids in Advanced Help 8

Gets search id for each topic.

Get or create an sid (search id) that correlates to each topic for the search system.

Parameters

array $topics:

Return value

array

1 call to AdvancedHelpSearch::getSids()
AdvancedHelpSearch::updateIndex in src/Plugin/Search/AdvancedHelpSearch.php
Updates the search index for this plugin.

File

src/Plugin/Search/AdvancedHelpSearch.php, line 127

Class

AdvancedHelpSearch
Executes a keyword search for Advanced Help against the {advanced_help} topic pages.

Namespace

Drupal\advanced_help\Plugin\Search

Code

private function getSids($topics) {
  $language = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  $result = $this->database
    ->select('advanced_help_index', 'ahi')
    ->fields('ahi', [
    'sid',
    'module',
    'topic',
    'langcode',
  ])
    ->condition('langcode', $language)
    ->execute();
  foreach ($result as $sid) {
    if (empty($topics[$sid->module][$sid->topic])) {
      $this->database
        ->query("DELETE FROM {advanced_help_index} WHERE sid = :sid", [
        ':sid' => $sid->sid,
      ]);
    }
    else {
      $topics[$sid->module][$sid->topic]['sid'] = $sid->sid;
    }
  }
  return $topics;
}