grsearch

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: BSD-3-Clause Imports: 9 Imported by: 1

README

grsearch

go-redis based interface to RediSearch & RedisJSON designed to extend the go-redis API and follow its style as closely as possible.

The RediSearch functions are all prefixed with FT and follow the native command syntax as closely as possible although options and parameters for FT.SEARCH, FT.CREATE and FT.AGGREGATE and represented as structs. JSON searching is implemented via the FTSearchJSON method as result parsing differs from that needed for hash result parsing.

Search results are returned in using the SearchResult struct. Documents in search results are represented using the HashQueryResult and JSONQueryResult structs stored in the Value property of the results struct.

Builders

The IndexBuilder, QueryBuilder and AggregateBuilder types provide a fluent interface to the options structs.

options := grsearch.NewIndexBuilder().
        On("hash").
		Prefix("account:").
		Schema(grsearch.TagAttribute{
			Name    : "account_id",
			Alias   : "id",
			Sortable: true}).
        Schema(grsearch.TextAttribute{Name: "customer",
		    Sortable: true}).Schema(grsearch.TextAttribute{
		    Name    : "email",
		    Sortable: true}).
        Schema(grsearch.TagAttribute{
		    Name    : "account_owner",
		    Alias   : "owner",
		    Sortable: true}).
        Schema(grsearch.NumericAttribute{
		    Name    : "balance",
		    Sortable: true,
	}).Options()

as opposed to

