19 using System.Collections.Generic;
20 using Lucene.Net.Analysis;
21 using Lucene.Net.Analysis.Tokenattributes;
22 using Lucene.Net.Index;
23 using Lucene.Net.Index.Memory;
24 using Lucene.Net.Search.Spans;
25 using Lucene.Net.Support;
26 using Lucene.Net.Util;
28 namespace Lucene.Net.Search.Highlight
39 private float totalScore;
40 private ISet<String> foundTerms;
41 private IDictionary<String, WeightedSpanTerm> fieldWeightedSpanTerms;
42 private float maxTermWeight;
43 private int position = -1;
44 private String defaultField;
47 private bool expandMultiTermQuery =
true;
51 private bool skipInitExtractor;
52 private bool wrapToCaching =
true;
60 Init(query, null, null,
true);
70 Init(query, field, null,
true);
81 Init(query, field, reader,
true);
94 Init(query, field, reader,
true);
107 Init(query, field, null,
true);
116 this.fieldWeightedSpanTerms =
new HashMap<String, WeightedSpanTerm>(weightedTerms.Length);
122 if ((existingTerm == null) ||
127 fieldWeightedSpanTerms[t.
Term] = t;
128 maxTermWeight = Math.Max(maxTermWeight, t.
Weight);
131 skipInitExtractor =
true;
135 public float FragmentScore
137 get {
return totalScore; }
143 public float MaxTermWeight
145 get {
return maxTermWeight; }
149 public float GetTokenScore()
151 position += posIncAtt.PositionIncrement;
152 String termText = termAtt.
Term;
156 if ((weightedSpanTerm = fieldWeightedSpanTerms[termText]) == null)
167 float score = weightedSpanTerm.
Weight;
170 if (!foundTerms.Contains(termText))
173 foundTerms.Add(termText);
185 if (!skipInitExtractor)
187 if (fieldWeightedSpanTerms != null)
189 fieldWeightedSpanTerms.Clear();
191 return InitExtractor(tokenStream);
204 return fieldWeightedSpanTerms[token];
207 private void Init(
Query query, String field,
IndexReader reader,
bool expandMultiTermQuery)
209 this.reader = reader;
210 this.expandMultiTermQuery = expandMultiTermQuery;
217 WeightedSpanTermExtractor qse = defaultField == null
218 ?
new WeightedSpanTermExtractor()
219 : new WeightedSpanTermExtractor(defaultField);
221 qse.ExpandMultiTermQuery = expandMultiTermQuery;
222 qse.SetWrapIfNotCachingTokenFilter(wrapToCaching);
225 this.fieldWeightedSpanTerms = qse.GetWeightedSpanTerms(query,
230 this.fieldWeightedSpanTerms = qse.GetWeightedSpanTermsWithScores(query,
231 tokenStream, field, reader);
233 if (qse.IsCachedTokenStream)
235 return qse.TokenStream;
244 foundTerms = Support.Compatibility.SetFactory.CreateHashSet<
string>();
252 public bool IsExpandMultiTermQuery
254 get {
return expandMultiTermQuery; }
255 set { this.expandMultiTermQuery = value; }
265 public void SetWrapIfNotCachingTokenFilter(
bool wrap)
267 this.wrapToCaching = wrap;