23 using System.Collections.Generic;
27 namespace Lucene.Net.Index.Memory
29 public partial class MemoryIndex
31 private sealed
partial class MemoryIndexReader
33 private class MemoryTermPositionVector : TermPositionVector
35 private readonly MemoryIndex _index;
36 private readonly
string _fieldName;
37 private readonly KeyValuePair<String,ArrayIntList>[] sortedTerms;
39 public MemoryTermPositionVector(MemoryIndex index, Info info,
string fieldName)
42 _fieldName = fieldName;
43 sortedTerms = info.SortedTerms;
48 get {
return _fieldName; }
53 get {
return sortedTerms.Length; }
56 public string[] GetTerms()
58 var terms =
new String[sortedTerms.Length];
59 for (
int i = sortedTerms.Length; --i >= 0; )
61 terms[i] = sortedTerms[i].Key;
66 public int[] GetTermFrequencies()
68 int[] freqs =
new int[sortedTerms.Length];
69 for (
int i = sortedTerms.Length; --i >= 0; )
71 freqs[i] = _index.NumPositions(sortedTerms[i].Value);
76 public int IndexOf(
string term)
78 int i = Array.BinarySearch(sortedTerms,
new KeyValuePair<string, ArrayIntList>(term, null), Info.ArrayIntListComparer);
79 return i >= 0 ? i : -1;
82 public int[] IndexesOf(
string[] terms,
int start,
int len)
84 int[] indexes =
new int[len];
85 for (
int i = 0; i < len; i++)
87 indexes[i] = IndexOf(terms[start++]);
92 public int[] GetTermPositions(
int index)
94 return sortedTerms[index].Value.ToArray(_index.stride);
97 public TermVectorOffsetInfo[] GetOffsets(
int index)
99 if (_index.stride == 1)
return null;
101 ArrayIntList positions = sortedTerms[index].Value;
102 int size = positions.Size();
103 TermVectorOffsetInfo[] offsets =
new TermVectorOffsetInfo[size / _index.stride];
105 for (
int i = 0, j = 1; j < size; i++, j += _index.stride)
107 int start = positions.Get(j);
108 int end = positions.Get(j + 1);
109 offsets[i] =
new TermVectorOffsetInfo(start, end);