lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Earwin Burrfoot (JIRA)" <>
Subject [jira] [Commented] (LUCENE-3041) Support Query Visting / Walking
Date Fri, 29 Apr 2011 17:08:03 GMT


Earwin Burrfoot commented on LUCENE-3041:

I vehemently oppose introducing the "visitor design pattern" (classic double-dispatch version)
into the Query API. It is a badly broken replacement (ie, cannot be easily extended) for multiple

Also, from the looks of it (short IRC discussion), user-written visitors and rewrite() API
have totally different aims.
- rewrite() is very specific (it is a pre-search preparation that produces runnable query,
eg expands multi-term queries into OR sequences or wrapped filters), but should work over
any kinds of user-written Queries with possibly exotic behaviours (eg, take rewrite from the
cache). Consequently, the logic is tightly coupled to each Query-impl innards.
- user-written visitors on the other hand, may have a multitude of purporses (wildly varying
logic for node handling + navigation - eg, some may want to see MTQs expanded, and some may
not) over relatively fixed number of possible node types.

So the best possible solution so far is to keep rewrite() asis - it serves its purporse quite
And introduce generic reflection-based multiple-dispatch visitor that can walk any kind of
hierarchies (eg, in my project I rewrite ASTs to ASTs, ASTs to Queries, and Queries to bags
of Terms) so people can transform their query trees.
The current patch contains a derivative of [my original version|].
And here's a [test/example|]
This visitor keeps all logic on itself and thus cannot replace rewrite().

> Support Query Visting / Walking
> -------------------------------
>                 Key: LUCENE-3041
>                 URL:
>             Project: Lucene - Java
>          Issue Type: Improvement
>          Components: Search
>            Reporter: Chris Male
>            Priority: Minor
>         Attachments: LUCENE-3041.patch, LUCENE-3041.patch, LUCENE-3041.patch, LUCENE-3041.patch
> Out of the discussion in LUCENE-2868, it could be useful to add a generic Query Visitor
/ Walker that could be used for more advanced rewriting, optimizations or anything that requires
state to be stored as each Query is visited.
> We could keep the interface very simple:
> {code}
> public interface QueryVisitor {
>   Query visit(Query query);
> }
> {code}
> and then use a reflection based visitor like Earwin suggested, which would allow implementators
to provide visit methods for just Querys that they are interested in.

This message is automatically generated by JIRA.
For more information on JIRA, see:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message