lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zhang, Lisheng" <Lisheng.Zh...@BroadVision.com>
Subject RE: Modify TermQueries or Tokens
Date Sat, 01 May 2010 03:15:53 GMT
Hi,

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 [mailto:condit@sdsc.edu]
Sent: Friday, April 30, 2010 4:06 PM
To: java-user@lucene.apache.org
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() + "*")));
				}
				else
					wildcardQuery(clause.getQuery());
			}			
		} 
	}

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

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message