search

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	DefaultLimit = 50
	MaxLimit     = 50
)

Page sizes: a page holds at most MaxLimit results.

View Source
const MaxCursorChars = 200

MaxCursorChars bounds the length of a cursor accepted from a client.

View Source
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

func ParseQuery(q string, loc *time.Location) (Query, error)

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

func (q Query) Match() string

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

func New(db *store.DB, c *chat.Service, loc *time.Location) *Service

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.

type Term

type Term struct {
	// Text is the term as typed (without the surrounding quotes of a phrase).
	Text string
	// Phrase marks a "quoted phrase"; other terms are bare words.
	Phrase bool
}

Term is one text term of a query.

Jump to

Keyboard shortcuts

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