ruflin/Elastica

The Phrase suggester should support multiple direct_generators

sergiuionescu opened this issue · 6 comments

The current Phrase suggester(https://github.com/ruflin/Elastica/blob/master/src/Suggest/Phrase.php#L12) only supports one generator. Subsequently calling \Elastica\Suggest\Phrase::addCandidateGenerator always overwrites the previous generator value.

According to https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html#_direct_generators multiple generators can be used. Ex:

{
    "suggest": {
        "text": "obel prize",
        "simple_phrase": {
            "phrase": {
                "field": "title.trigram",
                "size": 1,
                "direct_generator": [
                    {
                        "field": "title.trigram",
                        "suggest_mode": "always"
                    },
                    {
                        "field": "title.reverse",
                        "suggest_mode": "always",
                        "pre_filter": "reverse",
                        "post_filter": "reverse"
                    }
                ]
            }
        }
    }
}

At the moment the workaround we can use is:

\Elastica\Suggest\Phrase::setParam('direct_generator', [
    $trigramGenerator->toArray()['direct_generator'],
    $reverseGenerator->toArray()['direct_generator'],
])

Is it possible to update the Phrase suggester class to support a list of generators?

Thanks!

@sergiuionescu Interested to open a PR? 😇

@ruflin Please have a look at #1964 .
Please run the github action tests, i haven't been able to spin up the integration env locally.

Thanks! Test should always be run automatically.

@ruflin they are not run anymore automatically for new contributors.
I had to approve @sergiuionescu work for running the tests as github recently changed this behaviour to avoid abuses (crypto mining, ...).

Closing as #1964 was merged and fixed that.