Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 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
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
build: # test with redisearch:latest
build: # test with redisearch:edge
docker:
- image: circleci/golang:1.9
- image: redislabs/redisearch:latest
- image: redislabs/redisearch:edge

working_directory: /go/src/github.com/RediSearch/redisearch-go
steps:
- checkout
- run: go get -v -t -d ./...
- run: go test -v ./... -race -coverprofile=coverage.txt -covermode=atomic
- run: make get
- run: make coverage
- run: bash <(curl -s https://codecov.io/bash) -t ${CODECOV_TOKEN}

build_nightly: # test nightly with redisearch:edge
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
!.gitignore
!.circleci/config.yml
!/tests/*.bz2
!Makefile
25 changes: 25 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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/.
./quickstart > /dev/null

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

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

47 changes: 47 additions & 0 deletions examples/quickstart/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"fmt"
"github.com/RediSearch/redisearch-go/redisearch"
"log"
"time"
)

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>
}