19 using System.Collections.Generic;
20 using Lucene.Net.Analysis.Tokenattributes;
21 using Lucene.Net.Util;
25 namespace Lucene.Net.Analysis
33 private bool enablePositionIncrements =
false;
57 this.stopWords = (CharArraySet) stopWords;
61 this.stopWords =
new CharArraySet(stopWords.Count, ignoreCase);
62 this.stopWords.AddAll(stopWords);
64 this.enablePositionIncrements = enablePositionIncrements;
65 termAtt = AddAttribute<ITermAttribute>();
66 posIncrAtt = AddAttribute<IPositionIncrementAttribute>();
77 : this(enablePositionIncrements, @in, stopWords, false)
87 public static ISet<string> MakeStopSet(params
string[] stopWords)
89 return MakeStopSet(stopWords,
false);
99 public static ISet<string> MakeStopSet(IList<object> stopWords)
101 return MakeStopSet(stopWords,
false);
108 public static ISet<string> MakeStopSet(
string[] stopWords,
bool ignoreCase)
110 var stopSet =
new CharArraySet(stopWords.Length, ignoreCase);
111 stopSet.AddAll(stopWords);
119 public static ISet<string> MakeStopSet(IList<object> stopWords,
bool ignoreCase)
121 var stopSet =
new CharArraySet(stopWords.Count, ignoreCase);
122 foreach(var word
in stopWords)
123 stopSet.Add(word.ToString());
128 public override bool IncrementToken()
131 int skippedPositions = 0;
132 while (input.IncrementToken())
134 if (!stopWords.Contains(termAtt.TermBuffer(), 0, termAtt.TermLength()))
136 if (enablePositionIncrements)
138 posIncrAtt.PositionIncrement = posIncrAtt.PositionIncrement + skippedPositions;
142 skippedPositions += posIncrAtt.PositionIncrement;
152 public static bool GetEnablePositionIncrementsVersionDefault(
Version matchVersion)
154 return matchVersion.OnOrAfter(
Version.LUCENE_29);
172 public bool EnablePositionIncrements
174 get {
return enablePositionIncrements; }
175 set { enablePositionIncrements = value; }