rnewson / couchdb-lucene

Enables full-text searching of CouchDB documents using Lucene
Apache License 2.0
769 stars 145 forks source link

Problems searching index using dates #220

Closed elwin1234 closed 9 years ago

elwin1234 commented 9 years ago

Hi,

According to the documentation the following formats are valid for date search:

field<date>:[from TO to] where from and to match any of these patterns: "yyyy-MM-dd'T'HH:mm:ssZ", yyyy-MM-dd'T'HH:mm:ss, "yyyy-MM-ddZ", "yyyy-MM-dd", "yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS". So, in order to search for articles published in July, you would issue a following query: published_at<date>:["2010-07-01T00:00:00"+TO+"2010-07-31T23:59:59"]

I created the following index

..
document.add(
  new Date(), {
    "field":"indexDate",
    "store":"yes",
    "type":"date"
  }
);
..

Querying ?q=indexDate:["2015-05-21T13:00:30"+TO+"2015-05-21T15:00:30"] works, where ?q=indexDate:["2015-05-21T13:00:30Z"+TO+"2015-05-21T15:00:30Z"] gives me the following error:

Bad query syntax: Cannot parse 'indexDate:[\"2015-05-21T13:00:30Z\" TO \"2015-05-21T15:00:30Z\"]': Unable to parse the date: 2015-05-21T13:00:30Z

Furthermore I expect that the times you provide in search are in UTC format, but they seem to use local times.

Can I add a timezone offset to my search query?

rnewson commented 9 years ago

Ah, 'Z' here stands for timezone, not a literal Z. See https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html for details but you want to say 2015-05-21T13:00:30-0500 or similar.

elwin1234 commented 9 years ago

Ah, thanks! Great!