index

package
v0.0.0-...-6217932 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2016 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

The index package implements a distributed search index.

It is basically a simple reverse document index, implemented as a PartitionedService, which keeps the entire database in-memory (and occasionally checkpoints to disk).

The query engine is not particularly clever or efficient, and the query expression language is rudimental, but the implementation is very simple and straightforward. And, of course, the entire service can be replaced by anything that implements the Index interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	IndexPmapFile = config.String("index_pmap", "/etc/djrandom/part-index.json", "Index partition map file")
)

Functions

func NewPartitionMapFromConfig

func NewPartitionMapFromConfig() *partition.PartitionMap

func RegisterService

func RegisterService(is *IndexService)

Types

type AddDocRequest

type AddDocRequest struct {
	DocId api.SongID
	Doc   api.Document
}

type DeleteDocRequest

type DeleteDocRequest struct {
	DocId api.SongID
}

type DeleteDocResponse

type DeleteDocResponse struct{}

type Index

type Index struct {
	Name string
	M    map[string]api.SongSet
}

Index is an index for a single attribute. Each key can have multiple values.

func NewIndex

func NewIndex(name string) *Index

func (*Index) Add

func (i *Index) Add(key string, id api.SongID)

Add a key/value pair to the index.

func (*Index) Discard

func (i *Index) Discard(key string, id api.SongID)

Discard a key from the index.

func (*Index) Get

func (i *Index) Get(key string) (api.SongSet, bool)

Get returns all values for key.

type IndexClient

type IndexClient struct {
	P *partition.PartitionMap
	// contains filtered or unexported fields
}

IndexClient is the distributed index client stub.

func NewIndexClient

func NewIndexClient(pmap *partition.PartitionMap) *IndexClient

func NewIndexClientFromConfig

func NewIndexClientFromConfig() *IndexClient

func (*IndexClient) AddDoc

func (ic *IndexClient) AddDoc(id api.SongID, doc api.Document) error

AddDoc adds a Document to the index.

func (*IndexClient) DeleteDoc

func (ic *IndexClient) DeleteDoc(id api.SongID) error

DeleteDoc removes a document from the index, given its ID.

func (*IndexClient) Scan

func (ic *IndexClient) Scan() []api.SongID

Scan returns a list of all the document IDs contained in the index (warning: potentially a very large list!).

func (*IndexClient) Search

func (ic *IndexClient) Search(query string) api.SongSet

Search runs a query against the index and returns a set of document IDs.

type IndexService

type IndexService struct {
	partition.PartitionedServiceBase

	// The in-memory multi-index object.
	Index *MultiIndex

	// Client for rebalancing.
	Client *IndexClient
	// contains filtered or unexported fields
}

func NewIndexService

func NewIndexService(stateFile string, pmap *partition.PartitionMap, selfTarget string) *IndexService

func (*IndexService) Move

func (is *IndexService) Move(key string) error

func (*IndexService) Scan

func (is *IndexService) Scan() <-chan string

func (*IndexService) Stop

func (is *IndexService) Stop()

type IndexServiceRPC

type IndexServiceRPC struct {
	// contains filtered or unexported fields
}

Just a wrapper that only exposes RPC methods.

func (*IndexServiceRPC) AddDoc

func (isrpc *IndexServiceRPC) AddDoc(req *AddDocRequest, resp *bool) error

func (*IndexServiceRPC) DeleteDoc

func (isrpc *IndexServiceRPC) DeleteDoc(req *DeleteDocRequest, resp *DeleteDocResponse) error

func (*IndexServiceRPC) Scan

func (isrpc *IndexServiceRPC) Scan(req *ScanRequest, resp *ScanResponse) error

func (*IndexServiceRPC) Search

func (isrpc *IndexServiceRPC) Search(req *SearchRequest, resp *SearchResponse) error

type MultiIndex

type MultiIndex struct {
	// The various indexes we built.
	Indexes map[string]*Index

	// The reverse docId -> values map which we're going to use to
	// remove documents from the index.
	D map[api.SongID]api.Document
	// contains filtered or unexported fields
}

func LoadMultiIndex

func LoadMultiIndex(path string) (*MultiIndex, error)

func NewMultiIndex

func NewMultiIndex() *MultiIndex

func (*MultiIndex) AddDoc

func (is *MultiIndex) AddDoc(id api.SongID, doc api.Document) error

AddDoc adds a document to the index.

func (*MultiIndex) DeleteDoc

func (is *MultiIndex) DeleteDoc(id api.SongID)

DeleteDoc removes a document from the index.

func (*MultiIndex) GetDocIds

func (is *MultiIndex) GetDocIds() []api.SongID

GetDocIds returns the list of unique document IDs in the index.

func (*MultiIndex) Lookup

func (is *MultiIndex) Lookup(key string, value string) api.SongSet

Lookup performs a point lookup in the index, returns a list of document IDs.

func (*MultiIndex) Save

func (is *MultiIndex) Save(path string) error

func (*MultiIndex) Scan

func (is *MultiIndex) Scan(out chan api.SongID)

Scan outputs all document IDs to the given channel.

func (*MultiIndex) Search

func (is *MultiIndex) Search(query string) api.SongSet

Search parses and executes a query. It returns the list of matching document IDs.

type QueryAstNode

type QueryAstNode interface {
	Eval(QueryIndex) api.SongSet
	String() string
}

Query AST.

func NewQueryAndNode

func NewQueryAndNode(args []QueryAstNode) QueryAstNode

func NewQueryOrNode

func NewQueryOrNode(args []QueryAstNode) QueryAstNode

func NewQuerySearchNode

func NewQuerySearchNode(key string, value string) QueryAstNode

func NewQuerySearchNodeOnManyKeys

func NewQuerySearchNodeOnManyKeys(keys []string, value string) QueryAstNode

func StringToQuery

func StringToQuery(s string) QueryAstNode

StringToQuery parses a query string and builds a search query.

type QueryIndex

type QueryIndex interface {
	Lookup(key, value string) api.SongSet
}

Interface from the index implementation to the query engine.

type ScanRequest

type ScanRequest struct{}

type ScanResponse

type ScanResponse struct {
	DocIds []api.SongID
}

type SearchRequest

type SearchRequest struct {
	Query string
}

type SearchResponse

type SearchResponse struct {
	Results api.SongSet
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL