Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 709
Logan Avatar asked Mar 27 '26 02:03

Logan


1 Answers

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.
like image 61
jpountz Avatar answered Mar 28 '26 16:03

jpountz