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

"Field expression is not valid" for Range in LuceneCheck #92

Open
SleepyMorpheus opened this issue Mar 27, 2023 · 1 comment
Open

"Field expression is not valid" for Range in LuceneCheck #92

SleepyMorpheus opened this issue Mar 27, 2023 · 1 comment

Comments

@SleepyMorpheus
Copy link

Hi,
I'm running the following snipped to parse and check a lucene query with the luqum=0.12.1 packet.

from luqum.parser import parser
from luqum.check import LuceneCheck

query = parser.parse('size:[1 TO 10]')
check = LuceneCheck()
print(check.errors(query))

I expect there to be no error as this is a valid query as mentioned in the official documentation of elastic. But instead the LuceneCheck returns the following error:

['field expression is not valid : size:[1 TO 10]']

I therefore suspect that there might be a problem in the check.py module. Can anyone confirm my findings or is this a problem on my end?

@SleepyMorpheus
Copy link
Author

After checking out the check.py file it appears to me that the following check fails when parsing a SearchField with a Range as expr:

    SIMPLE_EXPR_FIELDS = (
        tree.Boost, tree.Proximity, tree.Fuzzy, tree.Word, tree.Phrase)

    FIELD_EXPR_FIELDS = tuple(list(SIMPLE_EXPR_FIELDS) + [tree.FieldGroup])

    # .....

    @_check_children
    def check_search_field(self, item, parents):
        if not self._check_field_name(item.name):
            yield "%s is not a valid field name" % item.name
        if not isinstance(item.expr, self.FIELD_EXPR_FIELDS):
            yield "field expression is not valid : %s" % item

In my opinion the tree.Range class should be a member of FIELD_EXPR_FIELDS as it is a valid lucene statement. I have therefore added the class to the list as well as created a dedicated test called test_search_field_range.

Would this work or am I forgetting something here?

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 a pull request may close this issue.

1 participant