lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Condit <con...@sdsc.edu>
Subject RE: Modify TermQueries or Tokens
Date Fri, 30 Apr 2010 23:05:37 GMT
> 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


Mime
View raw message