tags:

views:

325

answers:

3

I am using the Lucene search engine but it only seems to find matches that occur at the beginning of terms.

For example: Searching for "one" would match "onematch" or "one day a time" but not "loneranger".

The Lucene doc says it doesnt support wildcards at the front of a search string so I am not sure whether Lucene even searches inter-term matches or only can match documents that start with the search term.

Is this a problem with how I have created my index, how I am building my search query or just a limitation of Lucene?

A: 

Lucene will find a document if the search term appears anywhere within it, but it doesn't allow you to do wildcard queries where the wildcard is on the front of the search term, because it performs horribly. If that is functionality you care about, you will either have to do some low-level Lucene hacking change a config flag (thanks for the interesting link), find a third-party library that has already done that hacking, or find a different search implementation (for small enough datasets, the built in search from a lot of RDBMS engines is sufficient).

Hank Gay
+2  A: 

Found some info in another post here on Stack Overflow [LUCENE.NET] Leading wildcard throws an error"

You can set the SetAllowLeadingWildcardCharacters property on your Query Parser to allow leading wildcards during your search. This will of course have the obvious large performance impact but will allow user to find matches within a search term.

Marcus Erickson
A: 

Your query should be

"Query query = new WildcardQuery(new Term("contents", "*one *"));"

where contents is the field name in which you are searching.

"one" should be enclosed with asterisk mark. I have given space in the query after *one but there should not be any space. without space the * is not displaying that is why I added star.

lucene user