19 using System.Collections;
20 using System.Collections.Generic;
24 using Lucene.Net.Util;
26 namespace Lucene.Net.Index
49 public abstract class FieldEnumerator<T> : IDisposable
79 private bool disposed;
89 this.Init(reader, field,
true);
99 protected void Init(
IndexReader reader,
string fieldName,
bool includeDocs)
101 this.termEnum = reader.
Terms(
new Term(fieldName));
105 this.tdEnum =
new TermDocEnumerator.TermDocUsingTermsEnumerator(this.termDocs, this.termEnum);
107 this.tEnum =
new TermEnumerator(termEnum, termDocs, fieldName,
this);
117 protected abstract bool TryParse(
string s);
122 public TermEnumerator Terms
124 get {
return this.tEnum; }
134 if (this.termDocs == null)
136 throw new NotSupportedException(
"This instance does not support enumeration over the document ids.");
145 #region IDisposable Members
150 public void Dispose()
154 this.disposed =
true;
155 if (this.termEnum != null)
157 this.termEnum.Close();
159 if (this.termDocs != null)
161 this.termDocs.Close();
163 GC.SuppressFinalize(
this);
172 public class TermEnumerator : IEnumerator<T>, IEnumerable<T>
187 private Term currentTerm;
197 private bool isFirst =
true;
213 this.termEnum = termEnum;
214 this.termDocs = termDocs;
215 this.fieldName = field;
216 this.enclosing = enclosing;
219 #region IEnumerator<T> Members
232 #region IEnumerator Members
237 object IEnumerator.Current
239 get {
return (
object)this.Current; }
246 public bool MoveNext()
250 this.isFirst =
false;
254 if (!this.termEnum.Next())
260 this.currentTerm = termEnum.Term;
261 if (this.currentTerm == null || (!this.currentTerm.Field.Equals(
this.fieldName)))
266 if (this.enclosing.TryParse(
this.currentTerm.Text))
268 if (this.termDocs != null)
270 this.termDocs.Seek(this.termEnum);
283 throw new NotSupportedException(
"The enumerator cannot be reset");
288 #region IDisposable Members
290 public void Dispose()
297 #region IEnumerable<T> Members
303 public IEnumerator<T> GetEnumerator()
310 #region IEnumerable Members
316 IEnumerator IEnumerable.GetEnumerator()
318 return this.GetEnumerator();
343 this.termDocs = termDocs;
352 this.termDocs.
Seek(t);
355 #region IEnumerable<int> Members
357 public IEnumerator<int> GetEnumerator()
364 #region IEnumerable Members
366 IEnumerator IEnumerable.GetEnumerator()
368 return this.GetEnumerator();
373 #region IDisposable Members
378 public void Dispose()
380 if (this.termDocs != null)
410 :
this(termDocs, null)
421 this.termEnum = termEnum;
430 this.termDocs.
Seek(te);
433 #region IEnumerable<int> Members
439 public IEnumerator<int> GetEnumerator()
446 #region IEnumerable Members
452 IEnumerator IEnumerable.GetEnumerator()
454 return this.GetEnumerator();
459 #region IEnumerator<int> Members
466 get {
return this.termDocs.
Doc; }
471 #region IDisposable Members
476 public void Dispose()
484 #region IEnumerator Members
489 object IEnumerator.Current
491 get {
throw new NotImplementedException(); }
498 public bool MoveNext()
500 return this.termDocs.
Next();
508 throw new NotImplementedException();
528 this.Init(reader, fieldName);
539 this.Init(reader, fieldName, includeDocs);
547 protected override bool TryParse(
string s)
549 this.tEnum.Current = s;
558 public abstract class NumericFieldEnum<T> : FieldEnumerator<T>
574 base.Init(reader, field, includeDocs);
575 this.parser = parser;
583 protected override bool TryParse(
string s)
587 return this.TryParseNumeric(s);
591 return this.TryParseString(s);
600 protected abstract bool TryParseString(
string s);
607 protected abstract bool TryParseNumeric(
string s);
622 this.Init(reader, fieldName,
true, parser);
633 this.Init(reader, fieldName, includeDocs, parser);
641 protected override bool TryParseString(
string s)
643 this.tEnum.Current = Int32.Parse(s);
653 protected override bool TryParseNumeric(
string s)
656 if (shift > 0 && shift <= 31)
681 this.Init(reader, fieldName,
true, parser);
692 this.Init(reader, fieldName, includeDocs, parser);
700 protected override bool TryParseString(
string s)
702 this.tEnum.Current =
float.Parse(s);
712 protected override bool TryParseNumeric(
string s)
715 if (shift > 0 && shift <= 31)
739 this.Init(reader, fieldName,
true, parser);
750 this.Init(reader, fieldName, includeDocs, parser);
758 protected override bool TryParseString(
string s)
760 this.tEnum.Current =
Double.Parse(s);
770 protected override bool TryParseNumeric(
string s)
773 if (shift > 0 && shift <= 63)
797 this.Init(reader, fieldName,
true, parser);
808 this.Init(reader, fieldName, includeDocs, parser);
816 protected override bool TryParseString(
string s)
818 this.tEnum.Current =
long.Parse(s);
828 protected override bool TryParseNumeric(
string s)
831 if (shift > 0 && shift <= 63)