Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix suggest query names for Completion suggestor. (Finish work on #1098) #1836

Merged
merged 9 commits into from
Jun 7, 2024

Conversation

Caiofcas
Copy link
Contributor

@Caiofcas Caiofcas commented Jun 6, 2024

Basically a rebase of #1098. From what I understand it also closes #1650 (that is how I found the old PR).

If anything has changed in the code style from then I can adequate the work already done by tell-k, but it seems a small enough change.

Original PR description:

According to official documentation, Completion Suggester seems to be using correct prefix rather than text.

POST music/_search?pretty
{
    "suggest": {
        "song-suggest" : {
            "prefix" : "nir", 
            "completion" : { 
                "field" : "suggest" 
            }
        }
    }
}

According to official documentation, Completion Suggester seems to be using correct prefix rather than text.

POST music/_search?pretty
{
    "suggest": {
        "song-suggest" : {
            "prefix" : "nir", 
            "completion" : { 
                "field" : "suggest" 
            }
        }
    }
}

In the Search.suggest method, however, it always becomes text, so I fixed it.

In Completion Suggestor you can also specify regex.

POST music/_search?pretty
{
    "suggest": {
        "song-suggest" : {
            "regex" : "n[ever|i]r",
            "completion" : {
                "field" : "suggest"
            }
        }
    }
}

I also modified it so that the user can select it.

# Sample of use

# Term Suggester
s = s.suggest('song-suggest', 'nir', term={'field': 'suggest'})

# Completion Suggester + prefix query
s = s.suggest('song-suggest', 'nir', completion={'field': 'suggest'})

# Completion Suggester + regex query
s = s.suggest('song-suggest', regex='n[ever|i]r', completion={'field': 'suggest'})
# "regex"  must be keyword argument.

Please feel free to merge it. thx.

Copy link
Collaborator

@miguelgrinberg miguelgrinberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@miguelgrinberg miguelgrinberg merged commit 25dfc31 into elastic:main Jun 7, 2024
16 checks passed
@miguelgrinberg miguelgrinberg added the backport 8.x Backport to 8.x label Jun 7, 2024
github-actions bot pushed a commit that referenced this pull request Jun 7, 2024
…) (#1836)

* Add search_analyzer.

* Fix suggest query names for Completion suggestor.

* Fix that arguments validation is more strictly.

* refactor: add type hints to wrappers.py

* Revert "refactor: add type hints to wrappers.py"

This reverts commit 90f43ca.

* feat: readd regex implementation

---------

Co-authored-by: tell-k <ffk2005@gmail.com>
Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
(cherry picked from commit 25dfc31)
miguelgrinberg pushed a commit that referenced this pull request Jun 7, 2024
…) (#1836) (#1840)

* Add search_analyzer.

* Fix suggest query names for Completion suggestor.

* Fix that arguments validation is more strictly.

* refactor: add type hints to wrappers.py

* Revert "refactor: add type hints to wrappers.py"

This reverts commit 90f43ca.

* feat: readd regex implementation

---------

Co-authored-by: tell-k <ffk2005@gmail.com>
Co-authored-by: Miguel Grinberg <miguel.grinberg@gmail.com>
(cherry picked from commit 25dfc31)

Co-authored-by: Caio Fontes <38675540+Caiofcas@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 8.x Backport to 8.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regex suggester support
3 participants