redisearch-go

Go client for RediSearch

Github stars Tracking Chart

license
CircleCI
GitHub issues
Codecov
Go Report Card
GoDoc

RediSearch Go Client

Mailing List
Gitter

Go client for RediSearch, based on redigo.

Installing

go get github.com/RediSearch/redisearch-go/redisearch

Usage Example

package main 
import (
	"fmt"
	"log"
	"time"

	"github.com/RediSearch/redisearch-go/redisearch"
)

func ExampleClient() {

	// 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.Index([]redisearch.Document{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>
}

Main metrics

Overview
Name With OwnerRediSearch/redisearch-go
Primary LanguageGo
Program languageGo (Language Count: 3)
Platform
License:BSD 3-Clause "New" or "Revised" License
所有者活动
Created At2017-07-26 19:14:15
Pushed At2024-07-01 07:54:04
Last Commit At2022-09-01 09:57:49
Release Count14
Last Release Namev2.1.1 (Posted on )
First Release Namev0.1.0 (Posted on )
用户参与
Stargazers Count312
Watchers Count8
Fork Count68
Commits Count214
Has Issues Enabled
Issues Count76
Issue Open Count15
Pull Requests Count90
Pull Requests Open Count11
Pull Requests Close Count16
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private