Build Status GoDoc

goreds is a Go port of tj/reds for Node.js



Currently reds strips stop words and applies the metaphone and porter stemmer algorithms to the remaining words before mapping the constants in Redis sets. For example the following text:

Tobi is a ferret and he only wants four dollars

Converts to the following constant map:

map[Tobi:TB ferret:FRT wants:WNTS four:FR dollars:DLRS]

This also means that phonetically similar words will match, for example "stefen", "stephen", "steven" and "stefan" all resolve to the constant "STFN". Reds takes this further and applies the porter stemming algorithm to "stem" words, for example "counts", and "counting" become "count".

Consider we have the following bodies of text:

Tobi really wants four dollars

For some reason tobi is always wanting four dollars

The following search query will then match both of these bodies, and "wanting", and "wants" both reduce to "want".

tobi wants four dollars


redis, _ := redis.DialURL("redis://localhost:6379")
search := goreds.NewClient(redis, "namespace")

// index some text and assign to their id
search.Index("example index text", "1")
search.Index("example text being indexed for the sake of this example", "2")
search.Index("example testing with a lot more text", "3")
search.Index("index some more sample text data", "4")

// remove an item from the search index

// query the search index that should match ids 1 and 4
ids, _ := search.Query("index text", goreds.AND)
// Output: [4 1]
Expand ▾ Collapse ▴





This section is empty.


This section is empty.


This section is empty.


type Client

type Client struct {
	Redis     redis.Conn
	Namespace string

    Client is a goreds client that uses a Redis client and Namespace to perform searches

    func NewClient

    func NewClient(redis redis.Conn, namespace string) *Client

      NewClient will create a new search client with the given redigo connection and namespace (defaults to "goreds"). You may create multiple clients with different namespaces for separate search indexes.

      [4 1]

      func (*Client) Index

      func (client *Client) Index(text, id string) error

        Index will store the `id` within the database and use the `text` as the searchable text

        func (*Client) Query

        func (client *Client) Query(text string, operator Operator) ([]string, error)

          Query performs a search against the database and returns a slice of ids that match

          func (*Client) Remove

          func (client *Client) Remove(id string) error

            Remove will delete the `id` from the database so it is not longer searchable

            type Operator

            type Operator string
            const (
            	AND Operator = "zinterstore"
            	OR  Operator = "zunionstore"

            Source Files


            Path Synopsis