lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject cvs commit: jakarta-lucene/src/java/org/apache/lucene/search DateFilter.java
Date Sat, 13 Sep 2003 10:44:25 GMT
ehatcher    2003/09/13 03:44:24

  Modified:    src/java/org/apache/lucene/search DateFilter.java
  Log:
  Reformatted and added inclusive notes to contructors/factories
  
  Revision  Changes    Path
  1.7       +115 -94   jakarta-lucene/src/java/org/apache/lucene/search/DateFilter.java
  
  Index: DateFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-lucene/src/java/org/apache/lucene/search/DateFilter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DateFilter.java	12 Aug 2003 09:17:53 -0000	1.6
  +++ DateFilter.java	13 Sep 2003 10:44:24 -0000	1.7
  @@ -64,102 +64,123 @@
   import org.apache.lucene.index.TermEnum;
   import org.apache.lucene.index.IndexReader;
   
  -/** A Filter that restricts search results to a range of time.
  +/**
  + * A Filter that restricts search results to a range of time.
  + *
  + * <p>For this to work, documents must have been indexed with a
  + * {@link DateField}.
  + */
  +public class DateFilter extends Filter {
  +    String field;
   
  -   <p>For this to work, documents must have been indexed with a {@link
  -   DateField}.  */
  +    String start = DateField.MIN_DATE_STRING();
  +    String end = DateField.MAX_DATE_STRING();
   
  -public class DateFilter extends Filter {
  -  String field;
  +    private DateFilter(String f) {
  +        field = f;
  +    }
   
  -  String start = DateField.MIN_DATE_STRING();
  -  String end = DateField.MAX_DATE_STRING();
  +    /**
  +     * Constructs a filter for field <code>f</code> matching dates
  +     * between <code>from</code> and <code>to</code> inclusively.
  +     */
  +    public DateFilter(String f, Date from, Date to) {
  +        field = f;
  +        start = DateField.dateToString(from);
  +        end = DateField.dateToString(to);
  +    }
   
  -  private DateFilter(String f) {
  -    field = f;
  -  }
  -
  -  /** Constructs a filter for field <code>f</code> matching dates between
  -    <code>from</code> and <code>to</code>. */
  -  public DateFilter(String f, Date from, Date to) {
  -    field = f;
  -    start = DateField.dateToString(from);
  -    end = DateField.dateToString(to);
  -  }
  -  /** Constructs a filter for field <code>f</code> matching times between
  -    <code>from</code> and <code>to</code>. */
  -  public DateFilter(String f, long from, long to) {
  -    field = f;
  -    start = DateField.timeToString(from);
  -    end = DateField.timeToString(to);
  -  }
  -
  -  /** Constructs a filter for field <code>f</code> matching dates before
  -    <code>date</code>. */
  -  public static DateFilter Before(String field, Date date) {
  -    DateFilter result = new DateFilter(field);
  -    result.end = DateField.dateToString(date);
  -    return result;
  -  }
  -  /** Constructs a filter for field <code>f</code> matching times before
  -    <code>time</code>. */
  -  public static DateFilter Before(String field, long time) {
  -    DateFilter result = new DateFilter(field);
  -    result.end = DateField.timeToString(time);
  -    return result;
  -  }
  -
  -  /** Constructs a filter for field <code>f</code> matching dates after
  -    <code>date</code>. */
  -  public static DateFilter After(String field, Date date) {
  -    DateFilter result = new DateFilter(field);
  -    result.start = DateField.dateToString(date);
  -    return result;
  -  }
  -  /** Constructs a filter for field <code>f</code> matching times after
  -    <code>time</code>. */
  -  public static DateFilter After(String field, long time) {
  -    DateFilter result = new DateFilter(field);
  -    result.start = DateField.timeToString(time);
  -    return result;
  -  }
  -
  -  /** Returns a BitSet with true for documents which should be permitted in
  -    search results, and false for those that should not. */
  -  public BitSet bits(IndexReader reader) throws IOException {
  -    BitSet bits = new BitSet(reader.maxDoc());
  -    TermEnum enumerator = reader.terms(new Term(field, start));
  -    TermDocs termDocs = reader.termDocs();
  -    if (enumerator.term() == null)
  -	return bits;
  -
  -    try {
  -      Term stop = new Term(field, end);
  -      while (enumerator.term().compareTo(stop) <= 0) {
  -	termDocs.seek(enumerator.term());
  -	try {
  -	  while (termDocs.next())
  -	    bits.set(termDocs.doc());
  -	} finally {
  -	  termDocs.close();
  -	}
  -	if (!enumerator.next()) {
  -	  break;
  -	}
  -      }
  -    } finally {
  -      enumerator.close();
  -    }
  -    return bits;
  -  }
  -
  -  public String toString() {
  -    StringBuffer buffer = new StringBuffer();
  -    buffer.append(field);
  -    buffer.append(":");
  -    buffer.append(DateField.stringToDate(start).toString());
  -    buffer.append("-");
  -    buffer.append(DateField.stringToDate(end).toString());
  -    return buffer.toString();
  -  }
  +    /**
  +     * Constructs a filter for field <code>f</code> matching times
  +     * between <code>from</code> and <code>to</code> inclusively.
  +     */
  +    public DateFilter(String f, long from, long to) {
  +        field = f;
  +        start = DateField.timeToString(from);
  +        end = DateField.timeToString(to);
  +    }
  +
  +    /**
  +     * Constructs a filter for field <code>f</code> matching
  +     * dates on or before before <code>date</code>.
  +     */
  +    public static DateFilter Before(String field, Date date) {
  +        DateFilter result = new DateFilter(field);
  +        result.end = DateField.dateToString(date);
  +        return result;
  +    }
  +
  +    /**
  +     * Constructs a filter for field <code>f</code> matching times
  +     * on or before <code>time</code>.
  +     */
  +    public static DateFilter Before(String field, long time) {
  +        DateFilter result = new DateFilter(field);
  +        result.end = DateField.timeToString(time);
  +        return result;
  +    }
  +
  +    /**
  +     * Constructs a filter for field <code>f</code> matching
  +     * dates on or after <code>date</code>.
  +     */
  +    public static DateFilter After(String field, Date date) {
  +        DateFilter result = new DateFilter(field);
  +        result.start = DateField.dateToString(date);
  +        return result;
  +    }
  +
  +    /**
  +     * Constructs a filter for field <code>f</code> matching
  +     * times on or after <code>time</code>.
  +     */
  +    public static DateFilter After(String field, long time) {
  +        DateFilter result = new DateFilter(field);
  +        result.start = DateField.timeToString(time);
  +        return result;
  +    }
  +
  +    /**
  +     * Returns a BitSet with true for documents which should be
  +     * permitted in search results, and false for those that should
  +     * not.
  +     */
  +    public BitSet bits(IndexReader reader) throws IOException {
  +        BitSet bits = new BitSet(reader.maxDoc());
  +        TermEnum enumerator = reader.terms(new Term(field, start));
  +        TermDocs termDocs = reader.termDocs();
  +        if (enumerator.term() == null) {
  +            return bits;
  +        }
  +
  +        try {
  +            Term stop = new Term(field, end);
  +            while (enumerator.term().compareTo(stop) <= 0) {
  +                termDocs.seek(enumerator.term());
  +                try {
  +                    while (termDocs.next()) {
  +                        bits.set(termDocs.doc());
  +                    }
  +                } finally {
  +                    termDocs.close();
  +                }
  +                if (!enumerator.next()) {
  +                    break;
  +                }
  +            }
  +        } finally {
  +            enumerator.close();
  +        }
  +        return bits;
  +    }
  +
  +    public String toString() {
  +        StringBuffer buffer = new StringBuffer();
  +        buffer.append(field);
  +        buffer.append(":");
  +        buffer.append(DateField.stringToDate(start).toString());
  +        buffer.append("-");
  +        buffer.append(DateField.stringToDate(end).toString());
  +        return buffer.toString();
  +    }
   }
  
  
  

Mime
View raw message