Skip to content

Commit bd1fa60

Browse files
documentations (#124)
1 parent bd0b1c1 commit bd1fa60

File tree

7 files changed

+59
-36
lines changed

7 files changed

+59
-36
lines changed

redisearch/aggregate.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import (
77
"reflect"
88
)
99

10-
// Projection
10+
// Projection - Apply a 1-to-1 transformation on one or more properties,
11+
// and either store the result as a new property down the pipeline, or
12+
// replace any property using this transformation. Expression is an expression
13+
// that can be used to perform arithmetic operations on numeric properties,
14+
// or functions that can be applied on properties depending on their types,
15+
// or any combination thereof.
1116
type Projection struct {
1217
Expression string
1318
Alias string
@@ -66,13 +71,16 @@ func (c Cursor) Serialize() redis.Args {
6671
return args
6772
}
6873

69-
// GroupBy
74+
//GroupBy groups the results in the pipeline based on one or more properties.
75+
//Each group should have at least one reducer, a function that handles the group
76+
//entries, either counting them, or performing multiple aggregate operations.
7077
type GroupBy struct {
7178
Fields []string
7279
Reducers []Reducer
7380
Paging *Paging
7481
}
7582

83+
// NewGroupBy creates a new GroupBy object
7684
func NewGroupBy() *GroupBy {
7785
return &GroupBy{
7886
Fields: make([]string, 0),
@@ -81,6 +89,7 @@ func NewGroupBy() *GroupBy {
8189
}
8290
}
8391

92+
// AddFields to the group. Can be single string or list of strings.
8493
func (g *GroupBy) AddFields(fields interface{}) *GroupBy {
8594
switch fields.(type) {
8695
case string:
@@ -93,11 +102,13 @@ func (g *GroupBy) AddFields(fields interface{}) *GroupBy {
93102
return g
94103
}
95104

105+
// Reduce adds reducer to the group's list
96106
func (g *GroupBy) Reduce(reducer Reducer) *GroupBy {
97107
g.Reducers = append(g.Reducers, reducer)
98108
return g
99109
}
100110

111+
// Limit adds Paging to the GroupBy object
101112
func (g *GroupBy) Limit(offset int, num int) *GroupBy {
102113
g.Paging = NewPaging(offset, num)
103114
return g
@@ -140,6 +151,7 @@ func NewAggregateQuery() *AggregateQuery {
140151
}
141152
}
142153

154+
// SetQuery sets the query to the AggregateQuery
143155
func (a *AggregateQuery) SetQuery(query *Query) *AggregateQuery {
144156
a.Query = query
145157
return a
@@ -150,11 +162,14 @@ func (a *AggregateQuery) SetWithSchema(value bool) *AggregateQuery {
150162
return a
151163
}
152164

165+
// SetVerbatim - If set, we do not try to use stemming for query expansion but search
166+
// the query terms verbatim.
153167
func (a *AggregateQuery) SetVerbatim(value bool) *AggregateQuery {
154168
a.Verbatim = value
155169
return a
156170
}
157171

172+
// SetMax is used to optimized sorting, by sorting only for the n-largest elements
158173
func (a *AggregateQuery) SetMax(value int) *AggregateQuery {
159174
a.Max = value
160175
return a
@@ -174,13 +189,13 @@ func (a *AggregateQuery) CursorHasResults() (res bool) {
174189
return
175190
}
176191

177-
//Adds a APPLY clause to the aggregate plan
192+
//Apply a 1-to-1 transformation on some property
178193
func (a *AggregateQuery) Apply(expression Projection) *AggregateQuery {
179194
a.AggregatePlan = a.AggregatePlan.AddFlat(expression.Serialize())
180195
return a
181196
}
182197

183-
//Sets the limit for the initial pool of results from the query.
198+
//Limit the number of results to return just num results starting at index offset (zero-based).
184199
func (a *AggregateQuery) Limit(offset int, num int) *AggregateQuery {
185200
a.Paging = NewPaging(offset, num)
186201
return a
@@ -219,7 +234,8 @@ func (a *AggregateQuery) SortBy(SortByProperties []SortingKey) *AggregateQuery {
219234
return a
220235
}
221236

222-
//Specify filters to filter the results using predicates relating to values in the result set.
237+
//Filter the results using predicate expressions relating to values in each result.
238+
//They are is applied post-query and relate to the current state of the pipeline.
223239
func (a *AggregateQuery) Filter(expression string) *AggregateQuery {
224240
a.AggregatePlan = a.AggregatePlan.Add("FILTER", expression)
225241
//a.Filters = append(a.Filters, expression)
@@ -241,7 +257,6 @@ func (q AggregateQuery) Serialize() redis.Args {
241257
if q.Verbatim {
242258
args = args.Add("VERBATIM")
243259
}
244-
245260
// WITHCURSOR
246261
if q.WithCursor {
247262
args = args.AddFlat(q.Cursor.Serialize())

redisearch/autocomplete.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (a *Autocompleter) AddTerms(terms ...Suggestion) error {
6868
return nil
6969
}
7070

71-
// AddTerms pushes new term suggestions to the index
71+
// DeleteTerms deletes term suggestions from the index
7272
func (a *Autocompleter) DeleteTerms(terms ...Suggestion) error {
7373
conn := a.pool.Get()
7474
defer conn.Close()
@@ -94,7 +94,7 @@ func (a *Autocompleter) DeleteTerms(terms ...Suggestion) error {
9494
return nil
9595
}
9696

97-
// AddTerms pushes new term suggestions to the index
97+
// Length gets the size of the suggestion
9898
func (a *Autocompleter) Length() (len int64, err error) {
9999
conn := a.pool.Get()
100100
defer conn.Close()
@@ -128,8 +128,8 @@ func (a *Autocompleter) Suggest(prefix string, num int, fuzzy bool) (ret []Sugge
128128

129129
// SuggestOpts gets completion suggestions from the Autocompleter dictionary to the given prefix.
130130
// SuggestOptions are passed allowing you specify if the returned values contain a payload, and scores.
131-
// If SuggestOptions.Fuzzy is set, we also complete for prefixes that are in 1 Levenshtein distance from the
132-
// given prefix
131+
// If SuggestOptions.Fuzzy is set, we also complete for prefixes that are in 1 Levenshtein distance
132+
// from the given prefix
133133
func (a *Autocompleter) SuggestOpts(prefix string, opts SuggestOptions) (ret []Suggestion, err error) {
134134
conn := a.pool.Get()
135135
defer conn.Close()

redisearch/client.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,10 @@ func (i *Client) Search(q *Query) (docs []Document, total int, err error) {
126126
payloadIdx = skip
127127
skip++
128128
}
129-
130129
if q.Flags&QueryNoContent == 0 {
131130
fieldsIdx = skip
132131
skip++
133132
}
134-
135133
if len(res) > skip {
136134
for i := 1; i < len(res); i += skip {
137135

@@ -145,7 +143,8 @@ func (i *Client) Search(q *Query) (docs []Document, total int, err error) {
145143
return
146144
}
147145

148-
// Adds an alias to an index.
146+
// AliasAdd adds an alias to an index.
147+
// Indexes can have more than one alias, though an alias cannot refer to another alias.
149148
func (i *Client) AliasAdd(name string) (err error) {
150149
conn := i.pool.Get()
151150
defer conn.Close()
@@ -154,7 +153,7 @@ func (i *Client) AliasAdd(name string) (err error) {
154153
return
155154
}
156155

157-
// Deletes an alias to an index.
156+
// AliasDel deletes an alias from index.
158157
func (i *Client) AliasDel(name string) (err error) {
159158
conn := i.pool.Get()
160159
defer conn.Close()
@@ -163,7 +162,9 @@ func (i *Client) AliasDel(name string) (err error) {
163162
return
164163
}
165164

166-
// Deletes an alias to an index.
165+
// AliasUpdate differs from the AliasAdd in that it will remove the alias association with
166+
// a previous index, if any. AliasAdd will fail, on the other hand, if the alias is already
167+
// associated with another index.
167168
func (i *Client) AliasUpdate(name string) (err error) {
168169
conn := i.pool.Get()
169170
defer conn.Close()
@@ -172,7 +173,7 @@ func (i *Client) AliasUpdate(name string) (err error) {
172173
return
173174
}
174175

175-
// Adds terms to a dictionary.
176+
// DictAdd adds terms to a dictionary.
176177
func (i *Client) DictAdd(dictionaryName string, terms []string) (newTerms int, err error) {
177178
conn := i.pool.Get()
178179
defer conn.Close()
@@ -182,7 +183,7 @@ func (i *Client) DictAdd(dictionaryName string, terms []string) (newTerms int, e
182183
return
183184
}
184185

185-
// Deletes terms from a dictionary
186+
// DictDel deletes terms from a dictionary
186187
func (i *Client) DictDel(dictionaryName string, terms []string) (deletedTerms int, err error) {
187188
conn := i.pool.Get()
188189
defer conn.Close()
@@ -192,7 +193,7 @@ func (i *Client) DictDel(dictionaryName string, terms []string) (deletedTerms in
192193
return
193194
}
194195

195-
// Dumps all terms in the given dictionary.
196+
// DictDump dumps all terms in the given dictionary.
196197
func (i *Client) DictDump(dictionaryName string) (terms []string, err error) {
197198
conn := i.pool.Get()
198199
defer conn.Close()
@@ -336,14 +337,12 @@ func (i *Client) MultiGet(documentIds []string) (docs []*Document, err error) {
336337
} else {
337338
docs[i] = nil
338339
}
339-
340340
}
341-
342341
}
343342
return
344343
}
345344

346-
// Explain Return a textual string explaining the query
345+
// Explain Return a textual string explaining the query (execution plan)
347346
func (i *Client) Explain(q *Query) (string, error) {
348347
conn := i.pool.Get()
349348
defer conn.Close()
@@ -354,22 +353,21 @@ func (i *Client) Explain(q *Query) (string, error) {
354353
return redis.String(conn.Do("FT.EXPLAIN", args...))
355354
}
356355

357-
// Deletes the index and all the keys associated with it.
356+
// Drop deletes the index and all the keys associated with it.
358357
func (i *Client) Drop() error {
359358
conn := i.pool.Get()
360359
defer conn.Close()
361360

362361
_, err := conn.Do("FT.DROP", i.name)
363362
return err
364-
365363
}
366364

367365
// Deletes the secondary index and optionally the associated hashes
368366
//
369367
// Available since RediSearch 2.0.
370368
//
371-
// By default, DropIndex() which is a wrapper for RediSearch FT.DROPINDEX does not delete the document hashes associated with the index.
372-
// Setting the argument deleteDocuments to true deletes the hashes as well.
369+
// By default, DropIndex() which is a wrapper for RediSearch FT.DROPINDEX does not delete the document
370+
// hashes associated with the index. Setting the argument deleteDocuments to true deletes the hashes as well.
373371
func (i *Client) DropIndex(deleteDocuments bool) error {
374372
conn := i.pool.Get()
375373
defer conn.Close()
@@ -389,7 +387,7 @@ func (i *Client) Delete(docId string, deleteDocument bool) (err error) {
389387
return i.delDoc(docId, deleteDocument)
390388
}
391389

392-
// Delete the document from the index and also delete the HASH key in which the document is stored
390+
// DeleteDocument delete the document from the index and also delete the HASH key in which the document is stored
393391
func (i *Client) DeleteDocument(docId string) (err error) {
394392
return i.delDoc(docId, true)
395393
}
@@ -406,6 +404,7 @@ func (i *Client) delDoc(docId string, deleteDocument bool) (err error) {
406404
return
407405
}
408406

407+
// Internal method to be used by Info()
409408
func (info *IndexInfo) setTarget(key string, value interface{}) error {
410409
v := reflect.ValueOf(info).Elem()
411410
for i := 0; i < v.NumField(); i++ {
@@ -602,8 +601,8 @@ func (i *Client) GetTagVals(index string, filedName string) ([]string, error) {
602601
return redis.Strings(conn.Do("FT.TAGVALS", args...))
603602
}
604603

605-
// Adds a synonym group.
606-
// Deprecated: This function is not longer supported on RediSearch 2.0 and above, use SynUpdate instead
604+
// SynAdd adds a synonym group.
605+
// Deprecated: This function is not longer supported on RediSearch 2.0 and above, use SynUpdate instead
607606
func (i *Client) SynAdd(indexName string, terms []string) (int64, error) {
608607
conn := i.pool.Get()
609608
defer conn.Close()
@@ -612,7 +611,7 @@ func (i *Client) SynAdd(indexName string, terms []string) (int64, error) {
612611
return redis.Int64(conn.Do("FT.SYNADD", args...))
613612
}
614613

615-
// Updates a synonym group, with additional terms.
614+
// SynUpdate updates a synonym group, with additional terms.
616615
func (i *Client) SynUpdate(indexName string, synonymGroupId int64, terms []string) (string, error) {
617616
conn := i.pool.Get()
618617
defer conn.Close()
@@ -621,7 +620,7 @@ func (i *Client) SynUpdate(indexName string, synonymGroupId int64, terms []strin
621620
return redis.String(conn.Do("FT.SYNUPDATE", args...))
622621
}
623622

624-
// Dumps the contents of a synonym group.
623+
// SynDump dumps the contents of a synonym group.
625624
func (i *Client) SynDump(indexName string) (map[string][]int64, error) {
626625
conn := i.pool.Get()
627626
defer conn.Close()
@@ -650,7 +649,7 @@ func (i *Client) SynDump(indexName string) (map[string][]int64, error) {
650649
}
651650

652651
// Adds a document to the index from an existing HASH key in Redis.
653-
// Deprecated: This function is not longer supported on RediSearch 2.0 and above, use HSET instead
652+
// Deprecated: This function is not longer supported on RediSearch 2.0 and above, use HSET instead
654653
// See the example ExampleClient_CreateIndexWithIndexDefinition for a deeper understanding on how to move towards using hashes on your application
655654
func (i *Client) AddHash(docId string, score float32, language string, replace bool) (string, error) {
656655
conn := i.pool.Get()

redisearch/document.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ func EscapeTextFileString(value string) string {
8686
return value
8787
}
8888

89-
// convert the result from a redis query to a proper Document object
89+
// internal function
90+
// loadDocument convert the result from a redis query to a proper Document object
9091
func loadDocument(arr []interface{}, idIdx, scoreIdx, payloadIdx, fieldsIdx int) (Document, error) {
9192

9293
var score float64 = 1
@@ -111,7 +112,8 @@ func loadDocument(arr []interface{}, idIdx, scoreIdx, payloadIdx, fieldsIdx int)
111112
return doc, nil
112113
}
113114

114-
// SetPayload Sets the document payload
115+
// internal function used by loadDocument()
116+
// loadFields loads the fields of the document
115117
func (d *Document) loadFields(lst []interface{}) *Document {
116118
for i := 0; i < len(lst); i += 2 {
117119
var prop string
@@ -137,7 +139,10 @@ func (d *Document) loadFields(lst []interface{}) *Document {
137139
// DocumentList is used to sort documents by descending score
138140
type DocumentList []Document
139141

140-
func (l DocumentList) Len() int { return len(l) }
142+
// Len returns the length of the DocumentList
143+
func (l DocumentList) Len() int { return len(l) }
144+
145+
// Swap two documents in the list by their index
141146
func (l DocumentList) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
142147
func (l DocumentList) Less(i, j int) bool { return l[i].Score > l[j].Score } //reverse sorting
143148

redisearch/index.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212
JSON
1313
)
1414

15+
// Parse IndexType enum to string
1516
func (it IndexType) String() string {
1617
return [...]string{"HASH", "JSON"}[it]
1718
}

redisearch/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type SummaryOptions struct {
7373
Separator string // default "..."
7474
}
7575

76-
// Query is a single search query and all its parameters and predicates
76+
// Query is a single search query containing all its parameters and predicates
7777
type Query struct {
7878
Raw string
7979

@@ -243,7 +243,7 @@ func appendNumArgs(num float64, exclude bool, args redis.Args) redis.Args {
243243
return append(args, num)
244244
}
245245

246-
// AddFilter adds a filter to the query
246+
// AddFilter adds a filter to the query.
247247
func (q *Query) AddFilter(f Filter) *Query {
248248
if q.Filters == nil {
249249
q.Filters = []Filter{}

redisearch/spellcheck.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ func NewMisspelledTerm(term string) MisspelledTerm {
9393
}
9494
}
9595

96+
// Len returns the length of the MisspelledSuggestionList
9697
func (l MisspelledTerm) Len() int { return len(l.MisspelledSuggestionList) }
98+
99+
// Swap two suggestions in the list
97100
func (l MisspelledTerm) Swap(i, j int) {
98101
maxLen := len(l.MisspelledSuggestionList)
99102
if i < maxLen && j < maxLen {

0 commit comments

Comments
 (0)