Thank you for your reply.

So my question is: can I get offset of time if I use NOW/MINUTE and not NOW/DAY 
rounding?

You said  " TZ affects what timezone is used when defining the concept of a 
"day" for 
the purposes of rounding by day. " I understand from this answer that query 
like I mentioned could not be treated as I want: different TZ give me different 
results.

Here you see different time zones but the results is always the same, even 
though it is not accurate to get the same response for last 5 hours in GMT time 
zone and in GMT+07 time zone.
http://localhost:8983/solr/CORE_1/select?q=*:*&fq=realDate:[NOW/MINUTE-5HOURS%20TO%20NOW/MINUTE-1MINUTES]&rows=20&NOW=1433934000000&facet.range=realDate&facet=true&facet.range.start=NOW/MINUTE-5HOURS&facet.range.end=NOW/MINUTE-1MINUTES&facet.range.gap=%2B1HOUR&fl=realDate&fl=f1&TZ=GMT

http://localhost:8983/solr/CORE_1/select?q=*:*&fq=realDate:[NOW/MINUTE-5HOURS%20TO%20NOW/MINUTE-1MINUTES]&rows=20&NOW=1433934000000&facet.range=realDate&facet=true&facet.range.start=NOW/MINUTE-5HOURS&facet.range.end=NOW/MINUTE-1MINUTES&facet.range.gap=%2B1HOUR&fl=realDate&fl=f1&TZ=America/Los_Angeles

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <lst name="responseHeader">
      <int name="status">0</int>
      <int name="QTime">8</int>
      <lst name="params">
         <str name="facet">true</str>
         <arr name="fl">
            <str>realDate</str>
            <str>f1</str>
         </arr>
         <str name="NOW">1433934000000</str>
         <str name="q">*:*</str>
         <str name="facet.range.start">NOW/MINUTE-5HOURS</str>
         <str name="facet.range">realDate</str>
         <str name="TZ">GMT</str>
         <str name="facet.range.gap">+1HOUR</str>
         <str name="facet.range.end">NOW/MINUTE-1MINUTES</str>
         <str name="fq">realDate:[NOW/MINUTE-5HOURS TO 
NOW/MINUTE-1MINUTES]</str>
         <str name="rows">20</str>
      </lst>
   </lst>
   <result name="response" numFound="1" start="0">
      <doc>
         <str name="f1">BOOOOO1</str>
         <date name="realDate">2015-06-10T07:00:00Z</date>
      </doc>
   </result>
   <lst name="facet_counts">
      <lst name="facet_queries" />
      <lst name="facet_fields" />
      <lst name="facet_dates" />
      <lst name="facet_ranges">
         <lst name="realDate">
            <lst name="counts">
               <int name="2015-06-10T06:00:00Z">0</int>
               <int name="2015-06-10T07:00:00Z">1</int>
               <int name="2015-06-10T08:00:00Z">0</int>
               <int name="2015-06-10T09:00:00Z">0</int>
               <int name="2015-06-10T10:00:00Z">0</int>
            </lst>
            <str name="gap">+1HOUR</str>
            <date name="start">2015-06-10T06:00:00Z</date>
            <date name="end">2015-06-10T11:00:00Z</date>
         </lst>
      </lst>
      <lst name="facet_intervals" />
   </lst>
</response>

if I would use the same Query with DAY rounding I'll get different results 
since the TimeZone feature will work: 
http://localhost:8983/solr/CORE_1/select?q=*:*&fq=realDate:[NOW/DAY-5HOURS%20TO%20NOW/DAY-1MINUTES]&rows=20&NOW=1433934000000&facet.range=realDate&facet=true&facet.range.start=NOW/DAY-5HOURS&facet.range.end=NOW/DAY-1MINUTES&facet.range.gap=%2B1HOUR&fl=realDate&fl=f1&TZ=GMT

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <lst name="responseHeader">
      <int name="status">0</int>
      <int name="QTime">7</int>
      <lst name="params">
         <str name="facet">true</str>
         <arr name="fl">
            <str>realDate</str>
            <str>f1</str>
         </arr>
         <str name="NOW">1433934000000</str>
         <str name="q">*:*</str>
         <str name="facet.range.start">NOW/DAY-5HOURS</str>
         <str name="facet.range">realDate</str>
         <str name="TZ">GMT</str>
         <str name="facet.range.gap">+1HOUR</str>
         <str name="facet.range.end">NOW/DAY-1MINUTES</str>
         <str name="fq">realDate:[NOW/DAY-5HOURS TO NOW/DAY-1MINUTES]</str>
         <str name="rows">20</str>
      </lst>
   </lst>
   <result name="response" numFound="0" start="0" />
   <lst name="facet_counts">
      <lst name="facet_queries" />
      <lst name="facet_fields" />
      <lst name="facet_dates" />
      <lst name="facet_ranges">
         <lst name="realDate">
            <lst name="counts">
               <int name="2015-06-09T19:00:00Z">0</int>
               <int name="2015-06-09T20:00:00Z">0</int>
               <int name="2015-06-09T21:00:00Z">0</int>
               <int name="2015-06-09T22:00:00Z">0</int>
               <int name="2015-06-09T23:00:00Z">0</int>
            </lst>
            <str name="gap">+1HOUR</str>
            <date name="start">2015-06-09T19:00:00Z</date>
            <date name="end">2015-06-10T00:00:00Z</date>
         </lst>
      </lst>
      <lst name="facet_intervals" />
   </lst>
