Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
41 changes: 40 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,39 @@ jobs:
- 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 get
- 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 get
- 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 get
- run: make test

build_nightly: # test nightly with redisearch:edge
docker:
- image: circleci/golang:1.12
Expand All @@ -73,6 +106,9 @@ workflows:
jobs:
- build
- build-tls
- build-latest
- build-v16
- build-v14
nightly:
triggers:
- schedule:
Expand All @@ -83,4 +119,7 @@ workflows:
- master
jobs:
- build_nightly
- build-tls
- build-tls
- build-latest
- build-v16
- build-v14
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ examples: get
--tls-ca-cert-file $(TLS_CACERT) \
--host $(REDISEARCH_TEST_HOST)

test: get
fmt:
$(GOFMT) ./...

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

coverage: get test
Expand Down
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
62 changes: 57 additions & 5 deletions redisearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,57 @@ 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) {
// GetRediSearchVersion returns RediSearch version by issuing "MODULE LIST" command
// and iterating through the availabe modules up until "ft" is found as the name property
func (c *Client) GetRediSearchVersion() (version int64, err error) {
conn := c.pool.Get()
defer conn.Close()
var values []interface{}
var moduleInfo []interface{}
var moduleName string
values, err = redis.Values(conn.Do("MODULE", "LIST"))
if err != nil {
return
}
for _, rawModule := range values {
moduleInfo, err = redis.Values(rawModule, err)
if err != nil {
return
}
moduleName, err = redis.String(moduleInfo[1], err)
if err != nil {
return
}
if moduleName == "ft" {
version, err = redis.Int64(moduleInfo[3], err)
}
}
return
}

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

// 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, err)
}

// internal method
func (i *Client) indexWithDefinition(indexName string, schema *Schema, definition *IndexDefinition, errIn error) (err error) {
err = errIn
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...)
Expand Down Expand Up @@ -340,7 +382,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 +422,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 +603,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 Down Expand Up @@ -600,6 +650,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