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 ¶
- type Builder
- func (b *Builder) And() *Builder
- func (b *Builder) Build(defaultField string, analyzer *analysis.Analyzer) (*riot.TopNSearch, error)
- func (b *Builder) Field(name string) *Builder
- func (b *Builder) Form(from int) *Builder
- func (b *Builder) From(from int) *Builder
- func (b *Builder) Highlight(enabled ...bool) *Builder
- func (b *Builder) HighlightEnabled() bool
- func (b *Builder) Match(text string) *Builder
- func (b *Builder) MatchAll(text ...string) *Builder
- func (b *Builder) Or() *Builder
- func (b *Builder) Size(size int) *Builder
- func (b *Builder) Sort(field string, ascending bool) *Builder
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 ¶
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 ¶
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 ¶
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) Highlight ¶
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 ¶
HighlightEnabled reports whether highlighting was enabled. Nil is disabled.
func (*Builder) MatchAll ¶
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.