SyliusElasticsearchPlugin icon indicating copy to clipboard operation
SyliusElasticsearchPlugin copied to clipboard

Attribute/Option value with special characters doesn't work

Open ghost opened this issue 5 years ago • 3 comments

Hello,

When you try to filter by an attribute value which is : 1/2" or 1" It's will result to an empty products list. But there's some products with this value.

So there's a bug on filtering value with some special characters.

ghost avatar Dec 17 '19 08:12 ghost

Due to : https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#_reserved_characters

ghost avatar Jan 13 '20 10:01 ghost

Hi, I encountered the same problem, any insight on how to solve it ?

RedwanK avatar Jul 10 '20 13:07 RedwanK

We have found a bad workaround... But it's working... at least for attributes. Decorate HasAttributesQueryBuilder and then :

public function buildQuery(array $data): ?AbstractQuery
    {
        $attributeQuery = new BoolQuery();

        foreach ((array) $data['attribute_values'] as $attributeValue) {
            // Add match because it can handle keyword analyzer and then analyze special char like (/...
            $termQuery = new Match();
           // add keyword to find exact match with special char too
            $termQuery->setParam($data['attribute'].'.keyword', $attributeValue);
            $attributeQuery->addShould($termQuery);

            // 'Term' because it can handle boolean value too and not Match
            $termQuery = new Term();
            $termQuery->setTerm($data['attribute'], $attributeValue);
            $attributeQuery->addShould($termQuery);
        }


        return $attributeQuery;
    }

smashou avatar Jul 10 '20 15:07 smashou

Looks like outdated issue image

rafalmal avatar Mar 31 '23 12:03 rafalmal