1 package org.apache.lucene.search; 2 3 18 19 import java.io.IOException ; 20 import org.apache.lucene.index.Term; 21 import org.apache.lucene.index.TermEnum; 22 23 27 public abstract class FilteredTermEnum extends TermEnum { 28 private Term currentTerm = null; 29 private TermEnum actualEnum = null; 30 31 public FilteredTermEnum() {} 32 33 34 protected abstract boolean termCompare(Term term); 35 36 37 public abstract float difference(); 38 39 40 protected abstract boolean endEnum(); 41 42 protected void setEnum(TermEnum actualEnum) throws IOException { 43 this.actualEnum = actualEnum; 44 Term term = actualEnum.term(); 46 if (term != null && termCompare(term)) 47 currentTerm = term; 48 else next(); 49 } 50 51 55 public int docFreq() { 56 if (actualEnum == null) return -1; 57 return actualEnum.docFreq(); 58 } 59 60 61 public boolean next() throws IOException { 62 if (actualEnum == null) return false; currentTerm = null; 64 while (currentTerm == null) { 65 if (endEnum()) return false; 66 if (actualEnum.next()) { 67 Term term = actualEnum.term(); 68 if (termCompare(term)) { 69 currentTerm = term; 70 return true; 71 } 72 } 73 else return false; 74 } 75 currentTerm = null; 76 return false; 77 } 78 79 81 public Term term() { 82 return currentTerm; 83 } 84 85 86 public void close() throws IOException { 87 actualEnum.close(); 88 currentTerm = null; 89 actualEnum = null; 90 } 91 } 92 | Popular Tags |