Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ea41f88
Add schema add and MAXTEXTFIELD support
felixls Nov 28, 2019
1df27b3
Fix the problem that the parameters LANGUAGE is not supported in the …
Nov 28, 2019
5e9b094
[add] testing for the query serialize method
Dec 5, 2019
f0362cd
Merge pull request #29 from bingeng99/feature/language
filipecosta90 Dec 5, 2019
f05c46b
[add] added IF {condition} to FT.ADD API
filipecosta90 Dec 17, 2019
6df6eae
Merge pull request #33 from RediSearch/replace.partial
filipecosta90 Dec 17, 2019
b96444b
[add] support for FT.SUGLEN, FT.SUGDEL. Included default options for …
filipecosta90 Dec 17, 2019
fcc6707
[merge] merged with master
filipecosta90 Dec 17, 2019
db9fc01
[add] improved spellcheck coverage
filipecosta90 Dec 17, 2019
dd1a63a
[add] enable LOAD parameter on FT.AGGREGATE command
filipecosta90 Dec 24, 2019
14ebde9
Merge pull request #37 from RediSearch/ft.aggregate.load
filipecosta90 Dec 24, 2019
54ac477
[add] added supported commands table to Readme
filipecosta90 Jan 24, 2020
77d272d
Merge pull request #38 from RediSearch/documentation
filipecosta90 Jan 27, 2020
ff7fae8
Update client.go
gkorland Mar 4, 2020
5e0163d
move from garyburd to gomodule
gkorland Mar 4, 2020
35d3f5d
Fix build
gkorland Mar 4, 2020
9613a4f
Merge pull request #45 from RediSearch/redigo
gkorland Mar 4, 2020
2778128
fix bug aggregate and fix bug limit
Mar 30, 2020
0369d52
[add] extended tests for Paging serialize()
filipecosta90 Mar 30, 2020
5e45a0a
[add] extended coverage for document.go
filipecosta90 Mar 30, 2020
7c3434d
[add] added spellcheck test file
filipecosta90 Mar 30, 2020
6df0c36
[add] no breaking changes on autocompleter
filipecosta90 Mar 30, 2020
dc05944
[add] fixed conflicts
filipecosta90 Mar 30, 2020
e9ef654
[add] fixed merge conflicts and prunned code
filipecosta90 Mar 30, 2020
c07c79e
[add] prunning changes
filipecosta90 Mar 30, 2020
f8833ae
[add] prunning changes
filipecosta90 Mar 30, 2020
84903f5
[add] Updated Readme with new supported commands
filipecosta90 Mar 30, 2020
dc65c2d
[add] support for FT.GET and FT.MGET
filipecosta90 Mar 30, 2020
78cab8d
[fix] fixed TestClient_Get
filipecosta90 Mar 30, 2020
a198e9c
[add] add support for FT.DICTADD FT.DICTDEL and FT.DICTDUMP
filipecosta90 Mar 30, 2020
e97368c
[add] added support for FT.ALIASADD, FT.ALIASUPDATE, FT.ALIASDEL
filipecosta90 Mar 31, 2020
31029bc
[add] updated Readme with Alias supported commands
filipecosta90 Mar 31, 2020
e440655
Merge pull request #46 from mriskyp/fix_bug_redisearch
filipecosta90 Apr 1, 2020
2ad24bb
Merge branch 'master' of https://github.com/RediSearch/redisearch-go …
filipecosta90 Apr 1, 2020
5cfa76b
[add] added test for FT.AGGREGATE reply parsing. (quick refactoring i…
filipecosta90 Apr 1, 2020
b7769b1
Merge branch 'master' into ft.sug.refactor
filipecosta90 Apr 2, 2020
522e62a
Merge pull request #48 from RediSearch/extend.coverage
gkorland Apr 2, 2020
9e484b4
[add] added missing inline docs
filipecosta90 Apr 2, 2020
09c668e
Merge branch 'master' into ft.sug.refactor
filipecosta90 Apr 2, 2020
c5e3c09
[fix] fixed conflicts on test files
filipecosta90 Apr 2, 2020
f5e7755
[add] added missing inline documents for Single Document Indexing Opt…
filipecosta90 Apr 2, 2020
82d2f33
[fix] moved IndexingOptions( represent the options for indexing a sin…
filipecosta90 Apr 2, 2020
8e48e5d
Merge pull request #36 from RediSearch/ft.sug.refactor
gkorland Apr 2, 2020
9817666
Support FT.CONFIG command
dengliming Apr 4, 2020
910ef02
Merge pull request #50 from dengliming/master
filipecosta90 Apr 5, 2020
531d81d
Support FT.TAGVALS command
dengliming Apr 5, 2020
809e4da
Merge pull request #53 from dengliming/f_get_tagvals
filipecosta90 Apr 5, 2020
7ccd0b5
Update README.md (#54)
dengliming Apr 6, 2020
a595a0d
Shared pool among clients and fixed pool resources release (#51)
filipecosta90 Apr 7, 2020
76b1c66
Support FT.SYNADD FT.SYNUPDATE FT.SYNDUMP commands (#55)
dengliming Apr 10, 2020
b4cac87
Support FT.ADDHASH command (#62)
dengliming Apr 20, 2020
42408e1
NewSchema fix and extended testing for SerializeSchema (#58)
filipecosta90 Apr 21, 2020
216ad27
Support GeoField GEOFILTER FILTER (#63)
dengliming Apr 23, 2020
9e670fa
Update README.md
gkorland Apr 24, 2020
20b650b
Merge branch 'master' of https://github.com/Felixls/redisearch-go int…
filipecosta90 May 1, 2020
4ea6536
Merge branch 'Felixls-master'
filipecosta90 May 1, 2020
4a6e496
[add] updated CI rules
filipecosta90 May 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 95 additions & 14 deletions redisearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ type Options struct {
NoOffsetVectors bool

Stopwords []string

MaxTextFields int
}

// DefaultOptions represents the default options
var DefaultOptions = Options{
MaxTextFields: 32,
NoSave: false,
NoFieldFlags: false,
NoFrequencies: false,
Expand Down Expand Up @@ -68,6 +71,9 @@ func NewClient(addr, name string) *Client {
// CreateIndex configues the index and creates it on redis
func (i *Client) CreateIndex(s *Schema) error {
args := redis.Args{i.name}

args = append(args, "MAXTEXTFIELDS", fmt.Sprintf("%d", s.Options.MaxTextFields))

// Set flags based on options
if s.Options.NoFieldFlags {
args = append(args, "NOFIELDS")
Expand Down Expand Up @@ -159,6 +165,81 @@ func (i *Client) CreateIndex(s *Schema) error {
return err
}

// AddField Adds a new field to the index.
func (i *Client) AddField(f Field) error {
args := redis.Args{i.name}

args = append(args, "SCHEMA", "ADD")

switch f.Type {
case TextField:

args = append(args, f.Name, "TEXT")
if f.Options != nil {
opts, ok := f.Options.(TextFieldOptions)
if !ok {
return errors.New("Invalid text field options type")
}

if opts.Weight != 0 && opts.Weight != 1 {
args = append(args, "WEIGHT", opts.Weight)
}
if opts.NoStem {
args = append(args, "NOSTEM")
}

if opts.Sortable {
args = append(args, "SORTABLE")
}

if opts.NoIndex {
args = append(args, "NOINDEX")
}
}

case NumericField:
args = append(args, f.Name, "NUMERIC")
if f.Options != nil {
opts, ok := f.Options.(NumericFieldOptions)
if !ok {
return errors.New("Invalid numeric field options type")
}

if opts.Sortable {
args = append(args, "SORTABLE")
}
if opts.NoIndex {
args = append(args, "NOINDEX")
}
}
case TagField:
args = append(args, f.Name, "TAG")
if f.Options != nil {
opts, ok := f.Options.(TagFieldOptions)
if !ok {
return errors.New("Invalid tag field options type")
}
if opts.Separator != 0 {
args = append(args, "SEPARATOR", fmt.Sprintf("%c", opts.Separator))

}
if opts.Sortable {
args = append(args, "SORTABLE")
}
if opts.NoIndex {
args = append(args, "NOINDEX")
}
}
default:
return fmt.Errorf("Unsupported field type %v", f.Type)
}

conn := i.pool.Get()
defer conn.Close()
_, err := conn.Do("FT.ALTER", args...)
return err
}

// IndexingOptions represent the options for indexing a single document
type IndexingOptions struct {
Language string
Expand Down Expand Up @@ -361,15 +442,15 @@ func (i *Client) SpellCheck(q *Query, s *SpellCheckOptions) (suggs []MisspelledT
return
}
total = 0
suggs = make([]MisspelledTerm, 0 )
suggs = make([]MisspelledTerm, 0)

// Each misspelled term, in turn, is a 3-element array consisting of
// - the constant string "TERM" ( 3-element position 0 -- we dont use it )
// - the term itself ( 3-element position 1 )
// - an array of suggestions for spelling corrections ( 3-element position 2 )
termIdx := 1
suggIdx := 2
for i := 0; i < len(res); i ++ {
for i := 0; i < len(res); i++ {
var termArray []interface{} = nil
termArray, err = redis.Values(res[i], nil)
if err != nil {
Expand All @@ -390,40 +471,40 @@ func (i *Client) SpellCheck(q *Query, s *SpellCheckOptions) (suggs []MisspelledT
}

// Aggregate
func (i *Client) Aggregate( q *AggregateQuery ) ( aggregateReply [][]string, total int, err error) {
func (i *Client) Aggregate(q *AggregateQuery) (aggregateReply [][]string, total int, err error) {
conn := i.pool.Get()
defer conn.Close()
hasCursor := q.WithCursor
validCursor := q.CursorHasResults()
var res []interface{} = nil
if ! validCursor {
if !validCursor {
args := redis.Args{i.name}
args = append(args, q.Serialize()...)
res, err = redis.Values(conn.Do("FT.AGGREGATE", args...))
} else {
args := redis.Args{"READ", i.name, q.Cursor.Id}
res, err = redis.Values(conn.Do("FT.CURSOR", args... ))
res, err = redis.Values(conn.Do("FT.CURSOR", args...))
}
if err != nil {
return
}
// has no cursor
if ! hasCursor {
total = len(res)-1
if !hasCursor {
total = len(res) - 1
if total > 1 {
aggregateReply = ProcessAggResponse(res[1:] )
aggregateReply = ProcessAggResponse(res[1:])
}
// has cursor
// has cursor
} else {
var partialResults, err = redis.Values(res[0],nil)
var partialResults, err = redis.Values(res[0], nil)
if err != nil {
return aggregateReply,total,err
return aggregateReply, total, err
}
q.Cursor.Id, err = redis.Int(res[1],nil)
q.Cursor.Id, err = redis.Int(res[1], nil)
if err != nil {
return aggregateReply,total,err
return aggregateReply, total, err
}
total = len(partialResults)-1
total = len(partialResults) - 1
if total > 1 {
aggregateReply = ProcessAggResponse(partialResults[1:])
}
Expand Down