0

I have attempted this with phrase, wildcard and keyword queries but nothing really works perfectly.

  ...    
    @Field(name = "firstLastName", index = org.hibernate.search.annotations.Index.YES, analyze = Analyze.NO, store = Store.NO)
    public String getFirstLastName() {
        return this.firstLastName;
    }
...

Now I want to query this field and return the correct results if a user types John Smith, Smith John or Smith Jo* or John Smi*....

junction = junction.should(qb.keyword().wildcard().onField("firstLastName")
                            .matching("John Smith*").createQuery());

If I search for just Smith or John given a keyword query, I get a hit. I am not analyzing the field as I didn't think I needed to but I tried it both ways with no success...

chrislhardin
  • 1,747
  • 1
  • 28
  • 44

1 Answers1

1

Several issues here:

  • You need to use an analyzer, be it only to split the strings on whitespaces. Define an analyzer and assign it to your field.
  • You can't use wildcard queries if you want the strings to be analyzed: wildcard queries are not analyzed. You should use an EdgeNGramFilter instead.

This answer to a very similar question will probably help: Hibernate Search: How to use wildcards correctly?

yrodiere
  • 9,280
  • 1
  • 13
  • 35