FileDocCategorySizeDatePackage
DateFilter.javaAPI DocApache Lucene 1.94319Mon Feb 20 09:20:04 GMT 2006org.apache.lucene.search

DateFilter

public class DateFilter extends Filter
A Filter that restricts search results to a range of time.

For this to work, documents must have been indexed with a {@link DateField}.

deprecated
Instead, use {@link RangeFilter} combined with {@link org.apache.lucene.document.DateTools}.

Fields Summary
String
field
String
start
String
end
Constructors Summary
private DateFilter(String f)


     
    field = f;
  
public DateFilter(String f, Date from, Date to)
Constructs a filter for field f matching dates between from and to inclusively.

    field = f;
    start = DateField.dateToString(from);
    end = DateField.dateToString(to);
  
public DateFilter(String f, long from, long to)
Constructs a filter for field f matching times between from and to inclusively.

    field = f;
    start = DateField.timeToString(from);
    end = DateField.timeToString(to);
  
Methods Summary
public static org.apache.lucene.search.DateFilterAfter(java.lang.String field, java.util.Date date)
Constructs a filter for field f matching dates on or after date.

    DateFilter result = new DateFilter(field);
    result.start = DateField.dateToString(date);
    return result;
  
public static org.apache.lucene.search.DateFilterAfter(java.lang.String field, long time)
Constructs a filter for field f matching times on or after time.

    DateFilter result = new DateFilter(field);
    result.start = DateField.timeToString(time);
    return result;
  
public static org.apache.lucene.search.DateFilterBefore(java.lang.String field, java.util.Date date)
Constructs a filter for field f matching dates on or before before date.

    DateFilter result = new DateFilter(field);
    result.end = DateField.dateToString(date);
    return result;
  
public static org.apache.lucene.search.DateFilterBefore(java.lang.String field, long time)
Constructs a filter for field f matching times on or before time.

    DateFilter result = new DateFilter(field);
    result.end = DateField.timeToString(time);
    return result;
  
public java.util.BitSetbits(org.apache.lucene.index.IndexReader reader)
Returns a BitSet with true for documents which should be permitted in search results, and false for those that should not.

    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());
        while (termDocs.next()) {
          bits.set(termDocs.doc());
        }
        if (!enumerator.next()) {
          break;
        }
      }
    } finally {
      enumerator.close();
      termDocs.close();
    }
    return bits;
  
public java.lang.StringtoString()

    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();