1、分析器可以剔除所有停用词,并将这些词本来所处的位置留空,还可以对词干过滤器进行选择
2、移除停用词
public class PositionStopFilter extends TokenFilter{
private Set stopWords;
publicPositioinStopFilter(TokenSteam in,Set stpWords){
super(in);
this.stopWords=stopWords;
}
public final Token next()throws IOException{
int increment=0;
for(Token token=input.next();token!=null;token=input.next()){
if (!stopWords.contains(token.termText())){
token.getPositionIncrement()+increment;
return token;
}
increment++;
}
return null;
}
3、自己定义的分析器
public class PositionalPorterStopAnalyer extends Analyer{
private Set stopWords;
publicPositionalPortStopAnalyer(){
this(StopAnalyzer.ENGLISH_STOP_WORDS);
}
publicPositionalPortStopAnalyzer(String[] stopList){
stopWords=stopFilter.makeStopset(stopList);
}
//下面的代码使用了词干还原PorterStemFilter
public TokenStreamtokenStream(String fieldName,Reader reader){
return new PorterStemFilter(
new PositionalStopFilter{
new LowerCaseTokenizer(reader),stopwords));
}
)
}
}
4、使用PharseQuery允许查询的短语有空缺,但是必须使用setPhraseSlop(n)进行设置,将空缺设置为n,空缺一般是停用词造成的。