public static function SuggestionStorage::getScore in Autocomplete Search Suggestions 8
Same name and namespace in other branches
- 8.2 src/SuggestionStorage.php \Drupal\suggestion\SuggestionStorage::getScore()
- 3.0.x src/SuggestionStorage.php \Drupal\suggestion\SuggestionStorage::getScore()
Calculate a suggestion's score.
Parameters
array $atoms: An array of strings.
Return value
int The suggestion's score.
1 call to SuggestionStorage::getScore()
- suggestion_surfer_submit in ./
suggestion.module - Custom submit function to add surfer suggestions.
File
- src/
SuggestionStorage.php, line 157
Class
- SuggestionStorage
- Database CRUD.
Namespace
Drupal\suggestionCode
public static function getScore(array $atoms = []) {
$types = SuggestionHelper::types();
if (!count($types)) {
return 0;
}
$query = db_select('node__body', 'b');
$query
->fields('b', [
'entity_id',
]);
$query
->join('node_field_data', 'n', 'n.nid = b.entity_id');
$query
->condition('n.status', 1);
$query
->condition('n.type', $types, 'IN');
foreach ($atoms as $atom) {
$query
->condition('b.body_value', '%' . db_like($atom) . '%', 'LIKE');
}
return count($atoms) ? count($query
->execute()
->fetchCol()) : 0;
}