diff --git a/core/indexer/fulltext.go b/core/indexer/fulltext.go index 8a2737bbd..5eb67227e 100644 --- a/core/indexer/fulltext.go +++ b/core/indexer/fulltext.go @@ -161,13 +161,23 @@ func (i *indexer) prepareSearchDocument(ctx context.Context, id string) (docs [] if rel.Format != model.RelationFormat_shorttext && rel.Format != model.RelationFormat_longtext { continue } - val := sb.Details().GetString(domain.RelationKey(rel.Key)) + val := sb.CombinedDetails().GetString(domain.RelationKey(rel.Key)) if val == "" { continue } // skip readonly and hidden system relations if bundledRel, err := bundle.PickRelation(domain.RelationKey(rel.Key)); err == nil { - if bundledRel.ReadOnly || bundledRel.Hidden && rel.Key != bundle.RelationKeyName.String() { + layout, _ := sb.Layout() + skip := bundledRel.ReadOnly || bundledRel.Hidden + if rel.Key == bundle.RelationKeyName.String() { + skip = false + } + if layout == model.ObjectType_note && rel.Key == bundle.RelationKeySnippet.String() { + // index snippet only for notes, so we will be able to do fast prefix queries + skip = false + } + + if skip { continue } } diff --git a/pkg/lib/localstore/ftsearch/ftsearchtantivy.go b/pkg/lib/localstore/ftsearch/ftsearchtantivy.go index 6b6fe27ce..9b3804f88 100644 --- a/pkg/lib/localstore/ftsearch/ftsearchtantivy.go +++ b/pkg/lib/localstore/ftsearch/ftsearchtantivy.go @@ -419,7 +419,13 @@ func (f *ftSearchTantivy) performSearch(spaceId, query string, buildQueryFunc fu } func (f *ftSearchTantivy) buildObjectQuery(qb *tantivy.QueryBuilder, query string) { - qb.Query(tantivy.Must, fieldId, bundle.RelationKeyName.String(), tantivy.TermQuery, 1.0) + qb.BooleanQuery(tantivy.Must, qb.NestedBuilder(). + Query(tantivy.Should, fieldId, bundle.RelationKeyName.String(), tantivy.TermQuery, 1.0). + // snippets are indexed only for notes which don't have a name, we should do a prefix search there as well + Query(tantivy.Should, fieldId, bundle.RelationKeySnippet.String(), tantivy.TermQuery, 1.0), + 1.0, + ) + if containsChineseCharacters(query) { qb.BooleanQuery(tantivy.Must, qb.NestedBuilder(). Query(tantivy.Should, fieldTitleZh, query, tantivy.PhrasePrefixQuery, 1.0).