omnisearch

package
v2.273.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: Apache-2.0, MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSearch

func DefaultSearch(ctx context.Context, manager *initutil.Manager, parentsStr ...string) (<-chan *ResultReturn, error)

func NewRdvpConstructorFromPeerInfo

func NewRdvpConstructorFromPeerInfo(pis ...peer.AddrInfo) func(*zap.Logger, host.Host) (Provider, error)

func NewRdvpConstructorFromStr

func NewRdvpConstructorFromStr(addrs ...string) func(context.Context, *zap.Logger, host.Host) (Provider, error)

Types

type Configurator

type Configurator func(*coordinatorConfig) error

Configurator is used to configure the search engine.

func CAddEngine

func CAddEngine(engines ...interface{}) Configurator

CAddEngine will add engines to the Coordinator. It accept either instancied Engine or function returning an Engine. The function can have some params, in this case the provider logic will be used. The function must return an Engine and may return an error, if it returns an error it will be checked against nil and any non nil value will error.

func CAddParser

func CAddParser(parsers ...interface{}) Configurator

CAddParser adds some parser to the coordinator. It accept either instancied Parser or function returning a Parser. The function can have some params, in this case the provider logic will be used. The function must return a Parser and may return an error, if it returns an error it will be checked against nil and any non nil value will error.

func CAddProvider

func CAddProvider(provs ...interface{}) Configurator

CAddProvider will add providers to the config, from first to last. It accept either instancied Provider or function returning a Provider. The function can have some params, in this case the provider logic will be used. The function must return a Provider and may return an error, if it returns an error it will be checked against nil and any non nil value will error. The provider will be registered for each type only if the type is not yet registered.

func CMerge

func CMerge(cfgs ...Configurator) Configurator

CMerge merges multiple configurator, from first to last.

type Coordinator

type Coordinator interface {
	// Do execute a search with the currently available resources.
	// The chan will be closed once finished.
	Do(context.Context, ...interface{}) <-chan *ResultReturn
}

Coordinator executes searches

func NewCoordinator

func NewCoordinator(ctx context.Context, cfgs ...Configurator) (Coordinator, error)

NewCoordinatorWithBootstrap createsb a new Coordinator.

type Engine

type Engine interface {
	Informator
	// Search tries a search on the passed string.
	//
	// Search will be called in sync, if Search wants to fork it need to increment the waitGroup and
	// then set the field `decrement` in the ResultReturn to true (only set the last if you return multiple of them).
	// Or if the search was unsuccess full, decrement yourself.
	// You could also send a ResultReturn with a nil `Object` and decrement set (nil r.Object are just ignored).
	//
	// If you want to write to the channel you must do it concurrently.
	Search(context.Context, *sync.WaitGroup, chan<- *ResultReturn, *ResultReturn)
}

func NewEngine

func NewEngine(ctx context.Context, h host.Host, disc discovery.Discovery) (Engine, error)

type Informator

type Informator interface {
	Name() string
	// contains filtered or unexported methods
}

type Parser

type Parser interface {
	Informator
	// Parse tries to decode string
	// Return nil if weren't success full, else reflection will be used to know how to continue search.
	Parse(*ResultReturn) *ResultReturn
}

func NewParser

func NewParser() Parser

type Provider

type Provider interface {
	Informator
	Available() []reflect.Type
	Make(reflect.Type) (reflect.Value, error)
}

Provider can creates objects for the engines or other provider. Provider are only used at instantiation time.

func NewManagerFromManager

func NewManagerFromManager(m *initutil.Manager) Provider

func NewManagerFromNothing

func NewManagerFromNothing(ctx context.Context) (Provider, error)

func NewMirror

func NewMirror(objs ...interface{}) Provider

NewMirror creates a mirror provider. The mirror provider just reprovide the given objects.

type ResultReturn

type ResultReturn struct {
	Object    interface{}   // The thing actually found.
	Finder    Informator    // Reference to the object used to found it.
	Previous  *ResultReturn // Reference to the object with the search were triggered (is nil for parents).
	Decrement bool          // If true the Coordinator knows the search were a forked one and is now finished.
}

ResultReturn is a struct used to communicate metadata.

func (*ResultReturn) String

func (r *ResultReturn) String() string

Jump to

Keyboard shortcuts

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