Skip to content

Commit

Permalink
added additional check to ensure autocomplete suggests only searchabl…
Browse files Browse the repository at this point in the history
…e terms
  • Loading branch information
ryanisn committed Aug 27, 2024
1 parent 9fbf386 commit 3ffbbb5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ public function isSearchable(): bool
|| $this->isFilterable());
}

/**
* Check if attribute value can be suggested.
*
* @return bool
*/
public function isSuggestible(): bool
{
return $this->getAttribute()->getIsSearchable();
}

/**
* Check if attribute is need to index always.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ public function getField(AbstractAttribute $attribute): array
];
}

$fieldMapping[$fieldName]['suggestible'] = $attributeAdapter->isSuggestible();

if ($attributeAdapter->isTextType()) {
$keywordFieldName = FieldTypeConverterInterface::INTERNAL_DATA_TYPE_KEYWORD;
$index = $this->indexTypeConverter->convert(
Expand Down Expand Up @@ -207,6 +209,7 @@ public function getField(AbstractAttribute $attribute): array
'normalizer' => 'folding',
];
}
$fieldMapping[$childFieldName]['suggestible'] = $attributeAdapter->isSuggestible();
}

return $fieldMapping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ private function addSuggestFields($searchQuery, $searchSuggestionsCount)
private function getSuggestFields()
{
$fields = array_filter($this->fieldProvider->getFields(), function ($field) {
return (($field['type'] ?? null) === 'text') && (($field['index'] ?? null) !== false);
return (($field['type'] ?? null) === 'text') && (($field['index'] ?? null) !== false)
&& (($field['suggestible'] ?? null) !== false);
});

return array_keys($fields);
Expand Down

0 comments on commit 3ffbbb5

Please sign in to comment.