jurismarches / luqum

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

Support implicit OR operation #9

Closed erlichmen closed 7 years ago

erlichmen commented 7 years ago

The following should be a valid lucene syntax:

name:bob city:nyc

it should equivalent to:

name:bob OR city:nyc

But I get UnknowOperation instead of OrOperation when parsing the string.

alexgarel commented 7 years ago

hello, sorry I'm on vacation, mainly AFK.

As a first short answer, the choice of OR or AND as the implicit operator is a choice than can be made later (see eg the default_operator argument in Query String Query and in luqum.elasticsearch.visitor.ElasticsearchQueryBuilder.__init__).

That's why the parser prefers to use this specific UnknowOperation node.

So you can either decide to use a visitor to replace the UnknownOperation to a OrOperation or treat UnknownOperation as a OrOperation in your code.

Hope it's clear enough !

alexgarel commented 7 years ago

Hello @erlichmen, can you get a look at https://github.com/jurismarches/luqum/pull/12 and tell me if this solutions seems ok to you.

alexgarel commented 7 years ago

@erlichmen did you look into it ? Without any response within two weeks I'll close this ticket. Thanks.

erlichmen commented 7 years ago

@alexgarel Works for me!.

impredicative commented 4 years ago

For any reader who is wondering how to use it:

from luqum.parser import parser
from luqum.tree import AndOperation
from luqum.utils import UnknownOperationResolver

unk_op_resolver = UnknownOperationResolver(AndOperation)
tree = unk_op_resolver(parser.parse('foo bar'))
alexgarel commented 4 years ago

good idea to put the code here @impredicative. There is also a reference in the doc