18 #if LUCENENET_350 //Lucene.Net specific code. See https://issues.apache.org/jira/browse/LUCENENET-350
21 using System.Collections.Generic;
22 using Lucene.Net.Index;
24 namespace Lucene.Net.Search.Vectorhighlight
26 public class VectorHighlightMapper : TermVectorMapper, ITermFreqVector, TermPositionVector
28 private readonly List<string> _terms;
29 private Dictionary<string, TermVectorOffsetInfo[]> _tvoi;
30 private Dictionary<string, int[]> _positions;
31 private Dictionary<string, int> _frequency;
32 private List<string> _indexMap;
33 private string _field;
34 private bool _storeOffsets;
35 private bool _storePositions;
37 public VectorHighlightMapper(List<string> terms)
40 _tvoi =
new Dictionary<string, TermVectorOffsetInfo[]>();
41 _positions =
new Dictionary<string, int[]>();
42 _frequency =
new Dictionary<string, int>();
43 _indexMap =
new List<string>();
46 public override void SetExpectations(
string field,
int numTerms,
bool storeOffsets,
bool storePositions)
49 _storeOffsets = storeOffsets;
50 _storePositions = storePositions;
52 _tvoi =
new Dictionary<string, TermVectorOffsetInfo[]>(numTerms);
54 _positions =
new Dictionary<string, int[]>(numTerms);
55 _frequency =
new Dictionary<string, int>(numTerms);
56 _indexMap =
new List<string>(numTerms);
59 public override void Map(
string term,
int frequency, TermVectorOffsetInfo[] offsets,
int[] positions)
61 if (StringUtils.AnyTermMatch(_terms, term))
65 _tvoi.Add(term, offsets);
67 _positions.Add(term, positions);
68 _frequency.Add(term,frequency);
74 get {
return _field; }
79 get {
return _tvoi.Count; }
82 public string[] GetTerms()
84 string[] result =
new string[_tvoi.Count];
85 _tvoi.Keys.CopyTo(result,0);
89 public int[] GetTermFrequencies()
91 int[] result =
new int[_frequency.Count];
92 _frequency.Values.CopyTo(result,0);
96 public int IndexOf(
string term)
98 return _indexMap.IndexOf(term);
101 public int[] IndexesOf(
string[] terms,
int start,
int len)
103 int[] result =
new int[terms.Length];
104 for (
int i = 0; i < terms.Length; i++)
106 string term = terms[i];
107 result[i] = _indexMap.IndexOf(term, start, len);
112 public int[] GetTermPositions(
int index)
114 if (index<_positions.Count)
116 string key = _indexMap[index];
117 return _positions[key];
122 public TermVectorOffsetInfo[] GetOffsets(
int index)
124 if (index < _tvoi.Count)
126 string key = _indexMap[index];
129 return new TermVectorOffsetInfo[0];