search

package
v0.2.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WeightDisplayNameExact = 100
	WeightDisplayNameFuzzy = 50
	WeightNameExact        = 80
	WeightNameFuzzy        = 40
	WeightTitleExact       = 60
	WeightTitleFuzzy       = 30
	WeightParticipantExact = 20
	WeightParticipantFuzzy = 10
)

Field weight constants for relevance scoring. Exact substring matches score higher than fuzzy matches.

Variables

This section is empty.

Functions

func ScoreField

func ScoreField(field, query string, exactWeight, fuzzyWeight int) int

ScoreField scores a single field against the query. Returns exactWeight for substring match, fuzzyWeight for fuzzy-only match, 0 otherwise.

func ScoreThread

func ScoreThread(thread db.Thread, query string, includeSelf bool) int

ScoreThread returns a relevance score for a thread against the query. Returns 0 if the thread does not match. Empty query matches everything with score 1. Multi-term queries use AND logic: all terms must match somewhere. When includeSelf is false, self participants are excluded from matching (contacts mode). When includeSelf is true, all participants are included (chats mode).

func SortByScoreAndActivity

func SortByScoreAndActivity(items []Scored[db.Thread])

SortByScoreAndActivity sorts scored threads by score descending, then by LastActivity descending (most recent first) as a tiebreaker.

func TermMatchesAnyField

func TermMatchesAnyField(fields []string, term string) bool

TermMatchesAnyField checks if a single term matches any of the given fields via case-insensitive substring or fuzzy match.

Types

type Scored

type Scored[T any] struct {
	Item  T
	Score int
}

Scored pairs an item with its relevance score for sorting.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL