lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zhang, Lisheng" <>
Subject RE: Modify TermQueries or Tokens
Date Fri, 30 Apr 2010 21:29:27 GMT

In that case, I would do:

1) if I can somehow know the input words (like foo, nacho, ...), I will create
   lucene BooleanQuery myself, that's the case in my application.

2) if I have to accept whole input string with all logic (AND, OR, ..) inside,
   I think it is easier to change TermQuery afterwards than parsing the string,
   since final result from query parser should be BooleanQuery (in your example), 
   then we iterate through each BooleanClause, if the clause is still BooleanQuery, 
   recursively go deep, if TermQuery, we may try to convert to WildCardQuery?

   I have not done that myself before, but feel it should work.

Best regards, Lisheng

-----Original Message-----
From: Christopher Condit []
Sent: Friday, April 30, 2010 2:08 PM
Cc: Zhang, Lisheng
Subject: RE: Modify TermQueries or Tokens

Hi Lisheng-
>> On a small index that I have I'd like to query certain fields by adding wildcards
>> on either side of the term: foo -> *foo*. I realize the performance
>> implications but there are some cases where these terms are crammed
>> together in the indexed content (ie foonacho)  and I need to be able to
>> return this result when searching for foo or when searching for nacho. I'm
>> curious what the best way to modify the TermQuery object is. I thought
>> about doing it directly on the token as it gets parsed, but getNextToken() is
>> final. Then I thought I could iterate over the TermQueries under the returned
>> Query and change their term, but there's no setTerm method. Is the only
>> way to do this by modifying the query string? Or is there some more elegant
>> way to modify the terms in a Query object? Something else I haven't
>> considered?

> Lucene already have class WildcardQuery, I think you can add "*" on either
> side (or both), when creating Term:

What about a more complex query string like: (foo OR nacho) AND ("bar baz") OR cheese~1.2.
If I feed this to the MultiFieldQueryParser can I change the TermQueries afterward? Or am
I going to have write some code to modify the original string?

Thanks for your response,

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

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

View raw message