</response>

here you can see the offset:

http://localhost:8983/solr/CORE_1/select?q=*:*&fq=realDate:[NOW/DAY-5HOURS%20TO%20NOW/DAY-1MINUTES]&rows=20&NOW=1433934000000&facet.range=realDate&facet=true&facet.range.start=NOW/DAY-5HOURS&facet.range.end=NOW/DAY-1MINUTES&facet.range.gap=%2B1HOUR&fl=realDate&fl=f1&TZ=America/Los_Angeles

<?xml version="1.0" encoding="UTF-8"?>
<response>
   <lst name="responseHeader">
      <int name="status">0</int>
      <int name="QTime">8</int>
      <lst name="params">
         <str name="facet">true</str>
         <arr name="fl">
            <str>realDate</str>
            <str>f1</str>
         </arr>
         <str name="NOW">1433934000000</str>
         <str name="q">*:*</str>
         <str name="facet.range.start">NOW/DAY-5HOURS</str>
         <str name="facet.range">realDate</str>
         <str name="TZ">America/Los_Angeles</str>
         <str name="facet.range.gap">+1HOUR</str>
         <str name="facet.range.end">NOW/DAY-1MINUTES</str>
         <str name="fq">realDate:[NOW/DAY-5HOURS TO NOW/DAY-1MINUTES]</str>
         <str name="rows">20</str>
      </lst>
   </lst>
   <result name="response" numFound="1" start="0">
      <doc>
         <str name="f1">BOOOOO4</str>
         <date name="realDate">2015-06-10T05:00:00Z</date>
      </doc>
   </result>
   <lst name="facet_counts">
      <lst name="facet_queries" />
      <lst name="facet_fields" />
      <lst name="facet_dates" />
      <lst name="facet_ranges">
         <lst name="realDate">
            <lst name="counts">
               <int name="2015-06-10T02:00:00Z">0</int>
               <int name="2015-06-10T03:00:00Z">0</int>
               <int name="2015-06-10T04:00:00Z">0</int>
               <int name="2015-06-10T05:00:00Z">1</int>
               <int name="2015-06-10T06:00:00Z">0</int>
            </lst>
            <str name="gap">+1HOUR</str>
            <date name="start">2015-06-10T02:00:00Z</date>
            <date name="end">2015-06-10T07:00:00Z</date>
         </lst>
      </lst>
      <lst name="facet_intervals" />
   </lst>
</response>


Thank you,
Jon. 



     On Tuesday, June 9, 2015 7:42 PM, Chris Hostetter 
<hossman_luc...@fucit.org> wrote:
   

 
: So, are you saying that you are expected to store UTC dates in your
: index, but if you happen to know that a user is in a different timezone,
: you can round those dates for them according to their timezone instead
: of UTC?
: 
: That's how I'd interpret it, but useful to confirm.

Date formatting and Date Math are two completley different things.

0) All dates, in the index, are stored in UTC.

1) All dates, if expressed as Strings, must be formatted in UTC when 
provided to TrieDateField either to index or for the purposes of query 
parsing.  (if you use SolrJ to send a Date object there is 
no String representation and UTC is irelevant, likewise things like 
ParseDateFieldUpdateProcessorFactory can parse other formats and be 
configured with other timezones)

2) By default, all date math expressions are evaluated relative to the UTC 
TimeZone, but the TZ parameter can be specified to override this 
behaviour, by forcing all date based addition and rounding to be relative 
to the specified time zone.

https://cwiki.apache.org/confluence/display/solr/Working+with+Dates



-Hoss
http://www.lucidworks.com/


  

Reply via email to