lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kasper van den Berg <>
Subject Programmatically create proximity or slop queries using Lucene's flexible parser
Date Tue, 18 Jun 2013 09:44:47 GMT
Hi all,

(Cross posted to stackoverflow yesterday (, no
answers at SO yet, perhaps java-users@lucene is a better place for this question; I hope not
to annoy any of you with these duplicate messages)

In Lucene (currently using version 4.1) using Lucene's flexible query parser , is it possible
to build(…) proximity queries from ProximityQueryNode?

The code uses a flexible parser in order to parse (partial) queries read from a file into
QueryNode; process these QueryNodes; and finally search using the built queries.

The three phases of the flexible parser:
* Parsing, does what I want it to do.
  The StandardSyntaxParser parses even complex queries with proximity operators (for example
"(\"letter comes\"~3 \"agitated employees\"~4 \"worried about salaries\"~1) AND (\"letter
comes agitated employees worried about salaries\"~8)" parses correctly (to a group containing
SlopQueryNode; having slop queries is adequate).

* Processing, removes proximity and slop nodes from the tree; skipping processing might work
and allows avoiding this problem.

* Building, replaces proximity and slop with BooleanQuery or ignores it and emits TermQuery
even for unprocessed QueryNode trees that do contain ProximityQueryNodes.

What can I do, so that Lucene parses partial queries to QueryNode parse trees, expand the
trees to search for other terms nearby, and submit the query to the searcher?


Lucene version 4.1, if needed I'll upgrade to 4.3.2
Parser ….flexible.standard.Standard, if needed I can switch parser but preferably one of
the flexible ones.

With kind regards,

Aan dit bericht kunnen geen rechten worden ontleend. Het bericht is alleen bestemd voor de
geadresseerde. Indien dit bericht niet voor u is bestemd, verzoeken wij u dit onmiddellijk
aan ons te melden en de inhoud van het bericht te vernietigen.

This message shall not constitute any obligations. This message is intended solely for the
addressee. If you have received this message in error, please inform us immediately and delete
its contents.
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message