query

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package query provides an immutable fluent builder for riot search requests. Expressions are left associative: Match("a").Or().Match("b").Match("c") means (a OR b) AND c, without operator precedence.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder stores a query description. Its zero value is ready to use. Fluent methods return copies; callers must retain the returned pointer. Build creates independent requests, but shares the supplied analyzer. Invalid clause operations are retained as errors until Build.

func Query

func Query() *Builder

Query returns an empty builder (all documents, size 10, offset 0, score descending, highlighting disabled).

func (*Builder) And

func (b *Builder) And() *Builder

And selects AND for the next clause (the default after each added clause). The last connector wins; leading and trailing connectors have no effect.

func (*Builder) Build

func (b *Builder) Build(defaultField string, analyzer *analysis.Analyzer) (*riot.TopNSearch, error)

Build validates the description and creates a fresh search request. Empty queries match all documents. Every text clause receives analyzer; nil lets riot use its configured default analyzer. Empty defaultField lets riot use its configured default search field. Pagination must be nonnegative and from+size must fit in an int. Sort names must not be empty.

func (*Builder) Field

func (b *Builder) Field(name string) *Builder

Field sets the last clause's field. An empty name uses Build's defaultField. It has no effect on an all-documents clause. Without a clause it records an error.

func (*Builder) Form

func (b *Builder) Form(from int) *Builder

Form is an alias for From.

func (*Builder) From

func (b *Builder) From(from int) *Builder

From sets the number of results to skip.

func (*Builder) Highlight

func (b *Builder) Highlight(enabled ...bool) *Builder

Highlight enables highlighting by default when called without arguments. If supplied, the first bool controls it; further values are ignored. Build requests match locations, leaving rendering to the caller.

func (*Builder) HighlightEnabled

func (b *Builder) HighlightEnabled() bool

HighlightEnabled reports whether highlighting was enabled. Nil is disabled.

func (*Builder) Match

func (b *Builder) Match(text string) *Builder

Match adds a clause matching any analyzed term in text.

func (*Builder) MatchAll

func (b *Builder) MatchAll(text ...string) *Builder

MatchAll with no arguments adds a clause matching all documents. With one argument it requires all analyzed terms using riot's AND operator. More than one argument is an error reported by Build.

func (*Builder) Or

func (b *Builder) Or() *Builder

Or selects OR for the next clause, after which the connector resets to AND.

func (*Builder) Size

func (b *Builder) Size(size int) *Builder

Size sets the result limit, including zero. The default is 10.

func (*Builder) Sort

func (b *Builder) Sort(field string, ascending bool) *Builder

Sort appends a sort key in priority order, replacing the default score sort. Names are literal field names, except _score selects document score. Direction is controlled only by ascending, not by prefixes in the field name.

Jump to

Keyboard shortcuts

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