lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Trying to create NEAR option in QueryParser -- ideas/help
Date Sun, 13 Jan 2002 02:04:15 GMT

I am trying to implement a NEAR option in the QueryParser.jj.

First I have to say, Brian Goetz has done an awesome job putting this 
I rely on it all the time, and it's solid and very complex especially if 
you don't know JavaCC

Now to my question.

Overview of how I think the QueryParser works:
The basis for the QueryParser is to break up everything into the 
appropriate type of Query (TermQuery, PhraseQuery, ...), by the matching 
the query pattern. Then to combine these queries into a collection of 
BooleanClauses and finally BooleanQueries.

Now the NEAR option will only work with phrase searches since that is 
the only place where you can set the slop factor.

So I had two thoughts.
1) Create a new pattern <TERM> "NEAR"<NUM>+ <TERM>
The problem I have with this, is that I don't think it will work since 
the parser will see <TERM> and never look for the "NEAR" option.

2) Retroactively make a TermQuery a PhraseQuery with a set slop.
This is somewhat how the AND conjunction works. I am proposing taking 
the previous BooleanClause and, check to see if the query is  a 
TermQuery. If so then extract the Term and replace the query in the 
BooleanClause with the new PhraseQuery. However, in trying to do this I 
find that I cannot extract the Term from the TermQuery because there is 
no getTerm() from the TermQuery. I don't think it would be difficult to 
add, but I there might be other issues.

Any thoughts or idea will be helpful.



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

View raw message