lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Hostetter <hossman_luc...@fucit.org>
Subject RE: Date Range Search throws IndexAccessException
Date Fri, 03 Dec 2004 19:31:20 GMT

: The problem with using a Filter is that I want to be able to merely generate
: a text query based on the range information instead of having to modify the
: core search module which basically receives text queries. If I understand
: correctly, the Filter would actually have to be created and passed into the
: search method.

I haven't acctually done this myself, but when I asked about RangeQuery vs
RangeFilter before, Erik pointed out that you can wrap a RangeFilter in
"FilteredQuery" so that you can still use the simpler search API (without
explicitly passing the filter).

If you're using the QueryParser that comes with Lucene, you can probably
subclass it and write you're own "getRangeQuery" to look like the code
below. (like i said, i haven't acctually tried this yet)

Truthfully, i wonder if it might not be a good idea to change the default
implimentation of getRangeQuery to be something like this?




  protected Query getRangeQuery(String field,
                                String part1,
                                String part2,
                                boolean inclusive) throws ParseException
  {
    try {
      DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
      df.setLenient(true);
      Date d1 = df.parse(part1);
      Date d2 = df.parse(part2);
      part1 = DateField.dateToString(d1);
      part2 = DateField.dateToString(d2);
    }
    catch (Exception e) { }

    return new FilteredQuery(
                          new TermQuery(new Term(field,"")), // match all docs
                          new RangeFilter(
                               new Term(field, part1),
                               new Term(field, part2),
                               inclusive,inclusive));
  }

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Mime
View raw message