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:con...@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-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org