1
votes

How to ignore Stop words during Lucene Search?

I have analyzed all data including Stop Words using Custom Analyzer because it is requirement in most of the searches.

But in solution another requirement jumps in for one of module, which says to exclude Stop words from searches, on same fields, where Stop words are already Analyzed.

While analysis

@Fields({@Field(index = Index.YES, store = Store.NO, analyzer = @Analyzer(impl=CustomStopWordsAccepterAnalyzer.class)),

Now requirement say to ignore stop word when search string have "Love With Hubby" and return best score results using Love Hubby. Kindly suggest!

1

1 Answers

0
votes

Once you enabled stopwords for a Field, the stopwords are effectively not encoded in the index so they can not be made to re-appear during query time.

The problem you have is quite common, as often people need to combine the score of multiple full-text queries performed with different options.

The solution is rather simple: for each property of your Java Entity, use multiple @Field annotations and assign a different index fieldname to each. This way you can target each different field with a BooleanQuery and have the scores of the output take both fields into account.