Fix project-aware thought text search for issue #30 #31
@@ -582,7 +582,7 @@ func (db *DB) SearchThoughtsText(ctx context.Context, query string, limit int, p
|
||||
args := []any{query}
|
||||
conditions := []string{
|
||||
"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 {
|
||||
args = append(args, *projectID)
|
||||
@@ -596,9 +596,10 @@ func (db *DB) SearchThoughtsText(ctx context.Context, query string, limit int, p
|
||||
|
||||
q := `
|
||||
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
|
||||
from thoughts t
|
||||
left join projects p on t.project_id = p.guid
|
||||
where ` + strings.Join(conditions, " and ") + `
|
||||
order by similarity desc
|
||||
limit $` + fmt.Sprintf("%d", len(args))
|
||||
|
||||
Reference in New Issue
Block a user