Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-57972

FTS dateTimeOptional does not work with default samples

    XMLWordPrintable

Details

    Description

       

      Creating a default mapping on travel-sample._default._default then running the query below

      {"explain": true,"fields": ["*"],"highlight": {},"query": {"inclusive_start": false, "field": "reviews.date", "start": "1969-12-31T23:59:59","end": "2024-03-31T01:33:51"}}

      nothing is returned.  If I modify KEY hotel_10025 the first item to one of the following

      • "date": "2000-03-31T01:33:51Z"     this is time.RFC3339
      • "date": "2000-03-31T01:33:51.00000001Z   this is time.RFC3339Nano
      • "date": "2000-03-31T01:33:51"     this is rfc3339NoTimezone
      • "date": "2000-03-31 01:33:51"     this is rfc3339NoTimezoneNoT
      • "date": "2000-03-31"     this is rfc3339NoTime{}

      In each case above I will get a single hit the modified key hotel_10025

      Unfortunately the following does not work which is the format of reviews.data in travel-sample._default._default

      • "date": "2013-06-22 18:33:50 +0300"

      Also items like the following date formats also do not work out of the box

      • "date": "2013-06-22 18:33"
      • "date": "2013-06-22 18"
      • "date": "2013-06-22 18:33 +0300"
      • date": "2013-06-22 18 +0300"
      • date": "2013-06-22 +0300"

      This make a poor initial developer experience as our sample sets should work out of the box easily without making a custom Date/Time Parsers and assigning it to the field.

      It seems that dateTimeOptional from the bleve source master/analysis/datetime/optional/optional.go (the default in Couchbase FTS indexing) only parses these formats but I expect from the source that it would parse five (5) formats

       

      In fact from the bleve source master/analysis/datetime/optional/optional.go we see
      const rfc3339NoTimezone = "2006-01-02T15:04:05"
      const rfc3339NoTimezoneNoT = "2006-01-02 15:04:05"
      const rfc3339NoTime = "2006-01-02"
       
      var layouts = []string{
      	time.RFC3339Nano,
      	time.RFC3339,
      	rfc3339NoTimezone,
      	rfc3339NoTimezoneNoT,
      	rfc3339NoTime,
      }

       

      It seems we could update the dates in travel-sample._default._default but this could break many legacy examples or we could add one more constant rfc3339NoTimezoneNoTHHMMOffest and put them it the layouts (above) in the bleve source optional.go.

      UPDATE:  A new constant must use magic number components as per https://pkg.go.dev/time search for example "2013-06-22 18:33 +0300" is illegal.

      const rfc3339NoTimezoneNoTHHMMOffest = "2006-01-02 15:04:05 -0700"
       
      var layouts = []string{
      	time.RFC3339Nano,
      	time.RFC3339,
      	rfc3339NoTimezone,
      	rfc3339NoTimezoneNoT,
      	rfc3339NoTime,
              rfc3339NoTimezoneNoTHHMMOffest
      }

      unfortunately the test runner that I found in bleve source flexible_test.go doesn't seem to like the above if I add the test

                     {
                              input:         "2000-03-31 01:33:51 +0300",
                              expectedTime:  time.Date(2000, 3, 30, 22, 33, 51, 0, time.UTC),
                              expectedError: nil,
                      },

      I get an odd failure

      linuxbrew@couch01:~/go/src/bleve01/analysis/datetime/flexible$ go test
      --- FAIL: TestFlexibleDateTimeParser (0.00s)
          --- FAIL: TestFlexibleDateTimeParser/2000-03-31_01:33:51_+0300 (0.00s)
              flexible_test.go:138: expected time 2000-03-30 22:33:51 +0000 UTC, got 2000-03-31 01:33:51 +0300 +0300
      FAIL
      exit status 1
      FAIL    github.com/blevesearch/bleve/v2/analysis/datetime/flexible      0.006s

      But I know Golang works for the travel-sample syntax as per

       

      package main
      import (
          "fmt"
          "time"
      )
      func main() {
          // Parse the date string
          layout := "2006-01-02 15:04:05 -0700" // Format of the input date string
          dateStr := "2000-03-31 23:33:51 -0300"
          date, err := time.Parse(layout, dateStr)
          if err != nil {
              fmt.Println("Error parsing date:", err)
              return
          }
          // Convert to ISO 8601 formatted string
          isoString := date.UTC().Format(time.RFC3339) // Using UTC() to convert to UTC time zone
          fmt.Println(dateStr + " (layout: " + layout + ") => " + isoString)
          // Output: 2000-03-31 23:33:51 -0300 (layout: 2006-01-02 15:04:05 -0700) => 2000-04-01T02:33:51Z
          dateStr = "2000-03-31 01:33:51 +0300"
          date, err = time.Parse(layout, dateStr)
          if err != nil {
              fmt.Println("Error parsing date:", err)
              return
          }
          // Convert to ISO 8601 formatted string
          isoString = date.UTC().Format(time.RFC3339) // Using UTC() to convert to UTC time zone
          fmt.Println(dateStr + " (layout: " + layout + ") => " + isoString)
          // Output: 2000-03-31 01:33:51 +0300 (layout: 2006-01-02 15:04:05 -0700) => 2000-03-30T22:33:51Z
      }
       
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sarthak.dua Sarthak Dua
            jon.strabala Jon Strabala
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty