forked from RediSearch/RediSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for [TEMPORARY {seconds}] on FT.CREATE (RediSearch#70)
* support for [TEMPORARY {seconds}] on FT.CREATE
- Loading branch information
1 parent
51a0cb3
commit 69202df
Showing
8 changed files
with
273 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Go parameters | ||
GOCMD=go | ||
GOBUILD=$(GOCMD) build | ||
GOINSTALL=$(GOCMD) install | ||
GOCLEAN=$(GOCMD) clean | ||
GOTEST=$(GOCMD) test | ||
GOGET=$(GOCMD) get | ||
GOMOD=$(GOCMD) mod | ||
|
||
.PHONY: all test coverage | ||
all: test coverage | ||
|
||
get: | ||
$(GOGET) -t -v ./... | ||
|
||
examples: get | ||
$(GOBUILD) ./examples/quickstart/. | ||
$(GOBUILD) ./examples/temporary/. | ||
./quickstart > /dev/null | ||
|
||
test: get examples | ||
$(GOTEST) -race -covermode=atomic ./... | ||
|
||
coverage: get test | ||
$(GOTEST) -race -coverprofile=coverage.txt -covermode=atomic ./redisearch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/RediSearch/redisearch-go/redisearch" | ||
"log" | ||
"time" | ||
) | ||
|
||
/** | ||
* This demo should be updated in RediSearch.io if changed | ||
* Update at: https://github.com/RediSearch/RediSearch/blob/master/docs/go_client.md | ||
*/ | ||
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.IndexOptions(redisearch.DefaultIndexingOptions, 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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
"github.com/RediSearch/redisearch-go/redisearch" | ||
) | ||
|
||
/** | ||
* This demo demonstrates the usage of CreateIndex(), to create a lightweight temporary index that 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. | ||
*/ | ||
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", "myTemporaryIndex") | ||
|
||
// Create a schema with a temporary index with temporary period of 10s | ||
sc := redisearch.NewSchema(*redisearch.NewOptions().SetTemporaryPeriod(10)). | ||
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.IndexOptions(redisearch.DefaultIndexingOptions, doc); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
docs, total, err := c.Search(redisearch.NewQuery("hello world"). | ||
Limit(0, 2). | ||
SetReturnFields("title")) | ||
|
||
// Verify that the we're able to search on the temporary created index | ||
fmt.Println(docs[0].Id, docs[0].Properties["title"], total, err) | ||
// Output: doc1 Hello world 1 <nil> | ||
|
||
time.Sleep(15*time.Second) | ||
// Searching with limit and sorting | ||
_, err = c.Info() | ||
fmt.Println(err) | ||
// Output: Unknown Index name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package redisearch_test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/RediSearch/redisearch-go/redisearch" | ||
"log" | ||
"time" | ||
) | ||
|
||
// exemplifies the CreateIndex function with a temporary index specification | ||
func ExampleCreateIndex_temporary() { | ||
// Create a client. By default a client is schemaless | ||
// unless a schema is provided when creating the index | ||
c := redisearch.NewClient("localhost:6379", "myTemporaryIndex") | ||
|
||
// Create a schema with a temporary period of 60seconds | ||
sc := redisearch.NewSchema(*redisearch.NewOptions().SetTemporaryPeriod(10)). | ||
AddField(redisearch.NewTextField("body")). | ||
AddField(redisearch.NewTextFieldOptions("title", redisearch.TextFieldOptions{Weight: 5.0, Sortable: true})). | ||
AddField(redisearch.NewNumericField("date")) | ||
|
||
// 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.IndexOptions(redisearch.DefaultIndexingOptions, doc); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
docs, total, err := c.Search(redisearch.NewQuery("hello world"). | ||
Limit(0, 2). | ||
SetReturnFields("title")) | ||
|
||
// Verify that the we're able to search on the temporary created index | ||
fmt.Println(docs[0].Id, docs[0].Properties["title"], total, err) | ||
|
||
time.Sleep(15 * time.Second) | ||
// Searching with limit and sorting | ||
_, err = c.Info() | ||
fmt.Println(err) | ||
// Output: doc1 Hello world 1 <nil> | ||
// Unknown Index name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters