jurismarches / luqum

A lucene query parser generating ElasticSearch queries and more !
Other
187 stars 42 forks source link

Is it possible to manipulate a parsed tree to add elements? #32

Closed paulo-serrao closed 6 years ago

paulo-serrao commented 6 years ago

I see on the documentation that we can manipulate the parsed tree in order to change the value of a field or expression. But is it possible to manipulate the tree in order to also append an extra element?

Example, manipulate:

dog: "Max" AND color: "brown"

into:

(name:"Max" AND animal:"dog") AND color: "brown"

I can already convert "dog" into "name" by using the LuceneTreeTransformer example on the documentation, but how about adding new nodes? Is it possible? If so can can anyone share a simple example?

Thanks

alexgarel commented 6 years ago

hi @paulo-serrao sorry for your request was forgotten.

Of course you can do what you want. The pattern of LuceneTreeTransformer is not very good, we may revise it in the future. But for time beeing, you can either :

LuceneTreeTransformer is just an helper, but you can build your own pattern (let us know of a better pattern !). If I was to do this again, I would better do a whole second copy of the tree, something closer to bolton remap pattern.

alexgarel commented 6 years ago

I close the issue, also because it's old. Feel free to reopen if needed.