简体   繁体   中英

How to ignore Stop words search using Lucene, when analysis of Stop Words is required?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM