2 Commits

Author SHA1 Message Date
532d1560a3 Merge pull request 'Fix project-aware thought text search for issue #30' (#31) from fix/issue-30-project-aware-search into main
Some checks failed
CI / build-and-test (push) Failing after -32m48s
Reviewed-on: #31
2026-04-21 06:36:04 +00:00
894fa3fc1d fix: include project names in thought text search
Some checks failed
CI / build-and-test (push) Failing after -31m57s
CI / build-and-test (pull_request) Failing after -32m8s
2026-04-21 08:31:42 +02:00

View File

@@ -582,7 +582,7 @@ func (db *DB) SearchThoughtsText(ctx context.Context, query string, limit int, p
args := []any{query} args := []any{query}
conditions := []string{ conditions := []string{
"t.archived_at is null", "t.archived_at is null",
"to_tsvector('simple', t.content) @@ websearch_to_tsquery('simple', $1)", "(to_tsvector('simple', t.content) || to_tsvector('simple', coalesce(p.name, ''))) @@ websearch_to_tsquery('simple', $1)",
} }
if projectID != nil { if projectID != nil {
args = append(args, *projectID) args = append(args, *projectID)
@@ -596,9 +596,10 @@ func (db *DB) SearchThoughtsText(ctx context.Context, query string, limit int, p
q := ` q := `
select t.guid, t.content, t.metadata, select t.guid, t.content, t.metadata,
ts_rank_cd(to_tsvector('simple', t.content), websearch_to_tsquery('simple', $1)) as similarity, ts_rank_cd(to_tsvector('simple', t.content) || to_tsvector('simple', coalesce(p.name, '')), websearch_to_tsquery('simple', $1)) as similarity,
t.created_at t.created_at
from thoughts t from thoughts t
left join projects p on t.project_id = p.guid
where ` + strings.Join(conditions, " and ") + ` where ` + strings.Join(conditions, " and ") + `
order by similarity desc order by similarity desc
limit $` + fmt.Sprintf("%d", len(args)) limit $` + fmt.Sprintf("%d", len(args))