lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: Building query to match a sub-string of a field
Date Thu, 01 Jul 2004 16:34:34 GMT
On Jun 29, 2004, at 5:28 PM, Terence Lai wrote:
> Hi Everyone,
>
> I am trying to construct a query which matches a sub-string of a 
> field. As an illustration, I would like to search the following words 
> by using the sub-string "test":
>
> - test
> - testing
> - contest
> - contestable
>
> I realize that Lucene does support wildcard searches using "*" and "?" 
> in the custom query. Therefore, the query string "*test*" should give 
> me the right result. However, the Lucene query syntax 
> (http://jakarta.apache.org/lucene/docs/queryparsersyntax.html) does 
> not allow the wildcard "*" as the first character of the search. 
> Therefore, the query "*test*" is invalid. Does anyone have a solution 
> to build the query to achieve the same result?

Query query = new WildcardQuery(new Term("field", "*test*"));

Careful with performance and term expansion on this though.

	Erik


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


Mime
View raw message