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 MemoryTermEnum :
TermEnum
35 private readonly MemoryIndex _index;
36 private readonly MemoryIndexReader _reader;
40 public MemoryTermEnum(MemoryIndex index, MemoryIndexReader reader,
int ix,
int jx)
48 public override bool Next()
50 if (DEBUG) System.Diagnostics.Debug.WriteLine(
"TermEnum.next");
51 if (_j >= _index.sortedFields.Length)
return false;
52 Info info = _reader.GetInfo(_j);
53 if (++_i < info.SortedTerms.Length)
return true;
58 if (_j >= _index.sortedFields.Length)
return false;
59 _reader.GetInfo(_j).SortTerms();
67 if (DEBUG) System.Diagnostics.Debug.WriteLine(
"TermEnum.term: " + _i);
68 if (_j >= _index.sortedFields.Length)
return null;
69 Info info = _reader.GetInfo(_j);
70 if (_i >= info.SortedTerms.Length)
return null;
72 return CreateTerm(info, _j, info.SortedTerms[_i].Key);
76 public override int DocFreq()
78 if (DEBUG) System.Diagnostics.Debug.WriteLine(
"TermEnum.docFreq");
79 if (_j >= _index.sortedFields.Length)
return 0;
80 Info info = _reader.GetInfo(_j);
81 if (_i >= info.SortedTerms.Length)
return 0;
82 return _index.NumPositions(info.GetPositions(_i));
85 protected override void Dispose(
bool disposing)
87 if (DEBUG) System.Diagnostics.Debug.WriteLine(
"TermEnum.close");
90 private Term CreateTerm(Info info,
int pos,
string text)
93 Term template = info.template;
94 if (
template == null) {
95 String fieldName = _index.sortedFields[pos].Key;
96 template =
new Term(fieldName);
97 info.template =
template;
100 return template.CreateTerm(text);