Skip to content

Conversation

@tell-k
Copy link
Contributor

@tell-k tell-k commented Dec 30, 2018

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.

@tell-k
Copy link
Contributor Author

tell-k commented Jan 11, 2019

@honzakral

Is there any problem with this PR?
If there are problems, I'll fix them.

thx :)

Copy link
Contributor

@honzakral honzakral left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, and for the ping. Nothing wrong with the PR except for my lack of time :)

I added a short comment where I think we can do a bit better for easier code, if you agree then we can merge the PR.

"""
if text is None and regex is None:
raise ValueError('You have to pass "text" or "regex" argument.')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need additional validation rules here - if you supply both text and regex or you supply regex and completion is not in kwargs etc - any invalida combination essentially should raise a ValueError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, i'll fix it more strictly.

query_name= 'regex'
query_text = regex

s._suggest[name] = {query_name: query_text}
Copy link
Contributor

Choose a reason for hiding this comment

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

once we have validated out all the invalid combinations we should be ok with simpler code:

d = s._suggest[name] = kwargs
if text:
    d['text'] = text
else:
    d['regex'] = regex

@tell-k
Copy link
Contributor Author

tell-k commented Jan 14, 2019

@honzakral

Thank you for your review.
I fixed the points pointed out by you.
Please feel free to review it again.

I pray that you can afford the time :)

@tell-k
Copy link
Contributor Author

tell-k commented Feb 6, 2019

@honzakral

Can you review this PR again ?
If there's anything I can do for you, please let me know. Thx :)

@tell-k
Copy link
Contributor Author

tell-k commented May 14, 2019

@honzakral Any chance you can review and merge this?

@sethmlarson
Copy link
Contributor

Closing this PR as it's gone stale, rebase on master and I'll review again

@sethmlarson sethmlarson closed this Dec 7, 2020
miguelgrinberg added 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 <[email protected]>
Co-authored-by: Miguel Grinberg <[email protected]>
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 <[email protected]>
Co-authored-by: Miguel Grinberg <[email protected]>
(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 <[email protected]>
Co-authored-by: Miguel Grinberg <[email protected]>
(cherry picked from commit 25dfc31)

Co-authored-by: Caio Fontes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants