Skip to content

Commit

Permalink
Target non-default analyzer fields in exact search.
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud committed Jul 4, 2023
1 parent 60ee892 commit be83195
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer
* versions in the future.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Romain Ruaud <romain.ruaud@smile.fr>
* @copyright 2023 Smile
* @license Open Software License ("OSL") v. 3.0
*/

namespace Smile\ElasticsuiteCore\Search\Request\Query\Fulltext;

use Smile\ElasticsuiteCore\Api\Index\Mapping\FieldInterface;

/**
* Indicates if a field is used in search with a non-default analyzer.
*
* @category Smile
* @package Smile\ElasticsuiteCore
* @author Romain Ruaud <romain.ruaud@smile.fr>
*/
class NonStandardSearchableFieldFilter extends SearchableFieldFilter
{
/**
* {@inheritDoc}
*/
public function filterField(FieldInterface $field)
{
return parent::filterField($field) && ($field->getDefaultSearchAnalyzer() !== FieldInterface::ANALYZER_STANDARD);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,18 @@ private function getCutoffFrequencyQuery(ContainerConfigurationInterface $contai
{
$relevanceConfig = $containerConfig->getRelevanceConfig();

$nonStandardSearchableFieldFilter = $this->fieldFilters['nonStandardSearchableFieldFilter'];

$defaultFields = array_fill_keys([MappingInterface::DEFAULT_SEARCH_FIELD, 'sku'], 1);
$fields = $defaultFields + $this->getWeightedFields(
$containerConfig,
null,
$nonStandardSearchableFieldFilter,
MappingInterface::DEFAULT_SEARCH_FIELD
);

$queryParams = [
'fields' => array_fill_keys([MappingInterface::DEFAULT_SEARCH_FIELD, 'sku'], 1),
'fields' => array_fill_keys(array_keys($fields), 1),
'queryText' => $queryText,
'cutoffFrequency' => $relevanceConfig->getCutOffFrequency(),
'minimumShouldMatch' => $relevanceConfig->getMinimumShouldMatch(),
Expand Down
1 change: 1 addition & 0 deletions src/module-elasticsuite-core/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<arguments>
<argument name="fieldFilters" xsi:type="array">
<item name="searchableFieldFilter" xsi:type="object">Smile\ElasticsuiteCore\Search\Request\Query\Fulltext\SearchableFieldFilter</item>
<item name="nonStandardSearchableFieldFilter" xsi:type="object">Smile\ElasticsuiteCore\Search\Request\Query\Fulltext\NonStandardSearchableFieldFilter</item>
<item name="fuzzyFieldFilter" xsi:type="object">Smile\ElasticsuiteCore\Search\Request\Query\Fulltext\FuzzyFieldFilter</item>
<item name="nonStandardFuzzyFieldFilter" xsi:type="object">Smile\ElasticsuiteCore\Search\Request\Query\Fulltext\NonStandardFuzzyFieldFilter</item>
<item name="spannableFieldFilter" xsi:type="object">Smile\ElasticsuiteCore\Search\Request\Query\Fulltext\SpannableFieldFilter</item>
Expand Down

0 comments on commit be83195

Please sign in to comment.