FOSElasticaBundle icon indicating copy to clipboard operation
FOSElasticaBundle copied to clipboard

Finder does not apply analyzer from config when searching

Open ghost opened this issue 4 years ago • 0 comments

Hello,

Elasticsearch version: 6.0 FosElasticaBundle version: 5.2 Symfony version: 3.4

Recently I've applied the serch code from the Documentation to my code. I did this, due to finding out that the finder didnt use the analyzer given in the config. It works and looks the following:

            $finder = $this->container->get('fos_elastica.finder.category.de');
            $boolQuery = new \Elastica\Query\BoolQuery();
            $fieldQuery = new \Elastica\Query\Match();
            $fieldQuery->setFieldQuery('description',  strtolower($searchstring));
            $fieldQuery->setFieldParam('description', 'analyzer', 'default');
            $boolQuery->addShould($fieldQuery);
            $finder->find($boolQuery);

Config:

fos_elastica:
    clients:
        default: { url: '%fos.elastica.auth_url%' }
    indexes:
        category:
            index_name: index_name
            settings:
                index:
                    analysis:
                        analyzer:
                            default:
                                tokenizer: standard
                                filter: [ standard, lowercase, asciifolding, german_stem ]

            types:
                de:
                    properties:
                        name: ~
                        description: { analyzer: default }
                    persistence:
                        driver: phpcr
                        model: AppBundle\Document\Category
                        finder: ~

Is it possible for me to shorten the code similar to this manner and applying the analyzer automatically given from the config?

$finder->find($searchString);

I can't tell whether my config is missing something or generally if I am doing something wrong. Or maybe it isn't intended to work the way I'd expect.

In any case, cheers and thanks for taking your time!

ghost avatar Dec 18 '20 19:12 ghost