Documentation ¶
Index ¶
- Constants
- Variables
- func EscapeTextFileString(value string) string
- func ProcessAggResponse(res []interface{}) [][]stringdeprecated
- func ProcessAggResponseSS(res []interface{}) [][]string
- func SerializeIndexingOptions(opts IndexingOptions, args redis.Args) redis.Args
- func SerializeSchema(s *Schema, args redis.Args) (argsOut redis.Args, err error)
- type AggregateQuery
- func (a *AggregateQuery) Apply(expression Projection) *AggregateQuery
- func (a *AggregateQuery) CursorHasResults() (res bool)
- func (a *AggregateQuery) Filter(expression string) *AggregateQuery
- func (a *AggregateQuery) GroupBy(group GroupBy) *AggregateQuery
- func (a *AggregateQuery) Limit(offset int, num int) *AggregateQuery
- func (a *AggregateQuery) Load(Properties []string) *AggregateQuery
- func (q AggregateQuery) Serialize() redis.Args
- func (a *AggregateQuery) SetCursor(cursor *Cursor) *AggregateQuery
- func (a *AggregateQuery) SetMax(value int) *AggregateQuery
- func (a *AggregateQuery) SetQuery(query *Query) *AggregateQuery
- func (a *AggregateQuery) SetVerbatim(value bool) *AggregateQuery
- func (a *AggregateQuery) SetWithSchema(value bool) *AggregateQuery
- func (a *AggregateQuery) SortBy(SortByProperties []SortingKey) *AggregateQuery
- type Autocompleter
- func (a *Autocompleter) AddTerms(terms ...Suggestion) error
- func (a *Autocompleter) Delete() error
- func (a *Autocompleter) DeleteTerms(terms ...Suggestion) error
- func (a *Autocompleter) Length() (len int64, err error)
- func (a *Autocompleter) Serialize(prefix string, opts SuggestOptions) (redis.Args, int)
- func (a *Autocompleter) Suggest(prefix string, num int, fuzzy bool) (ret []Suggestion, err error)deprecated
- func (a *Autocompleter) SuggestOpts(prefix string, opts SuggestOptions) (ret []Suggestion, err error)
- type Client
- func (i *Client) AddField(f Field) error
- func (i *Client) AddHash(docId string, score float32, language string, replace bool) (string, error)
- func (i *Client) Aggregate(q *AggregateQuery) (aggregateReply [][]string, total int, err error)
- func (i *Client) AliasAdd(name string) (err error)
- func (i *Client) AliasDel(name string) (err error)
- func (i *Client) AliasUpdate(name string) (err error)
- func (i *Client) CreateIndex(s *Schema) (err error)
- func (i *Client) Delete(docId string, deleteDocument bool) (err error)
- func (i *Client) DictAdd(dictionaryName string, terms []string) (newTerms int, err error)
- func (i *Client) DictDel(dictionaryName string, terms []string) (deletedTerms int, err error)
- func (i *Client) DictDump(dictionaryName string) (terms []string, err error)
- func (i *Client) Drop() error
- func (i *Client) Explain(q *Query) (string, error)
- func (i *Client) Get(docId string) (doc *Document, err error)
- func (i *Client) GetConfig(option string) (map[string]string, error)
- func (i *Client) GetTagVals(index string, filedName string) ([]string, error)
- func (i *Client) Index(docs ...Document) error
- func (i *Client) IndexOptions(opts IndexingOptions, docs ...Document) error
- func (i *Client) Info() (*IndexInfo, error)
- func (i *Client) MultiGet(documentIds []string) (docs []*Document, err error)
- func (i *Client) Search(q *Query) (docs []Document, total int, err error)
- func (i *Client) SetConfig(option string, value string) (string, error)
- func (i *Client) SpellCheck(q *Query, s *SpellCheckOptions) (suggs []MisspelledTerm, total int, err error)
- func (i *Client) SynAdd(indexName string, terms []string) (int64, error)
- func (i *Client) SynDump(indexName string) (map[string][]int64, error)
- func (i *Client) SynUpdate(indexName string, synonymGroupId int64, terms []string) (string, error)
- type ConnPool
- type Cursor
- type Document
- type DocumentList
- type Field
- func NewGeoField(name string) Field
- func NewGeoFieldOptions(name string, options GeoFieldOptions) Field
- func NewNumericField(name string) Field
- func NewNumericFieldOptions(name string, options NumericFieldOptions) Field
- func NewSortableNumericField(name string) Field
- func NewSortableTextField(name string, weight float32) Field
- func NewTagField(name string) Field
- func NewTagFieldOptions(name string, opts TagFieldOptions) Field
- func NewTextField(name string) Field
- func NewTextFieldOptions(name string, opts TextFieldOptions) Field
- type FieldType
- type Filter
- type Flag
- type GeoFieldOptions
- type GeoFilterOptions
- type GroupBy
- type GroupByReducers
- type HighlightOptions
- type IndexInfo
- type IndexingOptions
- type MisspelledSuggestion
- type MisspelledTerm
- type MultiError
- type MultiHostPool
- type NumericFieldOptions
- type NumericFilterOptions
- type Operator
- type Options
- type Paging
- type Predicate
- func Equals(property string, value interface{}) Predicate
- func GreaterThan(property string, value interface{}) Predicate
- func GreaterThanEquals(property string, value interface{}) Predicate
- func InRange(property string, min, max interface{}, inclusive bool) Predicate
- func LessThan(property string, value interface{}) Predicate
- func LessThanEquals(property string, value interface{}) Predicate
- func NewPredicate(property string, operator Operator, values ...interface{}) Predicate
- type Projection
- type Query
- func (q *Query) AddFilter(f Filter) *Query
- func (q *Query) Highlight(fields []string, openTag, closeTag string) *Query
- func (q *Query) Limit(offset, num int) *Query
- func (q *Query) SetExpander(exp string) *Query
- func (q *Query) SetFlags(flags Flag) *Query
- func (q *Query) SetInFields(fields ...string) *Query
- func (q *Query) SetInKeys(keys ...string) *Query
- func (q *Query) SetLanguage(lang string) *Query
- func (q *Query) SetPayload(payload []byte) *Query
- func (q *Query) SetReturnFields(fields ...string) *Query
- func (q *Query) SetScorer(scorer string) *Query
- func (q *Query) SetSortBy(field string, ascending bool) *Query
- func (q *Query) Summarize(fields ...string) *Query
- func (q *Query) SummarizeOptions(opts SummaryOptions) *Query
- type Reducer
- type Schema
- type SingleHostPool
- type SortingKey
- type SpellCheckOptions
- type SuggestOptions
- type Suggestion
- type SuggestionList
- type SummaryOptions
- type TagFieldOptions
- type TextFieldOptions
- type Unit
Examples ¶
Constants ¶
const ( // GroupByReducerCount is an alias for GROUPBY reducer COUNT GroupByReducerCount = GroupByReducers("COUNT") // GroupByReducerCountDistinct is an alias for GROUPBY reducer COUNT_DISTINCT GroupByReducerCountDistinct = GroupByReducers("COUNT_DISTINCT") // GroupByReducerCountDistinctish is an alias for GROUPBY reducer COUNT_DISTINCTISH GroupByReducerCountDistinctish = GroupByReducers("COUNT_DISTINCTISH") // GroupByReducerSum is an alias for GROUPBY reducer SUM GroupByReducerSum = GroupByReducers("SUM") // GroupByReducerMin is an alias for GROUPBY reducer MIN GroupByReducerMin = GroupByReducers("MIN") // GroupByReducerMax is an alias for GROUPBY reducer MAX GroupByReducerMax = GroupByReducers("MAX") // GroupByReducerAvg is an alias for GROUPBY reducer AVG GroupByReducerAvg = GroupByReducers("AVG") // GroupByReducerStdDev is an alias for GROUPBY reducer STDDEV GroupByReducerStdDev = GroupByReducers("STDDEV") // GroupByReducerQuantile is an alias for GROUPBY reducer QUANTILE GroupByReducerQuantile = GroupByReducers("QUANTILE") // GroupByReducerToList is an alias for GROUPBY reducer TOLIST GroupByReducerToList = GroupByReducers("TOLIST") // GroupByReducerFirstValue is an alias for GROUPBY reducer FIRST_VALUE GroupByReducerFirstValue = GroupByReducers("FIRST_VALUE") // GroupByReducerRandomSample is an alias for GROUPBY reducer RANDOM_SAMPLE GroupByReducerRandomSample = GroupByReducers("RANDOM_SAMPLE") )
Variables ¶
var DefaultIndexingOptions = IndexingOptions{ Language: "", NoSave: false, Replace: false, Partial: false, ReplaceCondition: "", }
DefaultIndexingOptions are the default options for document indexing
var DefaultOptions = Options{ NoSave: false, NoFieldFlags: false, NoFrequencies: false, NoOffsetVectors: false, Stopwords: nil, Temporary: false, TemporaryPeriod: 0, }
DefaultOptions represents the default options
var DefaultSuggestOptions = SuggestOptions{ Num: 5, Fuzzy: false, WithPayloads: false, WithScores: false, }
DefaultIndexingOptions are the default options for document indexing
Functions ¶
func EscapeTextFileString ¶ added in v0.2.0
All punctuation marks and whitespaces (besides underscores) separate the document and queries into tokens. e.g. any character of `,.<>{}[]"':;!@#$%^&*()-+=~` will break the text into terms. So the text `foo-bar.baz...bag` will be tokenized into `[foo, bar, baz, bag]` Escaping separators in both queries and documents is done by prepending a backslash to any separator. e.g. the text `hello\-world hello-world` will be tokenized as `[hello-world, hello, world]`. **NOTE** that in most languages you will need an extra backslash when formatting the document or query, to signify an actual backslash, so the actual text in redis-cli for example, will be entered as `hello\\-world`. Underscores (`_`) are not used as separators in either document or query. So the text `hello_world` will remain as is after tokenization.
func ProcessAggResponse
deprecated
added in
v0.2.0
func ProcessAggResponse(res []interface{}) [][]string
Deprecated: Please use processAggReply() instead
func ProcessAggResponseSS ¶ added in v0.2.0
func ProcessAggResponseSS(res []interface{}) [][]string
func SerializeIndexingOptions ¶ added in v0.9.0
func SerializeIndexingOptions(opts IndexingOptions, args redis.Args) redis.Args
Types ¶
type AggregateQuery ¶ added in v0.2.0
type AggregateQuery struct { Query *Query AggregatePlan redis.Args Paging *Paging Max int WithSchema bool Verbatim bool WithCursor bool Cursor *Cursor }
AggregateQuery
func NewAggregateQuery ¶ added in v0.2.0
func NewAggregateQuery() *AggregateQuery
func (*AggregateQuery) Apply ¶ added in v0.2.0
func (a *AggregateQuery) Apply(expression Projection) *AggregateQuery
Adds a APPLY clause to the aggregate plan
func (*AggregateQuery) CursorHasResults ¶ added in v0.2.0
func (a *AggregateQuery) CursorHasResults() (res bool)
func (*AggregateQuery) Filter ¶ added in v0.2.0
func (a *AggregateQuery) Filter(expression string) *AggregateQuery
Specify filters to filter the results using predicates relating to values in the result set.
func (*AggregateQuery) GroupBy ¶ added in v0.2.0
func (a *AggregateQuery) GroupBy(group GroupBy) *AggregateQuery
Adds a GROUPBY clause to the aggregate plan
func (*AggregateQuery) Limit ¶ added in v0.2.0
func (a *AggregateQuery) Limit(offset int, num int) *AggregateQuery
Sets the limit for the initial pool of results from the query.
func (*AggregateQuery) Load ¶ added in v0.9.0
func (a *AggregateQuery) Load(Properties []string) *AggregateQuery
Load document fields from the document HASH objects (if they are not in the sortables)
func (AggregateQuery) Serialize ¶ added in v0.2.0
func (q AggregateQuery) Serialize() redis.Args
func (*AggregateQuery) SetCursor ¶ added in v0.2.0
func (a *AggregateQuery) SetCursor(cursor *Cursor) *AggregateQuery
func (*AggregateQuery) SetMax ¶ added in v0.2.0
func (a *AggregateQuery) SetMax(value int) *AggregateQuery
func (*AggregateQuery) SetQuery ¶ added in v0.2.0
func (a *AggregateQuery) SetQuery(query *Query) *AggregateQuery
func (*AggregateQuery) SetVerbatim ¶ added in v0.2.0
func (a *AggregateQuery) SetVerbatim(value bool) *AggregateQuery
func (*AggregateQuery) SetWithSchema ¶ added in v0.2.0
func (a *AggregateQuery) SetWithSchema(value bool) *AggregateQuery
func (*AggregateQuery) SortBy ¶ added in v0.2.0
func (a *AggregateQuery) SortBy(SortByProperties []SortingKey) *AggregateQuery
Adds a SORTBY clause to the aggregate plan
type Autocompleter ¶
type Autocompleter struct {
// contains filtered or unexported fields
}
Autocompleter implements a redisearch auto-completer API
func NewAutocompleter ¶
func NewAutocompleter(addr, name string) *Autocompleter
NewAutocompleter creates a new Autocompleter with the given host and key name
func NewAutocompleterFromPool ¶ added in v0.9.0
func NewAutocompleterFromPool(pool *redis.Pool, name string) *Autocompleter
NewAutocompleter creates a new Autocompleter with the given pool and key name
func (*Autocompleter) AddTerms ¶
func (a *Autocompleter) AddTerms(terms ...Suggestion) error
AddTerms pushes new term suggestions to the index
func (*Autocompleter) Delete ¶
func (a *Autocompleter) Delete() error
Delete deletes the Autocompleter key for this AC
func (*Autocompleter) DeleteTerms ¶ added in v0.9.0
func (a *Autocompleter) DeleteTerms(terms ...Suggestion) error
AddTerms pushes new term suggestions to the index
func (*Autocompleter) Length ¶ added in v0.9.0
func (a *Autocompleter) Length() (len int64, err error)
AddTerms pushes new term suggestions to the index
func (*Autocompleter) Serialize ¶ added in v0.9.0
func (a *Autocompleter) Serialize(prefix string, opts SuggestOptions) (redis.Args, int)
func (*Autocompleter) Suggest
deprecated
func (a *Autocompleter) Suggest(prefix string, num int, fuzzy bool) (ret []Suggestion, err error)
Suggest gets completion suggestions from the Autocompleter dictionary to the given prefix. If fuzzy is set, we also complete for prefixes that are in 1 Levenshten distance from the given prefix
Deprecated: Please use SuggestOpts() instead
func (*Autocompleter) SuggestOpts ¶
func (a *Autocompleter) SuggestOpts(prefix string, opts SuggestOptions) (ret []Suggestion, err error)
SuggestOpts gets completion suggestions from the Autocompleter dictionary to the given prefix. SuggestOptions are passed allowing you specify if the returned values contain a payload, and scores. If SuggestOptions.Fuzzy is set, we also complete for prefixes that are in 1 Levenshtein distance from the given prefix
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an interface to redisearch's redis commands
func NewClient ¶
NewClient creates a new client connecting to the redis host, and using the given name as key prefix. Addr can be a single host:port pair, or a comma separated list of host:port,host:port... In the case of multiple hosts we create a multi-pool and select connections at random
Example ¶
exemplifies the NewClient function
package main import ( "fmt" "github.com/RediSearch/redisearch-go/redisearch" "log" "time" ) func main() { // Create a client. By default a client is schemaless // unless a schema is provided when creating the index c := redisearch.NewClient("localhost:6379", "myIndex") // Create a schema sc := redisearch.NewSchema(redisearch.DefaultOptions). AddField(redisearch.NewTextField("body")). AddField(redisearch.NewTextFieldOptions("title", redisearch.TextFieldOptions{Weight: 5.0, Sortable: true})). AddField(redisearch.NewNumericField("date")) // Drop an existing index. If the index does not exist an error is returned c.Drop() // Create the index with the given schema if err := c.CreateIndex(sc); err != nil { log.Fatal(err) } // Create a document with an id and given score doc := redisearch.NewDocument("doc1", 1.0) doc.Set("title", "Hello world"). Set("body", "foo bar"). Set("date", time.Now().Unix()) // Index the document. The API accepts multiple documents at a time if err := c.Index([]redisearch.Document{doc}...); err != nil { log.Fatal(err) } // Searching with limit and sorting docs, total, err := c.Search(redisearch.NewQuery("hello world"). Limit(0, 2). SetReturnFields("title")) fmt.Println(docs[0].Id, docs[0].Properties["title"], total, err) }
Output: doc1 Hello world 1 <nil>
func NewClientFromPool ¶ added in v1.0.0
NewClientFromPool creates a new Client with the given pool and index name
Example ¶
exemplifies the NewClientFromPool function
package main import ( "fmt" "github.com/RediSearch/redisearch-go/redisearch" "github.com/gomodule/redigo/redis" "log" "time" ) func main() { host := "localhost:6379" password := "" pool := &redis.Pool{Dial: func() (redis.Conn, error) { return redis.Dial("tcp", host, redis.DialPassword(password)) }} c := redisearch.NewClientFromPool(pool, "search-client-1") // Create a schema sc := redisearch.NewSchema(redisearch.DefaultOptions). AddField(redisearch.NewTextField("body")). AddField(redisearch.NewTextFieldOptions("title", redisearch.TextFieldOptions{Weight: 5.0, Sortable: true})). AddField(redisearch.NewNumericField("date")) // Drop an existing index. If the index does not exist an error is returned c.Drop() // Create the index with the given schema if err := c.CreateIndex(sc); err != nil { log.Fatal(err) } // Create a document with an id and given score doc := redisearch.NewDocument("doc1", 1.0) doc.Set("title", "Hello world"). Set("body", "foo bar"). Set("date", time.Now().Unix()) // Index the document. The API accepts multiple documents at a time if err := c.Index([]redisearch.Document{doc}...); err != nil { log.Fatal(err) } // Searching with limit and sorting docs, total, err := c.Search(redisearch.NewQuery("hello world"). Limit(0, 2). SetReturnFields("title")) fmt.Println(docs[0].Id, docs[0].Properties["title"], total, err) }
Output: doc1 Hello world 1 <nil>
Example (Ssl) ¶
Example of how to establish an SSL connection from your app to the RedisAI Server
package main import ( "crypto/tls" "crypto/x509" "fmt" "github.com/RediSearch/redisearch-go/redisearch" "github.com/gomodule/redigo/redis" "io/ioutil" "log" "os" "time" ) func main() { // Consider the following helper methods that provide us with the connection details (host and password) // and the paths for: // tls_cert - A a X.509 certificate to use for authenticating the server to connected clients, masters or cluster peers. The file should be PEM formatted // tls_key - A a X.509 private key to use for authenticating the server to connected clients, masters or cluster peers. The file should be PEM formatted // tls_cacert - A PEM encoded CA's certificate file host, password := getConnectionDetails() tlsready, tls_cert, tls_key, tls_cacert := getTLSdetails() // Skip if we dont have all files to properly connect if tlsready == false { return } // Load client cert cert, err := tls.LoadX509KeyPair(tls_cert, tls_key) if err != nil { log.Fatal(err) } // Load CA cert caCert, err := ioutil.ReadFile(tls_cacert) if err != nil { log.Fatal(err) } caCertPool := x509.NewCertPool() caCertPool.AppendCertsFromPEM(caCert) clientTLSConfig := &tls.Config{ Certificates: []tls.Certificate{cert}, RootCAs: caCertPool, } // InsecureSkipVerify controls whether a client verifies the // server's certificate chain and host name. // If InsecureSkipVerify is true, TLS accepts any certificate // presented by the server and any host name in that certificate. // In this mode, TLS is susceptible to man-in-the-middle attacks. // This should be used only for testing. clientTLSConfig.InsecureSkipVerify = true pool := &redis.Pool{Dial: func() (redis.Conn, error) { return redis.Dial("tcp", host, redis.DialPassword(password), redis.DialTLSConfig(clientTLSConfig), redis.DialUseTLS(true), redis.DialTLSSkipVerify(true), ) }} c := redisearch.NewClientFromPool(pool, "search-client-1") // Create a schema sc := redisearch.NewSchema(redisearch.DefaultOptions). AddField(redisearch.NewTextField("body")). AddField(redisearch.NewTextFieldOptions("title", redisearch.TextFieldOptions{Weight: 5.0, Sortable: true})). AddField(redisearch.NewNumericField("date")) // Drop an existing index. If the index does not exist an error is returned c.Drop() // Create the index with the given schema if err := c.CreateIndex(sc); err != nil { log.Fatal(err) } // Create a document with an id and given score doc := redisearch.NewDocument("doc1", 1.0) doc.Set("title", "Hello world"). Set("body", "foo bar"). Set("date", time.Now().Unix()) // Index the document. The API accepts multiple documents at a time if err := c.Index([]redisearch.Document{doc}...); err != nil { log.Fatal(err) } // Searching with limit and sorting docs, total, err := c.Search(redisearch.NewQuery("hello world"). Limit(0, 2). SetReturnFields("title")) fmt.Println(docs[0].Id, docs[0].Properties["title"], total, err) } func getConnectionDetails() (host string, password string) { value, exists := os.LookupEnv("REDISEARCH_TEST_HOST") host = "localhost:6379" password = "" valuePassword, existsPassword := os.LookupEnv("REDISEARCH_TEST_PASSWORD") if exists && value != "" { host = value } if existsPassword && valuePassword != "" { password = valuePassword } return } func getTLSdetails() (tlsready bool, tls_cert string, tls_key string, tls_cacert string) { tlsready = false value, exists := os.LookupEnv("TLS_CERT") if exists && value != "" { info, err := os.Stat(value) if os.IsNotExist(err) || info.IsDir() { return } tls_cert = value } else { return } value, exists = os.LookupEnv("TLS_KEY") if exists && value != "" { info, err := os.Stat(value) if os.IsNotExist(err) || info.IsDir() { return } tls_key = value } else { return } value, exists = os.LookupEnv("TLS_CACERT") if exists && value != "" { info, err := os.Stat(value) if os.IsNotExist(err) || info.IsDir() { return } tls_cacert = value } else { return } tlsready = true return }
Output:
func (*Client) AddHash ¶ added in v1.0.0
func (i *Client) AddHash(docId string, score float32, language string, replace bool) (string, error)
Adds a document to the index from an existing HASH key in Redis.
func (*Client) Aggregate ¶ added in v0.2.0
func (i *Client) Aggregate(q *AggregateQuery) (aggregateReply [][]string, total int, err error)
Aggregate
func (*Client) AliasUpdate ¶ added in v0.9.0
Deletes an alias to an index.
func (*Client) CreateIndex ¶
CreateIndex configues the index and creates it on redis
func (*Client) Delete ¶ added in v0.2.0
Delete the document from the index, optionally delete the actual document
func (*Client) Drop ¶
Drop the Currentl just flushes the DB - note that this will delete EVERYTHING on the redis instance
func (*Client) GetTagVals ¶ added in v1.0.0
Get the distinct tags indexed in a Tag field
func (*Client) IndexOptions ¶
func (i *Client) IndexOptions(opts IndexingOptions, docs ...Document) error
IndexOptions indexes multiple documents on the index, with optional Options passed to options
func (*Client) Info ¶
Info - Get information about the index. This can also be used to check if the index exists
func (*Client) MultiGet ¶ added in v0.9.0
MultiGet - Returns the full contents of multiple documents. Returns an array with exactly the same number of elements as the number of keys sent to the command. Each element in it is either an Document or nil if it was not found.
func (*Client) Search ¶
Search searches the index for the given query, and returns documents, the total number of results, or an error if something went wrong
func (*Client) SpellCheck ¶ added in v0.2.0
func (i *Client) SpellCheck(q *Query, s *SpellCheckOptions) (suggs []MisspelledTerm, total int, err error)
SpellCheck performs spelling correction on a query, returning suggestions for misspelled terms, the total number of results, or an error if something went wrong
type Document ¶
Document represents a single document to be indexed or returned from a query. Besides a score and id, the Properties are completely arbitrary
func NewDocument ¶
NewDocument creates a document with the specific id and score
func (*Document) EstimateSize ¶
func (*Document) SetPayload ¶
SetPayload Sets the document payload
type DocumentList ¶
type DocumentList []Document
DocumentList is used to sort documents by descending score
func (DocumentList) Len ¶
func (l DocumentList) Len() int
func (DocumentList) Less ¶
func (l DocumentList) Less(i, j int) bool
func (DocumentList) Swap ¶
func (l DocumentList) Swap(i, j int)
type Field ¶
Field represents a single field's Schema
func NewGeoField ¶ added in v1.0.0
NewGeoField creates a new geo field with the given name
func NewGeoFieldOptions ¶ added in v1.0.0
func NewGeoFieldOptions(name string, options GeoFieldOptions) Field
NewGeoFieldOptions creates a new geo field with the given name and additional options
func NewNumericField ¶
NewNumericField creates a new numeric field with the given name
func NewNumericFieldOptions ¶
func NewNumericFieldOptions(name string, options NumericFieldOptions) Field
NewNumericFieldOptions defines a numeric field with additional options
func NewSortableNumericField ¶
NewSortableNumericField creates a new numeric field with the given name and a sortable flag
func NewSortableTextField ¶
NewSortableTextField creates a text field with the sortable flag set
func NewTagField ¶
NewTagField creates a new text field with default options (separator: ,)
func NewTagFieldOptions ¶
func NewTagFieldOptions(name string, opts TagFieldOptions) Field
NewTagFieldOptions creates a new tag field with the given options
func NewTextField ¶
NewTextField creates a new text field with the given weight
func NewTextFieldOptions ¶
func NewTextFieldOptions(name string, opts TextFieldOptions) Field
NewTextFieldOptions creates a new text field with given options (weight/sortable)
type Flag ¶
type Flag uint64
Flag is a type for query flags
const ( // Treat the terms verbatim and do not perform expansion QueryVerbatim Flag = 0x1 // Do not load any content from the documents, return just IDs QueryNoContent Flag = 0x2 // Fetch document scores as well as IDs and fields QueryWithScores Flag = 0x4 // The query terms must appear in order in the document QueryInOrder Flag = 0x08 // Fetch document payloads as well as fields. See documentation for payloads on redisearch.io QueryWithPayloads Flag = 0x10 DefaultOffset = 0 DefaultNum = 10 )
Query Flags
type GeoFieldOptions ¶ added in v1.0.0
type GeoFieldOptions struct {
NoIndex bool
}
GeoFieldOptions Options for geo fields
type GeoFilterOptions ¶ added in v1.0.0
Filter the results to a given radius from lon and lat. Radius is given as a number and units
type GroupBy ¶ added in v0.2.0
GroupBy
func NewGroupBy ¶ added in v0.2.0
func NewGroupBy() *GroupBy
type HighlightOptions ¶
HighlightOptions represents the options to higlight specific document fields. See http://redisearch.io/Highlight/
type IndexInfo ¶
type IndexInfo struct { Schema Schema Name string `redis:"index_name"` DocCount uint64 `redis:"num_docs"` RecordCount uint64 `redis:"num_records"` TermCount uint64 `redis:"num_terms"` MaxDocID uint64 `redis:"max_doc_id"` InvertedIndexSizeMB float64 `redis:"inverted_sz_mb"` OffsetVectorSizeMB float64 `redis:"offset_vector_sz_mb"` DocTableSizeMB float64 `redis:"doc_table_size_mb"` KeyTableSizeMB float64 `redis:"key_table_size_mb"` RecordsPerDocAvg float64 `redis:"records_per_doc_avg"` BytesPerRecordAvg float64 `redis:"bytes_per_record_avg"` OffsetsPerTermAvg float64 `redis:"offsets_per_term_avg"` OffsetBitsPerTermAvg float64 `redis:"offset_bits_per_record_avg"` }
IndexInfo - Structure showing information about an existing index
type IndexingOptions ¶
type IndexingOptions struct { // If set, we use a stemmer for the supplied language during indexing. If set to "", we Default to English. Language string // If set to true, we will not save the actual document in the database and only index it. NoSave bool // If set, we will do an UPSERT style insertion - and delete an older version of the document if it exists. Replace bool // (only applicable with Replace): If set, you do not have to specify all fields for reindexing. Partial bool // Applicable only in conjunction with Replace and optionally Partial // Update the document only if a boolean expression applies to the document before the update ReplaceCondition string }
IndexingOptions represent the options for indexing a single document
type MisspelledSuggestion ¶ added in v0.2.0
MisspelledSuggestion is a single suggestion from the spelling corrections
func NewMisspelledSuggestion ¶ added in v0.2.0
func NewMisspelledSuggestion(term string, score float32) MisspelledSuggestion
NewMisspelledSuggestion creates a MisspelledSuggestion with the specific term and score
type MisspelledTerm ¶ added in v0.2.0
type MisspelledTerm struct { Term string // MisspelledSuggestionList is a sortable list of suggestions returned from an engine MisspelledSuggestionList []MisspelledSuggestion }
MisspelledTerm contains the misspelled term and a sortable list of suggestions returned from an engine
func NewMisspelledTerm ¶ added in v0.2.0
func NewMisspelledTerm(term string) MisspelledTerm
func (MisspelledTerm) Len ¶ added in v0.2.0
func (l MisspelledTerm) Len() int
func (MisspelledTerm) Less ¶ added in v0.2.0
func (l MisspelledTerm) Less(i, j int) bool
func (MisspelledTerm) Swap ¶ added in v0.2.0
func (l MisspelledTerm) Swap(i, j int)
type MultiError ¶
type MultiError []error
MultiError Represents one or more errors
func NewMultiError ¶
func NewMultiError(len int) MultiError
NewMultiError initializes a multierror with the given len, and all sub-errors set to nil
func (MultiError) Error ¶
func (e MultiError) Error() string
Error returns a string representation of the error, in this case it just chains all the sub errors if they are not nil
type MultiHostPool ¶
func NewMultiHostPool ¶
func NewMultiHostPool(hosts []string) *MultiHostPool
func (*MultiHostPool) Close ¶ added in v1.0.0
func (p *MultiHostPool) Close() (err error)
func (*MultiHostPool) Get ¶
func (p *MultiHostPool) Get() redis.Conn
type NumericFieldOptions ¶
NumericFieldOptions Options for numeric fields
type NumericFilterOptions ¶ added in v1.0.0
Limit results to those having numeric values ranging between min and max. min and max follow ZRANGE syntax, and can be -inf, +inf
type Options ¶
type Options struct { // If set, we will not save the documents contents, just index them, for fetching ids only. NoSave bool // If set, we avoid saving field bits for each term. // This saves memory, but does not allow filtering by specific fields. // This is an option that is applied and index level. NoFieldFlags bool // If set, we avoid saving the term frequencies in the index. // This saves memory but does not allow sorting based on the frequencies of a given term within the document. // This is an option that is applied and index level. NoFrequencies bool // If set, , we avoid saving the term offsets for documents. // This saves memory but does not allow exact searches or highlighting. Implies NOHL // This is an option that is applied and index level. NoOffsetVectors bool // Set the index with a custom stop-words list, to be ignored during indexing and search time // This is an option that is applied and index level. // If the list is nil the default stop-words list is used. // See https://oss.redislabs.com/redisearch/Stopwords.html#default_stop-word_list Stopwords []string // If set to true, creates a lightweight temporary index which will expire after the specified period of inactivity. // The internal idle timer is reset whenever the index is searched or added to. // Because such indexes are lightweight, you can create thousands of such indexes without negative performance implications. Temporary bool TemporaryPeriod int }
Options are flags passed to the the abstract Index call, which receives them as interface{}, allowing for implementation specific options
func NewOptions ¶ added in v1.0.1
func NewOptions() *Options
func (*Options) SetStopWords ¶ added in v1.0.1
Set the index with a custom stop-words list, to be ignored during indexing and search time This is an option that is applied and index level. If the list is nil the default stop-words list is used. See https://oss.redislabs.com/redisearch/Stopwords.html#default_stop-word_list
func (*Options) SetTemporary ¶ added in v1.0.1
If set to true, creates a lightweight temporary index which will expire after the specified period of inactivity. The internal idle timer is reset whenever the index is searched or added to. To enable the temporary index creation, use SetTemporaryPeriod(). This method should be preferably used for disabling the flag
func (*Options) SetTemporaryPeriod ¶ added in v1.0.1
If set to a positive integer, creates a lightweight temporary index which will expire after the specified period of inactivity (in seconds). The internal idle timer is reset whenever the index is searched or added to.
type Predicate ¶
func GreaterThan ¶
func GreaterThanEquals ¶
func LessThanEquals ¶
func NewPredicate ¶
type Projection ¶ added in v0.2.0
Projection
func NewProjection ¶ added in v0.2.0
func NewProjection(expression string, alias string) *Projection
func (Projection) Serialize ¶ added in v0.2.0
func (p Projection) Serialize() redis.Args
type Query ¶
type Query struct { Raw string Paging Paging Flags Flag Slop int Filters []Filter InKeys []string InFields []string ReturnFields []string Language string Expander string Scorer string Payload []byte SortBy *SortingKey HighlightOpts *HighlightOptions SummarizeOpts *SummaryOptions }
Query is a single search query and all its parameters and predicates
func NewQuery ¶
NewQuery creates a new query for a given index with the given search term. For currently the index parameter is ignored
func (*Query) Highlight ¶
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 ¶
Limit sets the paging offset and limit for the query you can use LIMIT 0 0 to count the number of documents in the resultset without actually returning them
func (*Query) SetExpander ¶
SetExpander sets a custom user query expander to be used
func (*Query) SetInFields ¶ added in v1.0.1
SetInFields sets the INFIELDS argument of the query - filter the results to ones appearing only in specific fields of the document
func (*Query) SetInKeys ¶
SetInKeys sets the INKEYS argument of the query - limiting the search to a given set of IDs
func (*Query) SetLanguage ¶
SetLanguage sets the query language, used by the stemmer to expand the query
func (*Query) SetPayload ¶
SetPayload sets a binary payload to the query, that can be used by custom scoring functions
func (*Query) SetReturnFields ¶
SetReturnFields sets the fields that should be returned from each result. By default we return everything
func (*Query) SetScorer ¶
SetScorer sets an alternative scoring function to be used. The only pre-compiled supported one at the moment is DISMAX
func (*Query) Summarize ¶
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 Reducer ¶ added in v0.2.0
type Reducer struct { Name GroupByReducers Alias string Args []string }
Reducer represents an index schema Schema, or how the index would treat documents sent to it.
func NewReducer ¶ added in v0.2.0
func NewReducer(name GroupByReducers, args []string) *Reducer
NewReducer creates a new Reducer object
func NewReducerAlias ¶ added in v0.2.0
func NewReducerAlias(name GroupByReducers, args []string, alias string) *Reducer
NewReducer creates a new Reducer object
func (*Reducer) SetName ¶ added in v0.2.0
func (r *Reducer) SetName(reducer GroupByReducers) *Reducer
type Schema ¶
Schema represents an index schema Schema, or how the index would treat documents sent to it.
type SingleHostPool ¶
func NewSingleHostPool ¶
func NewSingleHostPool(host string) *SingleHostPool
type SortingKey ¶
SortingKey represents the sorting option if the query needs to be sorted based on a sortable fields and not a ranking function. See http://redisearch.io/Sorting/
func NewSortingKeyDir ¶ added in v0.2.0
func NewSortingKeyDir(field string, ascending bool) *SortingKey
func (SortingKey) Serialize ¶ added in v0.2.0
func (s SortingKey) Serialize() redis.Args
type SpellCheckOptions ¶ added in v0.2.0
SpellCheckOptions are options which are passed when performing spelling correction on a query
func NewSpellCheckOptions ¶ added in v0.2.0
func NewSpellCheckOptions(distance int) *SpellCheckOptions
func NewSpellCheckOptionsDefaults ¶ added in v0.2.0
func NewSpellCheckOptionsDefaults() *SpellCheckOptions
func (*SpellCheckOptions) AddExclusionDict ¶ added in v0.2.0
func (s *SpellCheckOptions) AddExclusionDict(dictname string) *SpellCheckOptions
AddExclusionDict adds a custom dictionary named {dictname} to the exclusion list
func (*SpellCheckOptions) AddInclusionDict ¶ added in v0.2.0
func (s *SpellCheckOptions) AddInclusionDict(dictname string) *SpellCheckOptions
AddInclusionDict adds a custom dictionary named {dictname} to the inclusion list
func (*SpellCheckOptions) SetDistance ¶ added in v0.2.0
func (s *SpellCheckOptions) SetDistance(distance int) (*SpellCheckOptions, error)
SetDistance Sets the the maximal Levenshtein distance for spelling suggestions (default: 1, max: 4)
type SuggestOptions ¶
SuggestOptions are options which are passed when recieving suggestions from the Autocompleter
type Suggestion ¶
Suggestion is a single suggestion being added or received from the Autocompleter
func ProcessSugGetVals ¶ added in v0.9.0
func ProcessSugGetVals(vals []string, inc int, WithScores, WithPayloads bool) (ret []Suggestion)
type SuggestionList ¶
type SuggestionList []Suggestion
SuggestionList is a sortable list of suggestions returned from an engine
func (SuggestionList) Len ¶
func (l SuggestionList) Len() int
func (SuggestionList) Less ¶
func (l SuggestionList) Less(i, j int) bool
func (SuggestionList) Swap ¶
func (l SuggestionList) Swap(i, j int)
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/
type TagFieldOptions ¶
type TagFieldOptions struct { // Separator is the custom separator between tags. defaults to comma (,) Separator byte NoIndex bool Sortable bool }
TagFieldOptions options for indexing tag fields
type TextFieldOptions ¶
TextFieldOptions Options for text fields - weight and stemming enabled/disabled.