options := grsearch.NewIndexOptions()
options.On = "hash"
options.Prefix = []string{"account:"}
options.Schema = []grsearch.SchemaAttribute{
	grsearch.TagAttribute{
		Name    : "account_id",
		Alias   : "id",
		Sortable: true},
    grsearch.TextAttribute{Name: "customer",
		Sortable: true},
	grsearch.TextAttribute{
		Name    : "email",
		Sortable: true},
    grsearch.TagAttribute{
		Name    : "account_owner",
		Alias   : "owner",
		Sortable: true},
	Schema(grsearch.NumericAttribute{
		Name    : "balance",
		Sortable: true,
	}
}
Searching hashes
import (
	"context"
	"log"

	"github.com/goslogan/grsearch"
	"github.com/redis/go-redis/v9"
)

client := grsearch.NewClient(&redis.Options{})
ctx := context.Background()

searchResult, err := client.FTSearch(ctx, "customers", "@id:{1128564}", nil).Results()
for id, customer := range searchResult {
	fmt.Println(searchResult.Value[id])
}

Search JSON

JSON searches return a map of JSONQueryResult (keyed by document key name). The Value property is set to the result of unmarshalling the string result into a map[string]interface{}.


import (
	"context"
	"log"

	"github.com/goslogan/grsearch"
	"github.com/redis/go-redis/v9"
)

client := grsearch.NewClient(&redis.Options{})
ctx := context.Background()

options := grsearch.NewQueryBuilder().
	Return("$..data", "data").
	WithScores().
	Options()

searchResult, err := client.FTSearch(ctx, "jcustomers", "@id:{1128564}", options).Results()
for id, customer := range searchResult {
	fmt.Println(searchResult[id].Value["data"])
}

Working with JSON.


import (
	"context"

	"github.com/goslogan/grsearch"
	"github.com/redis/go-redis/v9"
)

import (
	"context"
    "log"

    "github.com/goslogan/grsearch" 
	"github.com/redis/go-redis/v9"
    
)


client := grsearch.NewClient(&redis.Options{})
ctx := context.Background()

if _, err := client.JSONSet(ctx, "helloworld", "$", `{"a": 1, "b": 2, "hello": "world"}`).Result(); err != nil {
    log.Fatalf("Unable to set value: %+v", err)
}

helloVal := client.JSONGet(ctx, "helloworld", "$.hello").Val()


Documentation

Overview

Package grsearch is an extension to github.com/redis/go-redis, implementing support for RedisJSON and RediSearch. It attempts to follow the syntactic style of go-redis as closely as possible.

query provides an interface to RedisSearch's query functionality.

grsearch main module - defines the client class

Index

Constants

View Source
const (
	DefaultOffset = 0  // default first value for return offset
	DefaultLimit  = 10 // default number of results to return

	GeoMiles      = "mi"
	GeoFeet       = "f"
	GeoKilimetres = "km"
	GeoMetres     = "m"
	SortAsc       = "ASC"
	SortDesc      = "DESC"
	SortNone      = "" // SortNone is used to indicate that no sorting is required if you want be explicit

)

Variables

View Source
var LoadAll = AggregateLoad{Name: "*"}

LoadAll can be used to indicate FT.AGGREGATE idx LOAD *

Functions

func FilterValue

func FilterValue(val float64, exclusive bool) interface{}

FilterValue formats a value for use in a filter and returns it

Types

type AggregateApply

type AggregateApply struct {
	Expression string
	As         string
}

type AggregateBuilder

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

func NewAggregateBuilder

func NewAggregateBuilder() *AggregateBuilder

NewAggregateBuilder creats a new fluid builder for aggregates

func (*AggregateBuilder) Apply

func (a *AggregateBuilder) Apply(expression, name string) *AggregateBuilder

Apply appends a transform to the apply list

func (*AggregateBuilder) Cursor

func (a *AggregateBuilder) Cursor(count uint64, timeout time.Duration) *AggregateBuilder

WithCursor creates a cursor for the aggregate to scan parts of the result

func (*AggregateBuilder) Dialect

func (a *AggregateBuilder) Dialect(version uint8) *AggregateBuilder

Dialect sets the dialect option for the aggregate. It is NOT checked.

func (*AggregateBuilder) Filter

func (a *AggregateBuilder) Filter(filter string) *AggregateBuilder

Filter adds a result filter

func (*AggregateBuilder) GroupBy

GroupBy adds a new group by statement (constructed with a GroupByBuilder)

func (*AggregateBuilder) Limit

func (a *AggregateBuilder) Limit(offset, num int64) *AggregateBuilder

Limit sets the result limit

func (*AggregateBuilder) Load

func (a *AggregateBuilder) Load(name string, as string) *AggregateBuilder

Load adds a field to the load list for the aggregate. The alias can be the empty string.

func (*AggregateBuilder) LoadAll

func (a *AggregateBuilder) LoadAll() *AggregateBuilder

LoadAll sets the load list for this aggregate to "LOAD *".

func (*AggregateBuilder) Options

func (a *AggregateBuilder) Options() *AggregateOptions

Options returns the options struct built with the builder

func (*AggregateBuilder) Param

func (a *AggregateBuilder) Param(name string, value interface{}) *AggregateBuilder

Param sets the value of a aggregate parameter.

func (*AggregateBuilder) Params

func (a *AggregateBuilder) Params(params map[string]interface{}) *AggregateBuilder

Params sets all current parameters

func (*AggregateBuilder) SortBy

SortBy adds a sorting step to this aggregate.

func (*AggregateBuilder) SortByMax

func (a *AggregateBuilder) SortByMax(keys []AggregateSortKey, max int64) *AggregateBuilder

SortByMax sets the MAX limit on an aggregate sort key. This will be ignored if not sort keys have been supplied.

func (*AggregateBuilder) Timeout

func (a *AggregateBuilder) Timeout(timeout time.Duration) *AggregateBuilder

Timeout sets the timeout for the aggregate, overriding the default

func (*AggregateBuilder) Verbatim

func (a *AggregateBuilder) Verbatim() *AggregateBuilder

Verbatim sets the verbatim flag, disabling stemming

type AggregateCmd

type AggregateCmd struct {
	redis.Cmd
	// contains filtered or unexported fields
}

func NewAggregateCmd

func NewAggregateCmd(ctx context.Context, args ...interface{}) *AggregateCmd

func (*AggregateCmd) RESP3Data added in v0.5.1

func (cmd *AggregateCmd) RESP3Data() *RESPData

RESPData returns the additional data returned with a RESP3 response if set.

func (*AggregateCmd) Result

func (cmd *AggregateCmd) Result() ([]map[string]interface{}, error)

func (*AggregateCmd) SetRESP3Data added in v0.5.1

func (cmd *AggregateCmd) SetRESP3Data(data *RESPData)

SetRESPData stores the additional data returned with a RESP3 response if set.

func (*AggregateCmd) SetTotalResults added in v0.5.1

func (cmd *AggregateCmd) SetTotalResults(n int64)

func (*AggregateCmd) SetVal

func (cmd *AggregateCmd) SetVal(val []map[string]interface{})

func (*AggregateCmd) TotalResults added in v0.5.1

func (cmd *AggregateCmd) TotalResults() int64

func (*AggregateCmd) Val

func (cmd *AggregateCmd) Val() []map[string]interface{}

type AggregateCursor

type AggregateCursor struct {
	Count   uint64
	MaxIdle time.Duration
}

type AggregateFilter

type AggregateFilter string

type AggregateGroupBy

type AggregateGroupBy struct {
	Properties []string
	Reducers   []AggregateReducer
}

AggregateGroupBy represents a single GROUPBY statement in a

type AggregateLoad

type AggregateLoad struct {
	Name string
	As   string
}

Load represents parameters to the LOAD argument

type AggregateOptions

type AggregateOptions struct {
	Verbatim bool             // Set to true if stemming should not be used
	Load     []AggregateLoad  // Values for the LOAD subcommand; use the [LoadAll] variable to represent "LOAD *"
	Timeout  time.Duration    // Sets the query timeout. If zero, no TIMEOUT subcommmand is used
	Cursor   *AggregateCursor // nil means no cursor
	Params   map[string]interface{}
	Dialect  uint8
	Steps    []AggregateStep // The steps to be executed in order
}

AggregateOptions represents the options that can be passed to [FT.AGGREGATE]. This can be built by calling the NewAggregateOptions function or via [AggregateOptionsBuilder.Options] using the Builder API.

func NewAggregateOptions

func NewAggregateOptions() *AggregateOptions

NewAggregateOptions creates a new query with defaults set

type AggregateReducer

type AggregateReducer struct {
	Name string
	As   string
	Args []interface{}
}

func ReduceAvg

func ReduceAvg(property, as string) AggregateReducer

ReduceAvg returns a Reducer configured to return the mean value of the given property.

func ReduceCount

func ReduceCount(as string) AggregateReducer

ReduceCount returns a Reducer configured to count records

func ReduceCountDistinct

func ReduceCountDistinct(property, as string) AggregateReducer

ReduceCountDistinct returns a Reducer configured to count distinct values of a property

func ReduceCountDistinctIsh

func ReduceCountDistinctIsh(property, as string) AggregateReducer

ReduceCountDistinctIsh returns a Reducer configured to count distinct values of a property approximately

func ReduceFirstValue

func ReduceFirstValue(property, order, as string) AggregateReducer

ReduceFirstValue returns a Reducer configured to get the first value of a given property with optional sorting.

func ReduceFirstValueBy

func ReduceFirstValueBy(property, comparator, order, as string) AggregateReducer

ReduceFirstValue returns a Reducer configured to get the first value of a given property with optional sorting using another property as the comparator

func ReduceMax

func ReduceMax(property, as string) AggregateReducer

ReduceMax returns a Reducer configured to return the maximum value of the given property.

func ReduceMin

func ReduceMin(property, as string) AggregateReducer

ReduceMin returns a Reducer configured to return the minimum value of the given property.

func ReduceQuantile

func ReduceQuantile(property string, quantile float64, as string) AggregateReducer

ReduceAvg returns a Reducer configured to return the mean value of the given property.

func ReduceRandomSample

func ReduceRandomSample(property string, sampleSize int64, as string) AggregateReducer

ReduceRandomSample returns a Reducder configured to perform a random sampling of values of the property with a given sample size

func ReduceStdDev

func ReduceStdDev(property, as string) AggregateReducer

ReduceAvg returns a Reducer configured to return the mean value of the given property.

func ReduceSum

func ReduceSum(property, as string) AggregateReducer

ReduceSum returns a Reducer configured to return the sum of the values of the given property.

func ReduceToList

func ReduceToList(property, as string) AggregateReducer

ReduceToList returns a reducer configured to merge all distinct values of the property into an array

type AggregateSort

type AggregateSort struct {
	Keys []AggregateSortKey
	Max  int64
}

type AggregateSortKey

type AggregateSortKey struct {
	Name  string
	Order string
}

type AggregateStep

type AggregateStep interface {
	// contains filtered or unexported methods
}

type Client

type Client struct {
	redis.Client
	// contains filtered or unexported fields
}

Client represents the wrapped go-redis client. New clients should be created using NewClient

func FromRedisClient added in v0.5.3

func FromRedisClient(redisClient *redis.Client) *Client

FromRedisClient builds a client from an existing redis client

func NewClient

func NewClient(options *redis.Options) *Client

NewClient returns a new search client using the same options as the standard go-redis client.

func (Client) FTAggregate

func (c Client) FTAggregate(ctx context.Context, index, query string, options *AggregateOptions) *AggregateCmd

FTAggregate runs a search query on an index, and perform saggregate transformations on the results, extracting statistics etc from them

func (Client) FTAliasAdd

func (c Client) FTAliasAdd(ctx context.Context, alias, index string) *redis.BoolCmd

FTAliasAdd add an alias to an index.

func (Client) FTAliasDel

func (c Client) FTAliasDel(ctx context.Context, alias string) *redis.BoolCmd

FTAliasDel deletes an alias

func (Client) FTAliasUpdate

func (c Client) FTAliasUpdate(ctx context.Context, alias, index string) *redis.BoolCmd

FTAliasDel deletes an alias

func (Client) FTConfigGet

func (c Client) FTConfigGet(ctx context.Context, keys ...string) *ConfigGetCmd

FTConfigGet retrieves public config info from the search config

func (Client) FTConfigSet

func (c Client) FTConfigSet(ctx context.Context, name, value string) *redis.BoolCmd

FTConfigGet sets values in the search config

func (Client) FTCreate

func (c Client) FTCreate(ctx context.Context, index string, options *IndexOptions) *redis.BoolCmd

FTCreate creates a new index.

func (Client) FTDictAdd

func (c Client) FTDictAdd(ctx context.Context, dictionary string, terms ...string) *redis.IntCmd

FTDictAdd adds one more terms to a dictionary

func (Client) FTDictDel

func (c Client) FTDictDel(ctx context.Context, dictionary string, terms ...string) *redis.IntCmd

FTDictDel removes terms from a dictionary

func (Client) FTDictDump

func (c Client) FTDictDump(ctx context.Context, dictionary string) *redis.StringSliceCmd

FTDictDump returns a slice containing all the terms in a dictionary

func (Client) FTDropIndex

func (c Client) FTDropIndex(ctx context.Context, index string, dropDocuments bool) *redis.BoolCmd

FTDropIndex removes an index, optionally dropping documents in the index.

func (Client) FTInfo

func (c Client) FTInfo(ctx context.Context, index string) *InfoCmd

FTInfo returns information about an index

func (Client) FTList

func (c Client) FTList(ctx context.Context) *redis.StringSliceCmd

FTList returns a list of all the indexes currently defined

func (Client) FTSearchHash added in v0.4.0

func (c Client) FTSearchHash(ctx context.Context, index string, query string, qryOptions *QueryOptions) *QueryCmd

FTSearch queries an index (on hashes)

func (Client) FTSearchJSON

func (c Client) FTSearchJSON(ctx context.Context, index string, query string, qryOptions *QueryOptions) *QueryCmd

FTSearch queries an index on JSON documents

func (Client) FTSynDump

func (c Client) FTSynDump(ctx context.Context, index string) *SynonymDumpCmd

FTSynDump returns the contents of synonym map for an index

func (Client) FTSynUpdate

func (c Client) FTSynUpdate(ctx context.Context, index string, group string, terms ...string) *redis.BoolCmd

FTSynUpdate adds to or modifies a synonym group

func (Client) FTTagVals

func (c Client) FTTagVals(ctx context.Context, index, tag string) *redis.StringSliceCmd

FTTagVals returns the distinct values for a given tag

func (*Client) Process

func (c *Client) Process(ctx context.Context, cmd redis.Cmder) error

type ConfigGetCmd

type ConfigGetCmd struct {
	redis.Cmd
	// contains filtered or unexported fields
}

func NewConfigGetCmd

func NewConfigGetCmd(ctx context.Context, args ...interface{}) *ConfigGetCmd

func (*ConfigGetCmd) Result

func (cmd *ConfigGetCmd) Result() (map[string]string, error)

func (*ConfigGetCmd) SetVal

func (cmd *ConfigGetCmd) SetVal(val map[string]string)

func (*ConfigGetCmd) Val

func (cmd *ConfigGetCmd) Val() map[string]string

type ExtCmder

type ExtCmder interface {
	redis.Cmder
	// contains filtered or unexported methods
}

type GeoAttribute

type GeoAttribute struct {
	Name     string
	Alias    string
	Sortable bool
	NoIndex  bool
}

type GeoFilter

type GeoFilter struct {
	Attribute         string
	Long, Lat, Radius float64
	Units             string
}

GeoFilter represents a location and radius to be used in a search query

type GeometryAttribute

type GeometryAttribute struct {
	Name  string
	Alias string
}

type GroupByBuilder

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

func NewGroupByBuilder

func NewGroupByBuilder() *GroupByBuilder

NewGroupByBuilder creates a builder for group by statements in aggregates.

func (*GroupByBuilder) GroupBy

func (g *GroupByBuilder) GroupBy() AggregateGroupBy

GroupBy returns the grouping defined by the builder

func (*GroupByBuilder) Properties

func (g *GroupByBuilder) Properties(properties []string) *GroupByBuilder

Properties sets all the property for a group by at one time.

func (*GroupByBuilder) Property

func (g *GroupByBuilder) Property(name string) *GroupByBuilder

Property appends a property to the properties list, not adding it if it already exists

func (*GroupByBuilder) Reduce

Reduce adds a reducer function to the group by.

type IndexBuilder

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

func NewIndexBuilder

func NewIndexBuilder() *IndexBuilder

NewIndexBuilder creats a new fluid builder for indexes

func (*IndexBuilder) Filter

func (i *IndexBuilder) Filter(filter string) *IndexBuilder

Filter sets the IndexOptions' Filter field to the provided value

func (*IndexBuilder) Language

func (i *IndexBuilder) Language(language string) *IndexBuilder

Language sets the IndexOptions' Language field to the provided value, setting the default language for the index

func (*IndexBuilder) LanguageField

func (i *IndexBuilder) LanguageField(field string) *IndexBuilder

LanguageField sets the IndexOptions' LanguageField field to the provided value, setting the field definining language in the index

func (*IndexBuilder) MaxTextFields

func (i *IndexBuilder) MaxTextFields() *IndexBuilder

MaxTextFields sets the IndexOptions' MaxTextFields field to true

func (*IndexBuilder) NoFields

func (i *IndexBuilder) NoFields() *IndexBuilder

NoFields sets the IndexOptions' NoFields field to true

func (*IndexBuilder) NoFreqs

func (i *IndexBuilder) NoFreqs() *IndexBuilder

NoFreqs sets the IndexOptions' NoFreqs field to true.

func (*IndexBuilder) NoHighlight

func (i *IndexBuilder) NoHighlight() *IndexBuilder

NoHighlight sets the IndexOptions' NoHighlight field to true

func (*IndexBuilder) NoOffsets

func (i *IndexBuilder) NoOffsets() *IndexBuilder

NoOffsets sets the IndexOptions' NoOffsets field to true

func (*IndexBuilder) On

func (i *IndexBuilder) On(idxType string) *IndexBuilder

On indicates if the index is on hashes (default) or json

func (*IndexBuilder) Options

func (a *IndexBuilder) Options() *IndexOptions

Options returns the options struct built with the builder

func (*IndexBuilder) Prefix

func (i *IndexBuilder) Prefix(prefix string) *IndexBuilder

Prefix appends a prefix to the IndexOptions' Prefix array

func (*IndexBuilder) Schema

Schema appends a schema attribute to the IndexOptions' Schema array

func (*IndexBuilder) Score

func (i *IndexBuilder) Score(score float64) *IndexBuilder

Score sets the IndexOptions' Score field to the provided value, setting the default score for documents (this should be zero to 1.0 and is not checked)

func (*IndexBuilder) ScoreField

func (i *IndexBuilder) ScoreField(field string) *IndexBuilder

ScoreField sets the IndexOptions' ScoreField field to the provided value, setting the field defining document score in the index

func (*IndexBuilder) SkipInitialscan

func (i *IndexBuilder) SkipInitialscan() *IndexBuilder

SkipInitialscan sets the IndexOptions' SkipInitialscan field to true.

func (*IndexBuilder) StopWord

func (i *IndexBuilder) StopWord(word string) *IndexBuilder

topWord appends a new stopword to the IndexOptions' stopwords array and sets UseStopWords to true

func (*IndexBuilder) Temporary

func (i *IndexBuilder) Temporary(secs uint64) *IndexBuilder

Temporary sets the Temporary field to the given number of seconds.

type IndexOptions

type IndexOptions struct {
	On              string
	Prefix          []string
	Filter          string
	Language        string
	LanguageField   string
	Score           float64
	ScoreField      string
	MaxTextFields   bool
	NoOffsets       bool
	Temporary       uint64 // If this is a temporary index, number of seconds until expiry
	NoHighlight     bool
	NoFields        bool
	NoFreqs         bool
	StopWords       []string
	UseStopWords    bool
	SkipInitialscan bool
	Schema          []SchemaAttribute
}

SearchIndex defines an index to be created with FT.CREATE

func NewIndexOptions

func NewIndexOptions() *IndexOptions

NewIndexOptions returns an initialised IndexOptions struct with defaults set

type Info

type Info struct {
	IndexName                  string
	Index                      *IndexOptions
	NumDocs                    int64
	MaxDocId                   int64
	NumTerms                   int64
	NumRecords                 int64
	Indexing                   float64
	PercentIndexed             float64
	HashIndexingFailures       int64
	TotalInvertedIndexBlocks   int64
	InvertedSize               float64
	VectorIndexSize            float64
	DocTableSize               float64
	OffsetVectorsSize          float64
	SortableValuesSize         float64
	KeyTableSize               float64
	AverageRecordsPerDoc       float64
	AverageBytesPerRecord      float64
	AverageOffsetsPerTerm      float64
	AverageOffsetBitsPerRecord float64
	TotalIndexingTime          time.Duration
	NumberOfUses               int64
	GCStats                    struct {
		BytesCollected       int64
		TotalMsRun           time.Duration
		TotalCycles          int64
		AverageCycleTime     time.Duration
		LastRunTime          time.Duration
		GCNumericTreesMissed int64
		GCBlocksDenied       int64
	}
	CursorStats struct {
		GlobalIdle    int64
		GlobalTotal   int64
		IndexCapacity int64
		IndexTotal    int64
	}
	DialectStats struct {
		Dialect1 int64
		Dialect2 int64
		Dialect3 int64
	}
}

Info represents the parsed results of a call to FT.INFO.

type InfoCmd

type InfoCmd struct {
	redis.Cmd
	// contains filtered or unexported fields
}

func NewInfoCmd

func NewInfoCmd(ctx context.Context, args ...interface{}) *InfoCmd

func (*InfoCmd) Result

func (cmd *InfoCmd) Result() (*Info, error)

func (*InfoCmd) SetVal

func (c *InfoCmd) SetVal(i *Info)

func (*InfoCmd) Val

func (cmd *InfoCmd) Val() *Info

type IntSlicePointerCmd

type IntSlicePointerCmd struct {
	redis.SliceCmd
	// contains filtered or unexported fields
}

func NewIntSlicePointerCmd

func NewIntSlicePointerCmd(ctx context.Context, args ...interface{}) *IntSlicePointerCmd

NewIntSlicePointerCmd initialises an IntSlicePointerCmd

func (*IntSlicePointerCmd) Result

func (cmd *IntSlicePointerCmd) Result() ([]*int64, error)

func (*IntSlicePointerCmd) SetVal

func (cmd *IntSlicePointerCmd) SetVal(val []*int64)

func (*IntSlicePointerCmd) Val

func (cmd *IntSlicePointerCmd) Val() []*int64

type Limit

type Limit struct {
	Offset int64
	Num    int64
}

queryLimit defines the results by offset and number.

func NewLimit

func NewLimit(first int64, num int64) *Limit

NewQueryLimit returns an initialized limit struct

type NumericAttribute

type NumericAttribute struct {
	Name     string
	Alias    string
	Sortable bool
	NoIndex  bool
}

type QueryBuilder

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

func NewQueryBuilder

func NewQueryBuilder() *QueryBuilder

NewAggregateBuilder creats a new fluid builder for aggregates

func (*QueryBuilder) Ascending

func (q *QueryBuilder) Ascending() *QueryBuilder

Ascending sets the sort order of the query results to ascending if sortby is set

func (*QueryBuilder) Descending

func (q *QueryBuilder) Descending() *QueryBuilder

Descending sets the sort order of the query results to ascending if sortby is set

func (*QueryBuilder) Dialect

func (q *QueryBuilder) Dialect(version uint8) *QueryBuilder

Dialect sets the dialect option for the query. It is NOT checked.

func (*QueryBuilder) ExplainScore

func (q *QueryBuilder) ExplainScore() *QueryBuilder

ExplainScore sets the EXPLAINSCORE option for searches.

func (*QueryBuilder) Filter

func (q *QueryBuilder) Filter(attribute string, min, max interface{}) *QueryBuilder

Filter adds a filter to the current set

func (*QueryBuilder) GeoFilter

func (q *QueryBuilder) GeoFilter(attribute string, long, lat, radius float64, units string) *QueryBuilder

GeoFilter adds a geographic filter to the query

func (*QueryBuilder) Highlight

func (q *QueryBuilder) Highlight(fields []string) *QueryBuilder

Highlight sets the Highlight member of the query

func (*QueryBuilder) InField

func (q *QueryBuilder) InField(field string) *QueryBuilder

InFields adds a field to the INFIELDS list limiting the search to only the given fields.

func (*QueryBuilder) InKeys

func (q *QueryBuilder) InKeys(keys []string) *QueryBuilder

InKeys sets the keys to be searched, limiting the search to only these keys.

func (*QueryBuilder) Limit

func (q *QueryBuilder) Limit(first int64, num int64) *QueryBuilder

Limit adds a limit to a query, returning the Query with the limit added (to allow chaining)

func (*QueryBuilder) NoContent

func (q *QueryBuilder) NoContent() *QueryBuilder

NoContent sets the NoContent flag to true.

func (*QueryBuilder) NoStopWords

func (q *QueryBuilder) NoStopWords() *QueryBuilder

NoStopWords disables stop word checking

func (*QueryBuilder) Options

func (a *QueryBuilder) Options() *QueryOptions

Options returns the options struct built with the builder

func (*QueryBuilder) Param

func (q *QueryBuilder) Param(name string, value interface{}) *QueryBuilder

Param sets or adds the value of a query parameter.

func (*QueryBuilder) Params

func (q *QueryBuilder) Params(params map[string]interface{}) *QueryBuilder

Params sets the current set parameters

func (*QueryBuilder) Return

func (q *QueryBuilder) Return(identifier string, alias string) *QueryBuilder

Return appends a field to the return fields list

func (*QueryBuilder) Slop

func (q *QueryBuilder) Slop(slop int8) *QueryBuilder

Slop sets the slop length.

func (*QueryBuilder) SortBy

func (q *QueryBuilder) SortBy(field string) *QueryBuilder

SortBy sets the value of the sortby option to the query.

func (*QueryBuilder) Summarize

func (q *QueryBuilder) Summarize(fields []string, separator string, length, fragments int32) *QueryBuilder

Summarize sets the Summarize member of the query,

func (*QueryBuilder) Timeout

func (q *QueryBuilder) Timeout(timeout time.Duration) *QueryBuilder

WithTimeout sets the timeout for the query, overriding the default

func (*QueryBuilder) Verbatim

func (q *QueryBuilder) Verbatim() *QueryBuilder

Verbatim disables stemming.

func (*QueryBuilder) WithPayloads

func (q *QueryBuilder) WithPayloads() *QueryBuilder

WithPayloads sets the WITHPAYLOADS option for searches

func (*QueryBuilder) WithScores

func (q *QueryBuilder) WithScores() *QueryBuilder

WithScores sets the WITHSCORES option for searches

type QueryCmd

type QueryCmd struct {
	redis.Cmd
	// contains filtered or unexported fields
}

func NewQueryCmd

func NewQueryCmd(ctx context.Context, process cmdable, onHash bool, args ...interface{}) *QueryCmd

NewQueryCmd returns an initialised query command.

func (*QueryCmd) Count

func (cmd *QueryCmd) Count() int64

Count returns the total number of results from a successful query.

func (*QueryCmd) Iterator

func (cmd *QueryCmd) Iterator(ctx context.Context) *SearchIterator

Iterator returns an iterator for the search.

func (*QueryCmd) Key added in v0.5.0

func (cmd *QueryCmd) Key(key string) *SearchResult

Key returns the individual result with the given key

func (*QueryCmd) Keys added in v0.5.0

func (cmd *QueryCmd) Keys() []string

Keys returns the redis keys for all of the results

func (*QueryCmd) Len

func (cmd *QueryCmd) Len() int64

func (*QueryCmd) RESP3Data added in v0.5.0

func (cmd *QueryCmd) RESP3Data() *RESPData

RESPData returns the additional data returned with a RESP3 response if set.

func (*QueryCmd) Result

func (cmd *QueryCmd) Result() ([]*SearchResult, error)

func (*QueryCmd) SetCount

func (cmd *QueryCmd) SetCount(count int64)

func (*QueryCmd) SetRESP3Data added in v0.5.0

func (cmd *QueryCmd) SetRESP3Data(data *RESPData)

SetRESPData stores the additional data returned with a RESP3 response if set.

func (*QueryCmd) SetTotalResults added in v0.5.0

func (cmd *QueryCmd) SetTotalResults(r int64)

SetTotalResults store the total number of possible results for the query.

func (*QueryCmd) SetVal

func (cmd *QueryCmd) SetVal(val []*SearchResult)

func (*QueryCmd) String

func (cmd *QueryCmd) String() string

func (*QueryCmd) TotalResults added in v0.5.0

func (cmd *QueryCmd) TotalResults() int64

TotalResults returns the total number of possible results for the query (whilst Count returns the number of results from a single call to FTSEearch)

func (*QueryCmd) Val

func (cmd *QueryCmd) Val() []*SearchResult

type QueryFilter

type QueryFilter struct {
	Attribute string
	Min       interface{} // either a numeric value or +inf, -inf or "(" followed by numeric
	Max       interface{} // as above
}

func NewQueryFilter

func NewQueryFilter(attribute string) QueryFilter

NewQueryFilter returns a filter with the min and max properties to set + and - infinity.

type QueryHighlight

type QueryHighlight struct {
	Fields   []string
	OpenTag  string
	CloseTag string
}

QueryHighlight allows the user to define optional query highlighting

func NewQueryHighlight

func NewQueryHighlight() *QueryHighlight

type QueryOptions

type QueryOptions struct {
	NoContent    bool
	Verbatim     bool
	NoStopWords  bool
	WithScores   bool
	WithPayloads bool
	WithSortKeys bool
	InOrder      bool
	ExplainScore bool
	Limit        *Limit
	Return       []QueryReturn
	Filters      []QueryFilter
	InKeys       []string
	InFields     []string
	Language     string
	Slop         int8
	Expander     string
	Scorer       string
	SortBy       string
	SortOrder    string
	Dialect      uint8
	Timeout      time.Duration
	Summarize    *QuerySummarize
	HighLight    *QueryHighlight
	GeoFilters   []GeoFilter
	Params       map[string]interface{}
	// contains filtered or unexported fields
}

func NewQueryOptions

func NewQueryOptions() *QueryOptions

NewQuery creates a new query with defaults set

type QueryReturn

type QueryReturn struct {
	Name string
	As   string
}

type QuerySummarize

type QuerySummarize struct {
	Fields    []string
	Frags     int32
	Len       int32
	Separator string
}

func DefaultQuerySummarize

func DefaultQuerySummarize() *QuerySummarize

func NewQuerySummarize

func NewQuerySummarize() *QuerySummarize

type RESPData added in v0.5.0

type RESPData struct {
	Errors     []interface{}
	Warnings   []interface{}
	Format     string
	Attributes []interface{}
}

type SchemaAttribute

type SchemaAttribute interface {
	// contains filtered or unexported methods
}

type SearchCmdAble

type SearchCmdAble interface {
	FTSearch(ctx context.Context, index string, query string, options *QueryOptions) *QueryCmd
	FTAggregate(ctx context.Context, index string, query string, options *AggregateOptions) *QueryCmd
	FTDropIndex(ctx context.Context, index string, dropDocuments bool) *redis.BoolCmd
	FTCreateIndex(ctx context.Context, index string)
	FTConfigGet(ctx context.Context, keys ...string) *ConfigGetCmd
	FTConfigSet(ctx context.Context, name, value string) *redis.BoolCmd
	FTTagVals(ctx context.Context, index, tag string) *redis.StringSliceCmd
	FTList(ctx context.Context) *redis.StringSliceCmd
	FTInfo(ctx context.Context, index string) *InfoCmd
	FTDictAdd(ctx context.Context, dictionary string, terms ...string) *redis.IntCmd
	FTDictDel(ctx context.Context, dictionary string, terms ...string) *redis.IntCmd
	FTDictDump(ctx context.Context, dictionary string) *redis.StringSliceCmd
	FTSynUpdate(ctx context.Context, index string, group string, terms ...string) *redis.BoolCmd
	FTSynDump(ctx context.Context, index string) *SynonymDumpCmd
	FTAliasAdd(ctx context.Context, alias, index string) *redis.BoolCmd
	FTAliasDel(ctx context.Context, alias string) *redis.BoolCmd
	FTAliasUpdate(ctx context.Context, alias, index string) *redis.BoolCmd
}

type SearchIterator

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

SearchIterator is used to incrementally iterate over a collection of elements.

func NewSearchIterator

func NewSearchIterator(ctx context.Context, cmd *QueryCmd, process cmdable) *SearchIterator

NewSearchIterator returns a configured iterator for QueryCmd

func (*SearchIterator) Err

func (it *SearchIterator) Err() error

Err returns the last iterator error, if any.

func (*SearchIterator) Next

func (it *SearchIterator) Next(ctx context.Context) bool

Next advances the cursor and returns true if more values can be read.

func (*SearchIterator) Val

func (it *SearchIterator) Val() *SearchResult

Val returns the key/field at the current cursor position.

type SearchResult added in v0.5.0

type SearchResult struct {
	Key         string
	Score       float64
	Explanation interface{}
	Values      map[string]string
}

func (*SearchResult) UnMarshal added in v0.5.0

func (q *SearchResult) UnMarshal(key string, target interface{}) error

UnMarshal is a simple wrapper around encoding/JSON to simplify the retrieval of JSON results.

type SynonymDumpCmd

type SynonymDumpCmd struct {
	redis.Cmd
	// contains filtered or unexported fields
}

func NewSynonymDumpCmd

func NewSynonymDumpCmd(ctx context.Context, args ...interface{}) *SynonymDumpCmd

func (*SynonymDumpCmd) Result

func (cmd *SynonymDumpCmd) Result() (map[string][]string, error)

func (*SynonymDumpCmd) SetVal

func (cmd *SynonymDumpCmd) SetVal(val map[string][]string)

func (*SynonymDumpCmd) Val

func (cmd *SynonymDumpCmd) Val() map[string][]string

type TagAttribute

type TagAttribute struct {
	Name           string
	Alias          string
	Sortable       bool
	UnNormalized   bool
	Separator      string
	CaseSensitive  bool
	WithSuffixTrie bool
	NoIndex        bool
}

type TextAttribute

type TextAttribute struct {
	Name           string
	Alias          string
	Sortable       bool
	UnNormalized   bool
	Phonetic       string
	Weight         float64
	NoStem         bool
	WithSuffixTrie bool
	NoIndex        bool
}

type VectorAttribute

type VectorAttribute struct {
	Name           string
	Alias          string
	Algorithm      string
	Type           string
	Dim            uint64
	DistanceMetric string
	InitialCap     uint64
	BlockSize      uint64
	M              uint64
	EFConstruction uint64
	EFRuntime      uint64
	Epsilon        float64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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