query

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: BSD-3-Clause Imports: 0 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag

type Flag uint64

Flag is a type for query flags

const (
	QueryVerbatim     Flag = 0x1
	QueryNoContent    Flag = 0x2
	QueryTypePrefix   Flag = 0x3
	QueryTypeSuffix   Flag = 0x4
	QueryTypeWildcard Flag = 0x5

	DefaultOffset = 0
	DefaultNum    = 10
)

type HighlightOptions

type HighlightOptions struct {
	Fields []string
	Tags   [2]string
}

HighlightOptions represents the options to higlight specific document fields. See http://redisearch.io/Highlight/

type Operator

type Operator string
const (
	Eq Operator = "="

	Gt  Operator = ">"
	Gte Operator = ">="

	Lt  Operator = "<"
	Lte Operator = "<="

	Between          Operator = "BETWEEN"
	BetweenInclusive Operator = "BETWEEEN_EXCLUSIVE"
)

type Paging

type Paging struct {
	Offset int
	Num    int
}

Paging represents the offset paging of a search result

type Predicate

type Predicate struct {
	Property string
	Operator Operator
	Value    []interface{}
}

func Equals

func Equals(property string, value interface{}) Predicate

func GreaterThan

func GreaterThan(property string, value interface{}) Predicate

func GreaterThanEquals

func GreaterThanEquals(property string, value interface{}) Predicate

func InRange

func InRange(property string, min, max interface{}, inclusive bool) Predicate

func LessThan

func LessThan(property string, value interface{}) Predicate

func LessThanEquals

func LessThanEquals(property string, value interface{}) Predicate

func NewPredicate

func NewPredicate(property string, operator Operator, values ...interface{}) Predicate

type Query

type Query struct {
	Index      string
	Term       string
	Field      string
	Predicates []Predicate
	Paging     Paging
	Flags      Flag

	HighlightOpts *HighlightOptions
	SummarizeOpts *SummaryOptions
}

Query is a single search query and all its parameters and predicates

func NewQuery

func NewQuery(index, term string) *Query

NewQuery creates a new query for a given index with the given search term. For currently the index parameter is ignored

func (*Query) AddPredicate

func (q *Query) AddPredicate(p Predicate) *Query

AddPredicate adds a predicate to the query's filters

func (*Query) Highlight

func (q *Query) Highlight(fields []string, openTag, closeTag string) *Query

Highlight sets highighting on given fields. Highlighting marks all the query terms with the given open and close tags (i.e. <b> and </b> for HTML)

func (*Query) Limit

func (q *Query) Limit(offset, num int) *Query

Limit sets the paging offset and limit for the query

func (*Query) SetField

func (q *Query) SetField(field string) *Query

func (*Query) SetFlags

func (q *Query) SetFlags(flags Flag) *Query

SetFlags sets the query's optional flags

func (*Query) Summarize

func (q *Query) Summarize(fields ...string) *Query

Summarize sets summarization on the given list of fields. It will instruct the engine to extract the most relevant snippets from the fields and return them as the field content. This function works with the default values of the engine, and only sets the fields. There is a function that accepts all options - SummarizeOptions

func (*Query) SummarizeOptions

func (q *Query) SummarizeOptions(opts SummaryOptions) *Query

SummarizeOptions sets summarization on the given list of fields. It will instruct the engine to extract the most relevant snippets from the fields and return them as the field content.

This function accepts advanced settings for snippet length, separators and number of snippets

type SummaryOptions

type SummaryOptions struct {
	Fields       []string
	FragmentLen  int    // default 20
	NumFragments int    // default 3
	Separator    string // default "..."
}

SummaryOptions represents the configuration used to create field summaries. See http://redisearch.io/Highlight/

Jump to

Keyboard shortcuts

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