Files
opencloud/services/search/pkg/parity/query_range_test.go
T
Dominik Schmidt c3a08d88da fix(search): answer text on numeric and date fields the same on both engines
A text restriction on a numeric field reached the engines as is. bleve found nothing for size:>100 or size:50..500, OpenSearch failed the search with a number format exception. size=50 only matched on OpenSearch.

Both engines now read the value of such a restriction as a number and match it as a whole, with : and with =. Anything that is no number matches nothing, and so does text on a date field. size:>100 is not KQL, the range form is size>100; old iOS clients still send the colon form.

The field type comes from one table of all fields, built from the walk the mapping validation uses. It replaces the separate walk for numeric fields, which left out the parts of a location: location.altitude>1000 now matches, the parts are indexed as numbers next to the geopoint.

The parity suite covers >=, <=, combined ranges, number equality, the colon forms and the location parts.
2026-11-25 10:58:30 +01:00

46 lines
1.8 KiB
Go

package parity
import (
"github.com/opencloud-eu/opencloud/services/search/pkg/search"
)
func rangeGroup() queryGroup {
return queryGroup{
name: "range",
fixtures: []search.Resource{
fixtureDoc("small.txt", withSize(50)),
fixtureDoc("big.txt", withSize(500)),
fixtureDoc("ancient.txt", withSize(10), withMtime("2020-01-01T00:00:00Z")),
},
cases: []queryCase{
{id: 1, query: `size>100`, want: []string{"big.txt"}},
{id: 2, query: `size<100`, want: []string{"small.txt", "ancient.txt"}},
{id: 3, query: `mtime>"2021-01-01T00:00:00Z"`, want: []string{"small.txt", "big.txt"}},
{id: 4, query: `mtime<"2021-01-01T00:00:00Z"`, want: []string{"ancient.txt"}},
{id: 5, query: `Mtime:"today"`, want: []string{"small.txt", "big.txt"}},
{id: 6, query: `Mtime:"yesterday"`},
{id: 7, query: `mtime>2021`},
{id: 8, query: `name>100`},
{id: 9, query: `size>=50`, want: []string{"small.txt", "big.txt"}},
{id: 10, query: `size<=50`, want: []string{"small.txt", "ancient.txt"}},
{id: 11, query: `size>100 AND size<1000`, want: []string{"big.txt"}},
{id: 12, query: `mtime>=2021-01-01`, want: []string{"small.txt", "big.txt"}},
// a number on a numeric field matches as a whole, with : and with =
{id: 13, query: `size:50`, want: []string{"small.txt"}},
{id: 14, query: `size=50`, want: []string{"small.txt"}},
{id: 15, query: `size:1.5`},
{id: 16, query: `size:5*`},
// not KQL: a colon before the comparison makes it the text ">100",
// which no number is. Old iOS clients send this form.
{id: 17, query: `size:>100`},
{id: 18, query: `size:<100`},
{id: 19, query: `size:>=100`},
{id: 20, query: `mtime:>"2021-01-01T00:00:00Z"`},
{id: 21, query: `mtime:>2021-01-01`},
// the KQL range operator .. is not supported
{id: 22, query: `size:50..500`},
{id: 23, query: `mtime:2019-01-01..2020-12-31`},
},
}
}