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 Sat, 01 May 2010 03:15:53 GMT

It looks good to me, but I did not test, when testing,
we may print out both

initialQuery.toString() // query produced by QueryParser
finalQuery.toString()   // query after your new function

as comparison, besides testing the query result.

Best regards, Lisheng

-----Original Message-----
From: Christopher Condit []
Sent: Friday, April 30, 2010 4:06 PM
Subject: RE: Modify TermQueries or Tokens

> 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?

protected static void wildcardQuery(Query query) {
		if (query instanceof BooleanQuery) {
			BooleanQuery bQuery = (BooleanQuery)query;
			for (BooleanClause clause: bQuery.getClauses()) {
				if (clause.getQuery() instanceof TermQuery) {
					Term term = ((TermQuery)clause.getQuery()).getTerm();
					clause.setQuery(new WildcardQuery(new Term(term.field(), "*" + term.text() + "*")));

Does the trick (as long as the original query is a BooleanQuery). Thanks for the suggestion!

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

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

View raw message