jurismarches / luqum

A lucene query parser generating ElasticSearch queries and more !
Other
188 stars 40 forks source link

Unknown item type Phrase in LuceneCheck #95

Open SleepyMorpheus opened 1 year ago

SleepyMorpheus commented 1 year ago

Hi, When using the LuceneCheck with the following query f:"Foo Bar" I expect the check to return no error because this is (as far as I can tell) allowed in the lucene query language. I use the following code below to test this.

from .parser import parser
from .check import LuceneCheck
from .tree import SearchField, Phrase

query = (SearchField("f", Phrase('"Foo Bar"')))
check = LuceneCheck()
print(check.errors(query))

But against my expectations I get the following error.

 ['Unknown item type Phrase : "Foo Bar"']

After checking the check.py file, it appears to me that no check_phrase function is present in the LuceneCheck class which leads to the phrase object not being accepted. I'm not really sure if this is intended behavior or how to fix it but following code snippet might solve the problem

   def check_phrase(self, item, parents):
        if not item.value.endswith('"') or not item.value.startswith('"'):
            yield "Phrase value must start and end with double quote"

Any recommendations or ideas about how to fix it? Or am I doing something wrong?