Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO-4804 fulltext: index snippet for notes #1992

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions core/indexer/fulltext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/lib/localstore/ftsearch/ftsearchtantivy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Loading