mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-09-13 06:09:21 -04:00
Keyword and path fields always index their case-preserved base and, when CaseInsensitive is set, an additional <field>_lowercase sibling used only for matching. The KQL lowering marks a restriction case-insensitive; each backend searches the sibling and lowercases the query value the same way the sibling is precomputed at index time (Go strings.ToLower on both sides, so non-ASCII stays consistent). Search always returns the case-preserved base, so the sibling never has to be read back. In bleve it is indexed but not stored, kept out of _all, and without doc values. In OpenSearch it deliberately stays in _source: excluding it would make every update-by-query script rebuild all siblings from the document via painless toLowerCase, which lowercases differently than Go and would drift from the query side. Keeping it in _source avoids that, and a lowercased copy of a name or path is negligible disk in a cluster. The OpenSearch move script keeps the base and its sibling in sync by swapping the moved prefix in Path_lowercase and setting Name_lowercase from Go-lowercased params, so case-insensitive search still finds a file after it moves (previously the sibling went stale). bleve re-indexes the whole document on move/delete/restore, so its siblings stay fresh for free. This also repairs OpenSearch path search (the query value was no longer folded to lowercase, so path:<Foo> returned nothing) and makes bleve path queries match a folder and its descendants like OpenSearch's path_hierarchy. The Path base stays case-preserved so the move/delete descendant update (an exact TermQuery on Path) matches mixed-case folders.
25 lines
729 B
Go
25 lines
729 B
Go
package mapping
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/opencloud-eu/opencloud/pkg/conversions"
|
|
)
|
|
|
|
// PrepareForIndex converts v to the flat map[string]any the backend index
|
|
// clients expect: a json round-trip (conversions.To) plus type-specific
|
|
// adaptations (currently geopoint siblings). Pass the same overrides as the
|
|
// *BuildMapping calls so the document and the mapping stay in sync.
|
|
func PrepareForIndex(v any, overrides map[string]FieldOpts) (map[string]any, error) {
|
|
out, err := conversions.To[map[string]any](v)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("mapping: prepare %T: %w", v, err)
|
|
}
|
|
if out == nil {
|
|
return out, nil
|
|
}
|
|
addGeopointSiblings(out, overrides)
|
|
addLowercaseSiblings(out, overrides)
|
|
return out, nil
|
|
}
|