Logan
Logan

Reputation: 2505

WildcardQuery not returning correct result

I have created an index using some data. Now I am using WildcardQuery to search this data. The documents indexed have a field name Product Code against which I am searching.

Below is the code that I am using for creating the query and searching:

Term productCodeTerm = new Term("Product Code", "*"+searchText+"*");

query = new WildcardQuery(productCodeTerm);

searcher.search(query, 100);

The searchText variable contains the search string that is used to search the index. In case when searchString is 'jf', I get the following result:

JF32358
JF5215
JF2592

Now, when I try to search using 25, or f2 or f3 or anything else other than using only j,f,jf, then the query has no hits.

I am not able to understand why it is happening. Can someone help me understand the reason the search is behaving in this way?

Upvotes: 3

Views: 1321

Answers (2)

jpountz
jpountz

Reputation: 9964

What analyzer did you use at indexing time? Given your examples, you should make sure that your analyzer:

  • does lowercasing,
  • does not remove digits,
  • does not split at boundaries between letters and digits.

Upvotes: 2

Parvin Gasimzade
Parvin Gasimzade

Reputation: 26012

In the lucene FAQ page it says :

Leading wildcards (e.g. *ook) are not supported by the QueryParser by default. As of Lucene 2.1, they can be enabled by calling QueryParser.setAllowLeadingWildcard( true ). Note that this can be an expensive operation: it requires scanning the list of tokens in the index in its entirety to look for those that match the pattern.

For more information check here.

Upvotes: 0

Related Questions