Solr
  1. Solr
  2. SOLR-71

New support for "Date Math" when adding/quering date fields

    Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.0
    • Component/s: search, update
    • Labels:
      None

      Description

      New utility class and changes to DateField to support syntax like the following...

      startDate:[* TO NOW]
      startDate:[* TO NOW/DAY+1DAY]
      expirationDate:[NOW/DAY TO *]
      reviewDate:[NOW/DAY-1YEAR TO NOW/DAY]
      validDate:[NOW/MONTH TO NOW/MONTH+1MONTH-1MILLISECOND]

      ...where + and - mean what you think, and "/UNIT" rounds down to the nearest UNIT. The motivation for this being that date range queries like these are usefull for filters, but being date sensitve can't currently be "baked in" to a config as default params.

      a nice side effect of the implimentation, is that "timestamp" fields can be done with a document is added by using...

      <field name="myTimestampField">NOW</field>

      ...and Solr will compute the value when adding the document ... if we add default values to the schema.xml even that won't be neccessary.

      Comments?

      (I'd be particularly gratefull if smarter people then I would sanity check my use of ThreadLocal for managing the DateFormat in DateField ... i've never used ThreadLocal before. Any general comments on the syntax would also be appreciated: This left-to-right syntax seemed more intuative to write (and easier to parse) then some of the other syntaxes I'd considered)

        Activity

        Hide
        Hoss Man added a comment -

        Code, and tests ... if you readd the exampledocs the "incubationdate_dt" field is populated for the Solr product so you can play with it...

        incubationdate_dt:[* TO NOW-1DAY+3HOURS/MINUTE] ... matches.
        incubationdate_dt:[* TO NOW-2YEARS] ... does not match.

        Show
        Hoss Man added a comment - Code, and tests ... if you readd the exampledocs the "incubationdate_dt" field is populated for the Solr product so you can play with it... incubationdate_dt: [* TO NOW-1DAY+3HOURS/MINUTE] ... matches. incubationdate_dt: [* TO NOW-2YEARS] ... does not match.
        Hide
        Yonik Seeley added a comment -

        Sweet!

        A couple of very minor notes regarding ThreadLocal:

        • initialValue doesn't need to be synchronized... it's just that way in the javadoc example because they were incrementing a global counter
        • the trick you are trying in the ThreadLocalDateFormat aren't necessary. no method will be called until the constructor has completed. the java memory model also ensures that you see a completely constructed object from another thread, even if you haven't synchronized. The extra variable won't hurt either... the JVM will completely optimize it away (so this is just an FYI).
        Show
        Yonik Seeley added a comment - Sweet! A couple of very minor notes regarding ThreadLocal: initialValue doesn't need to be synchronized... it's just that way in the javadoc example because they were incrementing a global counter the trick you are trying in the ThreadLocalDateFormat aren't necessary. no method will be called until the constructor has completed. the java memory model also ensures that you see a completely constructed object from another thread, even if you haven't synchronized. The extra variable won't hurt either... the JVM will completely optimize it away (so this is just an FYI).
        Hide
        Bertrand Delacretaz added a comment -

        This looks like a very useful feature!

        Show
        Bertrand Delacretaz added a comment - This looks like a very useful feature!
        Hide
        Hoss Man added a comment -

        commited with some small modifications:

        1) got rid of the unneeded synchronized Yonik pointed out
        2) improved the javadocs a bit
        3) added mention of DateMath in example schema.xml
        4) added an example of a "baked in" Date Math query to the example solrconfig.xml

        Show
        Hoss Man added a comment - commited with some small modifications: 1) got rid of the unneeded synchronized Yonik pointed out 2) improved the javadocs a bit 3) added mention of DateMath in example schema.xml 4) added an example of a "baked in" Date Math query to the example solrconfig.xml
        Hide
        Hoss Man added a comment -

        This bug was modified as part of a bulk update using the criteria...

        • Marked ("Resolved" or "Closed") and "Fixed"
        • Had no "Fix Version" versions
        • Was listed in the CHANGES.txt for 1.1

        The Fix Version for all 38 issues found was set to 1.1, email notification
        was suppressed to prevent excessive email.

        For a list of all the issues modified, search jira comments for this
        (hopefully) unique string: 20080415hossman3

        Show
        Hoss Man added a comment - This bug was modified as part of a bulk update using the criteria... Marked ("Resolved" or "Closed") and "Fixed" Had no "Fix Version" versions Was listed in the CHANGES.txt for 1.1 The Fix Version for all 38 issues found was set to 1.1, email notification was suppressed to prevent excessive email. For a list of all the issues modified, search jira comments for this (hopefully) unique string: 20080415hossman3

          People

          • Assignee:
            Hoss Man
            Reporter:
            Hoss Man
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development