Hi, Just to make sure, below is the code I used to create wildcard query:
String field = "title"; String value = "mytitle"; Term term = new Term(field, "*" + value + "*"); WildcardQuery wildcardQuery = new WildcardQuery(term); I tested in 2.4.1 and it worked for me well. Best regards, Lisheng -----Original Message----- From: Zhang, Lisheng [mailto:lisheng.zh...@broadvision.com] Sent: Friday, April 30, 2010 1:41 PM To: java-user@lucene.apache.org Subject: RE: Modify TermQueries or Tokens Hi, Lucene already have class WildcardQuery, I think you can add "*" on either side (or both), when creating Term: http://lucene.apache.org/java/3_0_1/api/core/index.html But notice by default QueryParser cannot parse *queryString. Best regards, Lisheng -----Original Message----- From: Christopher Condit [mailto:con...@sdsc.edu] Sent: Friday, April 30, 2010 1:11 PM To: java-user@lucene.apache.org Subject: Modify TermQueries or Tokens 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? Thanks, -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 --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org