MCPcopy Index your code
hub / github.com/RediSearch/redisearch-go

github.com/RediSearch/redisearch-go @v2.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.1.1 ↗ · + Follow
386 symbols 2,304 edges 31 files 189 documented · 49%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

license Integration Tests 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 AggregateQuery
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 SetConfigGetConfig

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Function 185
Method 135
Struct 54
TypeAlias 11
Interface 1

Languages

Go100%

Modules by API surface

redisearch/client.go39 symbols
redisearch/aggregate_test.go38 symbols
redisearch/aggregate.go35 symbols
redisearch/client_test.go34 symbols
redisearch/schema.go33 symbols
redisearch/query.go33 symbols
redisearch/spellcheck.go16 symbols
redisearch/redisearch_test.go16 symbols
redisearch/index.go16 symbols
redisearch/spellcheck_test.go15 symbols
redisearch/document.go14 symbols
redisearch/autocomplete.go11 symbols

For agents

$ claude mcp add redisearch-go \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page