search

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package search implements the text analyzer behind full-text search: the pipeline that turns field text and query strings into the terms the match evaluator and the search index agree on.

The TypeScript client (client/src/search/) implements the identical pipeline; cross-language conformance vectors live in testdata/search/vectors.json. Term-for-term agreement between the two is the contract that makes a locally executed match and a server-executed match return the same rows, so every stage is defined without reference to locale, ICU, or any other environment-dependent tables. Every stage follows the tables of Unicode UnicodeVersion, and a code point that version does not assign is a separator:

  1. Unicode NFKC normalization, so full-width forms, ligatures and compatibility characters compare equal to their plain spellings.
  2. Unicode full lowercase (Default Case Conversion, no locale), the mapping JavaScript's String.prototype.toLowerCase applies.
  3. Unless Options.KeepDiacritics is set: NFD, drop the combining marks of the Combining Diacritical Marks block (U+0300–U+036F), NFC. The range restriction folds Latin, Greek and Cyrillic accents while leaving scripts whose marks carry meaning — Thai, Devanagari, Hebrew, Arabic — untouched.
  4. Segmentation. Runs of letters, digits and combining marks form one term each, capped at 64 code points. Code points in the CJK ranges below instead form runs emitted as character bigrams (a one-character run is emitted as is), which makes text in scripts written without word separators searchable without a dictionary.

The CJK ranges are fixed by this package rather than taken from Unicode script tables: U+3005–U+3007, U+3040–U+30FF (Hiragana, Katakana), U+3400–U+4DBF, U+4E00–U+9FFF, U+F900–U+FAFF, U+20000–U+2FA1F (Han), U+AC00–U+D7A3 (Hangul syllables).

A term's position is its index in the returned slice; scoring measures proximity as index distance.

Index

Constants

View Source
const UnicodeVersion = "15.0.0"

UnicodeVersion is the Unicode version whose tables the analyzer follows. Text in letters a later version assigns analyzes the same in every runtime: those code points split terms.

Variables

This section is empty.

Functions

func Analyze

func Analyze(text string, opts Options) []string

Analyze returns the terms of text in document order. It returns nil for text that yields no terms, including the empty string.

Every returned term is a slice of one string — text itself when it needed no normalization — so retaining a single term retains the whole of it.

Types

type Options

type Options struct {
	// KeepDiacritics disables the diacritic fold, so "café" and "cafe"
	// analyze to distinct terms.
	KeepDiacritics bool
}

Options configure analysis. The zero value is the default analyzer, and what a schema that sets no analyzer options gets.

type QueryTerm

type QueryTerm struct {
	Term string

	// Prefix marks a term that matches any indexed term it prefixes rather
	// than only itself. Only the final term of a query can carry it, and only
	// when the query ends in the term itself — a trailing space or other
	// separator makes the final term exact.
	Prefix bool
}

QueryTerm is one term of an analyzed query string.

func AnalyzeQuery

func AnalyzeQuery(query string, opts Options) []QueryTerm

AnalyzeQuery returns the terms of a query string, in order, with the final term marked as a prefix when the query ends inside it. It returns nil for a query that yields no terms.

Jump to

Keyboard shortcuts

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