Open line-o opened 2 years ago
I just tried to add a field that stores the timezone information
<field name="time-tz"
expression="fn:timezone-from-time(xs:time(@time))"
type="xs:dayTimeDuration" />
And the test below passes showing that
xs:dayTimeDuration
Additional findings
declare
%test:assertEquals("-PT2H", "PT0S", "PT2H")
function lfttt:timezone-values() {
collection("/db/" || $lfttt:collection)
//item[
ft:query(., "time-tz:*", map{
"leading-wildcard": "yes",
"fields": "time-tz"
})]
! ft:field(., "time-tz")
=> sort()
};
declare
%test:assertTrue
function lfttt:timezones-values-can-be-cast-to-dayTimeDuration() {
collection("/db/" || $lfttt:collection)
//item[
ft:query(., "time-tz:*", map{
"leading-wildcard": "yes",
"fields": "time-tz"
})]
! ft:field(., "time-tz")
=> fold-left(true(), function ($result, $next) {
$result and $next castable as xs:dayTimeDuration
})
};
Describe the bug
When one configures a Lucene Field index to be of type
xs:dateTime
orxs:time
the timezone is normalised to UTC before the value is added to the index. Two entries that mark the same moment in time but in different timezones have a frequency of two in the index. I believe this is not a bug, but more a design decision that needs to be documented. But since it is undocumented developers might expect a different behaviour.My tests whether sorting of xs:time takes the timezone into account were inconclusive. It appears that only the (normalised) time portion is used. That would mean that the sorting of field values is comparable and not affected by the current implementation.
Since the timezone information is gone upon retrieval it it is impossible to search for, filter or group by timezones with only the values stored in the index.
NOTE: The original information can still be retrieved from the hit itself.
Expected behavior
The fact that values typed as
xs:time
orxs:dateTime
are normalised to UTC needs to be documented. It could be worth to add an example how to store timezone information in a separate field or facet to enable search, filtering and grouping.Alternatively, a way to efficiently store and retrieve the timezone should be investigated.
To Reproduce
Tested on:
Additional context
conf.xml
? none