Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for RediSearch v2.0 Index Definition #81

Merged
merged 13 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
43 changes: 40 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- run:
name: Generate a root CA and a server certificate using redis helpers
command: |
git clone git://github.com/antirez/redis.git --branch 6.0.5
git clone git://github.com/antirez/redis.git --branch 6.0.6
cd redis
./utils/gen-test-certs.sh
cd ..
Expand Down Expand Up @@ -53,9 +53,41 @@ jobs:
- checkout
- run: make get
- run: make checkfmt
- run: make test
- run: make godoc_examples
- run: make coverage
- run: bash <(curl -s https://codecov.io/bash) -t ${CODECOV_TOKEN}

build-latest:
docker:
- image: circleci/golang:1.12
- image: redislabs/redisearch:latest

working_directory: /go/src/github.com/RediSearch/redisearch-go
steps:
- checkout
- run: make test

build-v16:
docker:
- image: circleci/golang:1.12
- image: redislabs/redisearch:1.6.13

working_directory: /go/src/github.com/RediSearch/redisearch-go
steps:
- checkout
- run: make test

build-v14:
docker:
- image: circleci/golang:1.12
- image: redislabs/redisearch:1.4.28

working_directory: /go/src/github.com/RediSearch/redisearch-go
steps:
- checkout
- run: make test

build_nightly: # test nightly with redisearch:edge
docker:
- image: circleci/golang:1.12
Expand All @@ -64,7 +96,6 @@ jobs:
working_directory: /go/src/github.com/RediSearch/redisearch-go
steps:
- checkout
- run: make get
- run: make test

workflows:
Expand All @@ -73,6 +104,9 @@ workflows:
jobs:
- build
- build-tls
- build-latest
- build-v16
- build-v14
nightly:
triggers:
- schedule:
Expand All @@ -83,4 +117,7 @@ workflows:
- master
jobs:
- build_nightly
- build-tls
- build-tls
- build-latest
- build-v16
- build-v14
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ examples: get
--tls-ca-cert-file $(TLS_CACERT) \
--host $(REDISEARCH_TEST_HOST)

test: get
fmt:
$(GOFMT) ./...
$(GOTEST) -race -covermode=atomic ./...

coverage: get test
$(GOTEST) -race -coverprofile=coverage.txt -covermode=atomic ./redisearch
godoc_examples: get fmt
$(GOTEST) -race -covermode=atomic -v ./redisearch

test: get fmt
$(GOTEST) -race -covermode=atomic -run "Test" -v ./redisearch

coverage: get
$(GOTEST) -race -coverprofile=coverage.txt -covermode=atomic -v ./redisearch

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ func ExampleClient() {
| :--- | ----: |
| [FT.CREATE](https://oss.redislabs.com/redisearch/Commands.html#ftcreate) | [CreateIndex](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Client.CreateIndex) |
| [FT.ADD](https://oss.redislabs.com/redisearch/Commands.html#ftadd) | [IndexOptions](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Client.IndexOptions) |
| [FT.ADDHASH](https://oss.redislabs.com/redisearch/Commands.html#ftaddhash) | [AddHash](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Client.AddHash) |
| [FT.ALTER](https://oss.redislabs.com/redisearch/Commands.html#ftalter) | [AddField](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Client.AddField) |
| [FT.ALIASADD](https://oss.redislabs.com/redisearch/Commands.html#ftaliasadd) | [AliasAdd](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Client.AliasAdd) |
| [FT.ALIASUPDATE](https://oss.redislabs.com/redisearch/Commands.html#ftaliasupdate) | [AliasUpdate](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Client.AliasUpdate) |
Expand All @@ -97,7 +96,6 @@ func ExampleClient() {
| [FT.SUGGET](https://oss.redislabs.com/redisearch/Commands.html#ftsugget) | [SuggestOpts](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Autocompleter.SuggestOpts) |
| [FT.SUGDEL](https://oss.redislabs.com/redisearch/Commands.html#ftsugdel) | [DeleteTerms](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Autocompleter.DeleteTerms) |
| [FT.SUGLEN](https://oss.redislabs.com/redisearch/Commands.html#ftsuglen) | [Autocompleter.Length](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Autocompleter.Length) |
| [FT.SYNADD](https://oss.redislabs.com/redisearch/Commands.html#ftsynadd) | [SynAdd](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Client.SynAdd) |
| [FT.SYNUPDATE](https://oss.redislabs.com/redisearch/Commands.html#ftsynupdate) | [SynUpdate](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Client.SynUpdate) |
| [FT.SYNDUMP](https://oss.redislabs.com/redisearch/Commands.html#ftsyndump) | [SynDump](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Client.SynDump) |
| [FT.SPELLCHECK](https://oss.redislabs.com/redisearch/Commands.html#ftspellcheck) | [SpellCheck](https://godoc.org/github.com/RediSearch/redisearch-go/redisearch#Client.SpellCheck) |
Expand Down
37 changes: 30 additions & 7 deletions redisearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,32 @@ func NewClientFromPool(pool *redis.Pool, name string) *Client {
return ret
}

// CreateIndex configues the index and creates it on redis
func (i *Client) CreateIndex(s *Schema) (err error) {
// CreateIndex configures the index and creates it on redis
func (i *Client) CreateIndex(schema *Schema) (err error) {
return i.indexWithDefinition(i.name, schema, nil)
}

// CreateIndexWithIndexDefinition configures the index and creates it on redis
// IndexDefinition is used to define a index definition for automatic indexing on Hash update
func (i *Client) CreateIndexWithIndexDefinition(schema *Schema, definition *IndexDefinition) (err error) {
return i.indexWithDefinition(i.name, schema, definition)
}

// internal method
func (i *Client) indexWithDefinition(indexName string, schema *Schema, definition *IndexDefinition) (err error) {
args := redis.Args{i.name}
if definition != nil {
args = definition.Serialize(args)
}
// Set flags based on options
args, err = SerializeSchema(s, args)
args, err = SerializeSchema(schema, args)
if err != nil {
return
}

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

// AddField Adds a new field to the index.
Expand Down Expand Up @@ -340,7 +353,7 @@ func (i *Client) Explain(q *Query) (string, error) {
return redis.String(conn.Do("FT.EXPLAIN", args...))
}

// Drop the Currentl just flushes the DB - note that this will delete EVERYTHING on the redis instance
// Deletes the index and all the keys associated with it.
func (i *Client) Drop() error {
conn := i.pool.Get()
defer conn.Close()
Expand Down Expand Up @@ -380,6 +393,13 @@ func (info *IndexInfo) setTarget(key string, value interface{}) error {
case reflect.Float64:
f, _ := redis.Float64(value, nil)
targetInfo.SetFloat(f)
case reflect.Bool:
f, _ := redis.Uint64(value, nil)
if f == 0 {
targetInfo.SetBool(false)
} else {
targetInfo.SetBool(true)
}
default:
panic("Tag set without handler")
}
Expand Down Expand Up @@ -554,6 +574,7 @@ func (i *Client) GetTagVals(index string, filedName string) ([]string, error) {
}

// Adds a synonym group.
// Deprecated: This function is not longer supported on RediSearch 2.0 and above, use SynUpdate instead
func (i *Client) SynAdd(indexName string, terms []string) (int64, error) {
conn := i.pool.Get()
defer conn.Close()
Expand All @@ -562,7 +583,7 @@ func (i *Client) SynAdd(indexName string, terms []string) (int64, error) {
return redis.Int64(conn.Do("FT.SYNADD", args...))
}

// Updates a synonym group.
// Updates a synonym group, with additional terms.
func (i *Client) SynUpdate(indexName string, synonymGroupId int64, terms []string) (string, error) {
conn := i.pool.Get()
defer conn.Close()
Expand Down Expand Up @@ -600,6 +621,8 @@ func (i *Client) SynDump(indexName string) (map[string][]int64, error) {
}

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