[ https://issues.apache.org/jira/browse/LUCENE-3041?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13027080#comment-13027080 ]
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 dispatch. 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 well. 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|https://gist.github.com/dfebaf79f5524e6ea8b4]. And here's a [test/example|https://gist.github.com/e5eb67d762be0bce8d28] This visitor keeps all logic on itself and thus cannot replace rewrite(). > Support Query Visting / Walking > ------------------------------- > > Key: LUCENE-3041 > URL: https://issues.apache.org/jira/browse/LUCENE-3041 > 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: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org For additional commands, e-mail: dev-h...@lucene.apache.org