GithubHelp home page GithubHelp logo

isabella232 / redisearch-go Goto Github PK

View Code? Open in Web Editor NEW

This project forked from redisearch/redisearch-go

0.0 0.0 0.0 2.49 MB

Go client for RediSearch

Home Page: https://redisearch.io

License: BSD 3-Clause "New" or "Revised" License

Go 99.23% Shell 0.07% Makefile 0.70%

redisearch-go's Introduction

license CircleCI GitHub issues Codecov Go Report Card GoDoc Total alerts

RediSearch Go Client

Forum Discord

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

Supported RediSearch Commands

Command Recommended API and godoc
FT.CREATE CreateIndex
FT.ADD IndexOptions
FT.ALTER AddField
FT.ALIASADD AliasAdd
FT.ALIASUPDATE AliasUpdate
FT.ALIASDEL AliasDel
FT.INFO Info
FT.SEARCH Search
FT.AGGREGATE Aggregate
FT.CURSOR Aggregate + (*WithCursor option set to True)
FT.EXPLAIN Explain
FT.DEL DeleteDocument
FT.GET Get
FT.MGET MultiGet
FT.DROP Drop
FT.TAGVALS GetTagVals
FT.SUGADD AddTerms
FT.SUGGET SuggestOpts
FT.SUGDEL DeleteTerms
FT.SUGLEN Autocompleter.Length
FT.SYNUPDATE SynUpdate
FT.SYNDUMP SynDump
FT.SPELLCHECK SpellCheck
FT.DICTADD DictAdd
FT.DICTDEL DictDel
FT.DICTDUMP DictDump
FT.CONFIG SetConfigใ€GetConfig

redisearch-go's People

Contributors

aldidana avatar dengliming avatar dvirsky avatar felixls avatar filipecosta90 avatar gkorland avatar is-a-gamer avatar itamarhaber avatar joshuaray avatar mibes avatar mibes404 avatar mnunberg avatar rokane avatar tropicalpenguin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.