uquery

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 20 Imported by: 1 module, 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

Index

Constants

View Source
const DefaultRescoreWindow = 10

DefaultRescoreWindow is the Elasticsearch default window_size.

View Source
const MaxRewriteMatches = 65536

MaxRewriteMatches is hard limit of documents joined by single nested / has_child / has_parent clause.

Variables

View Source
var (
	QueryRuleTypes         = []string{"pinned", "exclude"}
	QueryRuleCriteriaTypes = []string{"exact", "fuzzy", "prefix", "suffix", "contains", "lt", "lte", "gt", "gte", "always"}
)

QueryRuleTypes and QueryRuleCriteriaTypes are the values the query rules API accepts.

Functions

func FormatResponse

func FormatResponse(resp *meta.SearchResponse, q *meta.ZedQuery, buckets *search.Bucket) error

func MatchQueryRules added in v1.4.0

func MatchQueryRules(ruleset *meta.QueryRuleset, criteria map[string]interface{}) []*meta.QueryRule

MatchQueryRules returns the rules of ruleset whose criteria all match.

func ParseQueryDSL

func ParseQueryDSL(q *meta.ZedQuery, mappings *meta.Mappings, analyzers map[string]*analysis.Analyzer) (riot.SearchRequest, error)

ParseQueryDSL parse query DSL and return searchRequest

func ParseQueryDSLFromV1

func ParseQueryDSLFromV1(q *v1.ZedQuery) (*meta.ZedQuery, error)

ParseQueryDSLFromV1 parse query DSL from search v1 and return new zed query DSL

func RescoreWindow added in v1.4.0

func RescoreWindow(rescorers []*Rescorer, from, size int) int

RescoreWindow is the number of top hits a search has to collect so that every rescorer sees its whole window and the requested page.

func Rewrite

func Rewrite(query interface{}, exec func(sub map[string]interface{}, collectField string) ([]string, error)) (interface{}, error)

Rewrite replaces `nested`, `has_child`, `has_parent` and `parent_id` clauses of query DSL by plain term queries on hidden fields. Riot has no block join support, so joins are resolved in separate search pass (exec) and result is pushed back into query as list of document ids.

Clauses are rewritten as:

nested{path,query}       -> terms _id           of matching _nested_parent
has_child{type,query}    -> terms _id           of matching _join_parent
has_parent{type,query}   -> terms _join_parent  of matching _id
parent_id{type,id}       -> _join_name + _join_parent terms

`score_mode` / `score` are accepted but ignored: joined documents get constant score, child scores are not propagated to parent.

func RewriteLimit

func RewriteLimit() int

RewriteLimit returns maximum number of documents single join clause may match.

func RuleQuery added in v1.4.0

func RuleQuery(body map[string]interface{}, lookup RulesetLookup) (map[string]interface{}, error)

RuleQuery rewrites the body of a rule query into the query DSL applying the matched rules: pinned documents promote over organic, excluded documents are removed from all results.

func SortQueryRules added in v1.4.0

func SortQueryRules(rules []*meta.QueryRule)

SortQueryRules orders rules by priority, rules without priority last, and keeps the stored order of equal priorities.

func Transform added in v1.4.0

func Transform(query interface{}, fns map[string]TransformFunc) (interface{}, error)

Transform walks query and replaces every clause named in fns, at any depth of compound queries, by the query its function returns.

func ValidateQueryRule added in v1.4.0

func ValidateQueryRule(rule *meta.QueryRule) error

ValidateQueryRule checks a rule of the query rules API.

Types

type ExecFunc

type ExecFunc func(sub map[string]interface{}, collectField string) ([]string, error)

ExecFunc runs sub query and returns value of collectField for every matching document. Values are returned one per match, duplicates included, so that callers can count matches per parent (has_child min_children/max_children).

type Rescorer added in v1.4.0

type Rescorer struct {
	WindowSize         int
	Query              map[string]interface{}
	QueryWeight        float64
	RescoreQueryWeight float64
	ScoreMode          string // total, multiply, avg, max, min
}

Rescorer is one query rescorer of the rescore section of a search.

func ParseRescore added in v1.4.0

func ParseRescore(v interface{}) ([]*Rescorer, error)

ParseRescore parses a rescorer object or an array of them.

func (*Rescorer) Combine added in v1.4.0

func (r *Rescorer) Combine(score, rescore float64, matched bool) float64

Combine returns the rescored score of a hit of the window. matched is false when the hit does not match the rescore query, which keeps its weighted original score, as Elasticsearch does.

type RulesetLookup added in v1.4.0

type RulesetLookup func(id string) (*meta.QueryRuleset, error)

RulesetLookup loads a ruleset by id.

type TransformFunc added in v1.4.0

type TransformFunc func(body map[string]interface{}) (map[string]interface{}, error)

TransformFunc replaces the body of a query clause by a new query.

Directories

Path Synopsis
internal/testutil
Package testutil holds helpers shared by the analysis test packages.
Package testutil holds helpers shared by the analysis test packages.
Package assoc implements the Elasticsearch "associated terms" features (more_like_this, suggesters, significant_terms) as pure functions over riot readers.
Package assoc implements the Elasticsearch "associated terms" features (more_like_this, suggesters, significant_terms) as pure functions over riot readers.

Jump to

Keyboard shortcuts

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