Documentation
¶
Overview ¶
Package search implements full-text message search: the query grammar, the FTS5 MATCH construction, membership filtering, snippets and cursor pagination behind GET /api/v1/search.
Grammar (operators are case-insensitive, whitespace separates tokens):
words "exact phrase" in:#channel from:@user has:file|image|link before:YYYY-MM-DD after:YYYY-MM-DD
Words and phrases must all match (AND). The last bare word also matches as a prefix. Different operators narrow the result (AND); a repeated in: or from: widens it (OR); repeated has: operators all have to hold; repeated before:/after: intersect. before:D keeps messages created before the start of day D and after:D those created at or after it, in the server's local time zone. A token with an unknown operator name (or an operator with an empty value) is an ordinary word.
Index ¶
Constants ¶
const ( DefaultLimit = 50 MaxLimit = 50 )
Page sizes: a page holds at most MaxLimit results.
const MaxCursorChars = 200
MaxCursorChars bounds the length of a cursor accepted from a client.
const MaxQueryChars = 256
MaxQueryChars bounds the q parameter.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Params ¶
type Params struct {
// Q is the raw query text (see the package comment for the grammar).
Q string
// Cursor is the NextCursor of the previous page; empty for the first page.
Cursor string
// Limit is the page size, 1..MaxLimit; 0 means DefaultLimit.
Limit int
}
Params are the inputs of one search request.
type Query ¶
type Query struct {
// Terms are the words and phrases, in the order typed. Terms without a
// single letter or digit are dropped, as the tokenizer would ignore them.
Terms []Term
// Channels are the in: values (lower case, without "#"); any may match.
Channels []string
// Users are the from: values (without "@"); any may match.
Users []string
// HasFile, HasImage and HasLink are the has: filters.
HasFile, HasImage, HasLink bool
// Before is the exclusive upper bound and After the inclusive lower bound
// of created_at in unix milliseconds; nil means unbounded.
Before, After *int64
}
Query is a parsed search query.
func ParseQuery ¶
ParseQuery parses q. Dates are read as midnight in loc (time.Local when nil). The error is a *chat.ValidationError on field "q".
func (Query) Match ¶
Match returns the FTS5 MATCH expression for the text terms, or "" when the query has none (a filter-only query). Every term is one double-quoted FTS5 string (internal quotes doubled), so no input can introduce an FTS5 operator, column filter or syntax error; terms are AND-ed and the last term gets a prefix star when it is a bare word.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service searches the messages of the channels an actor belongs to.
func New ¶
New returns a search Service over db. chat hydrates the hits into wire messages. loc is the time zone of before:/after: dates; nil means time.Local, the server's zone.
func (*Service) Search ¶
func (s *Service) Search(ctx context.Context, actor chat.Actor, p Params) (protocol.SearchPage, error)
Search returns one page of hits, best match first (newest first for a query without text terms). Only messages in channels the actor is a member of and may view are searched; deleted and system messages never match.