lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Denner <>
Subject Refactoring suggestion for query parsing and creation
Date Mon, 07 Feb 2005 16:56:30 GMT

I have been working with Lucene for about a month now and I am really 
impressed by the work of the people involved.  I did, however, come across 
something that I thought my be better refactored: extending the QueryParser 
to add your own handling of various Query implementations.  So I had a go at 
introducing a QueryFactory interface that classes can implement to provide 
construction of these Query implementations, and then an instance can be 
passed to a QueryParser instance for it to use.  I have a patch that provides 
this if the developers of Lucene are interested but, because it is a quite 
dramatic change (it removes alot of deprecated methods which I was very 
worried about) I would prefer someone to take a look at it and see if they 
think it is worthwhile.

The reason I made this patch is that I wanted to deal with integer ranges for 
a particular field in my application and, like I said, extending QueryParser 
felt wrong to me (and took me almost a week to actually find!).  With the 
patch I write:

QueryParser parser = 
  new QueryParser(
    new StandardAnalyzer(),
    new SpecialQueryFactory(new QueryFactoryImpl()));

And my specialised QueryFactory implementation gets used during parsing.  The 
implementation of QueryFactoryImpl was created by moving those methods that 
created Query instances in the original QueryFactory into a separate class.  
I also created a MultiFieldQueryFactory implementation that takes the methods 
from MultiFieldQueryParser (effectively making it now redundant).

Personally I prefer the idea of composition over inheritance, in this 
circumstance, but I can understand why other people would not want this.

Anyway, if someone would like to see the patch (made against the HEAD of the 
Lucene CVS code) I can provide it; or you can tell me where to go!  Either 
way, Lucene has still made searching so much easier and I thank you.


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

View raw message