How to suggest only single words but index phrases

2019-09-09 14:03发布

问题:

I am having troubles right now. I am using ShingleAnalyzerWrapper to index phrases. But I need the SpellChecker to suggest me only single words.

How can i index phrases but search for both phrases and single words with SpellChecker?

Please, give some advice.

回答1:

Use this constructor, for your ShingleAnalyzerWrapper

ShingleAnalyzerWrapper(Analyzer defaultAnalyzer, 
                       int minShingleSize, 
                       int maxShingleSize, 
                       String tokenSeparator, 
                       boolean outputUnigrams, 
                       boolean outputUnigramsIfNoShingles)

passing true as the fifth argument (outputUnigrams). This will index all single tokens regardless of what you minShingleSize is. If your current minShingleSize is 2, you could just lower that to 1 to achieve the same result.