diff --git a/query/filter/filter.go b/query/filter/filter.go index a0050828..58e8a521 100644 --- a/query/filter/filter.go +++ b/query/filter/filter.go @@ -54,7 +54,8 @@ var ( type Filter interface { // Matches returns true if the input doc passes the filter, otherwise false Matches(doc []byte, metadata []byte) bool - // MatchesDoc similar to Matches but used when document is already parsed + // MatchesDoc similar to Matches but used when document is already parsed. This is mainly used by + // standalone search index. MatchesDoc(doc map[string]any) bool ToSearchFilter() string // IsSearchIndexed to let caller knows if there is any fields in the query not indexed in search. This diff --git a/query/filter/selector.go b/query/filter/selector.go index 0118566d..9cf08db3 100644 --- a/query/filter/selector.go +++ b/query/filter/selector.go @@ -175,6 +175,10 @@ func (s *Selector) ToSearchFilter() string { } func (s *Selector) IsSearchIndexed() bool { + if !s.Field.SearchIndexed { + return false + } + switch { case s.Field.DataType == schema.DoubleType: v, ok := s.Matcher.GetValue().(*value.DoubleValue) diff --git a/schema/search.go b/schema/search.go index 848541db..d5a7e8b5 100644 --- a/schema/search.go +++ b/schema/search.go @@ -458,25 +458,12 @@ func (s *ImplicitSearchIndex) buildSearchSchema(searchStoreName string) { tsFields := make([]tsApi.Field, 0, len(s.QueryableFields)) for _, f := range s.QueryableFields { - // the implicit search index by default index all the fields that are indexable and same applies to facet/sort. - shouldIndex := SupportedSearchIndexableType(f.DataType, f.SubType) - shouldFacet := DefaultFacetableType(f.DataType) - shouldSort := DefaultSortableType(f.DataType) - - if !shouldSort && f.Sortable { - // honor schema i.e. in case of strings user can explicitly enable sorting. - shouldSort = true - } - if !shouldFacet && f.Faceted { - shouldFacet = true - } - tsFields = append(tsFields, tsApi.Field{ Name: f.Name(), Type: f.SearchType, - Facet: &shouldFacet, - Index: &shouldIndex, - Sort: &shouldSort, + Facet: &f.Faceted, + Index: &f.SearchIndexed, + Sort: &f.Sortable, Optional: &ptrTrue, NumDim: f.Dimensions, }) @@ -486,9 +473,9 @@ func (s *ImplicitSearchIndex) buildSearchSchema(searchStoreName string) { tsFields = append(tsFields, tsApi.Field{ Name: f.InMemoryName(), Type: f.SearchType, - Facet: &shouldFacet, - Index: &shouldIndex, - Sort: &shouldSort, + Facet: &f.Faceted, + Index: &f.SearchIndexed, + Sort: &f.Sortable, Optional: &ptrTrue, }) } @@ -531,26 +518,16 @@ func (s *ImplicitSearchIndex) GetSearchDeltaFields(existingFields []*QueryableFi e := existingFieldMap[f.FieldName] delete(existingFieldMap, f.FieldName) - shouldIndex := SupportedSearchIndexableType(f.DataType, f.SubType) - shouldFacet := DefaultFacetableType(f.DataType) - shouldSort := DefaultSortableType(f.DataType) - if !shouldSort && f.Sortable { - shouldSort = true - } - if !shouldFacet && f.Faceted { - shouldFacet = true - } - stateChanged := false if e != nil { inSearchState, found := fieldsInSearchMap[f.FieldName] - if found && inSearchState.Index != nil && *inSearchState.Index != shouldIndex { + if found && inSearchState.Index != nil && *inSearchState.Index != f.SearchIndexed { stateChanged = true } - if found && inSearchState.Facet != nil && *inSearchState.Facet != shouldFacet { + if found && inSearchState.Facet != nil && *inSearchState.Facet != f.Faceted { stateChanged = true } - if found && inSearchState.Sort != nil && *inSearchState.Sort != shouldSort { + if found && inSearchState.Sort != nil && *inSearchState.Sort != f.Sortable { stateChanged = true } @@ -579,9 +556,9 @@ func (s *ImplicitSearchIndex) GetSearchDeltaFields(existingFields []*QueryableFi tsFields = append(tsFields, tsApi.Field{ Name: f.FieldName, Type: f.SearchType, - Facet: &shouldFacet, - Index: &shouldIndex, - Sort: &shouldSort, + Facet: &f.Faceted, + Index: &f.SearchIndexed, + Sort: &f.Sortable, Optional: &ptrTrue, NumDim: f.Dimensions, })