combinator

package
v0.0.0-...-b7c488f Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: MIT Imports: 23 Imported by: 3

Documentation

Overview

Package combinator contains methods for performing logical operations on queries.

Index

Constants

This section is empty.

Variables

View Source
var (
	// OrOperator combines documents using `OR`.
	OrOperator = orOperator{}
	// AndOperator combines documents using `AND`.
	AndOperator = andOperator{}
	// NotOperator combines documents using `NOT`.
	NotOperator = notOperator{}
)
View Source
var ErrCacheMiss = errors.New("cache miss error")

ErrCacheMiss indicates that a read did not fail, but the item was not present in the cache.

Functions

func BlockTransform

func BlockTransform(blockSize int) func(string) []string

BlockTransform determines how diskv should partition folders.

func HashCQR

func HashCQR(representation cqr.CommonQueryRepresentation) uint64

HashCQR creates a hash of the query.

func NewLogicalTree

func NewLogicalTree(query pipeline.Query, ss stats.StatisticsSource, seen QueryCacher) (LogicalTree, QueryCacher, error)

NewLogicalTree creates a new logical tree. If the operator of the query is unknown (i.e. it is not one of `or`, `and`, `not`, or an `adj` operator) the default operator will be `or`.

Note that once one tree has been constructed, the returned map can be used to save processing.

Types

type AdjAtom

type AdjAtom struct {
	Clause
}

AdjAtom is a special type of atom for adjacent queries.

func NewAdjAtom

func NewAdjAtom(query cqr.BooleanQuery) AdjAtom

NewAdjAtom creates a new adjacent atom.

func (AdjAtom) Documents

func (a AdjAtom) Documents(cache QueryCacher) Documents

Documents returns the documents retrieved by the adjacency operator.

func (AdjAtom) Query

Query returns the underlying query of the adjacency operator.

func (AdjAtom) String

func (a AdjAtom) String() string

String returns the query string.

type Atom

type Atom struct {
	Clause
	N float64
	R float64
}

Atom is the smallest possible component of a query.

func NewAtom

func NewAtom(keyword cqr.Keyword) Atom

NewAtom creates a new atom.

func (Atom) Documents

func (a Atom) Documents(cache QueryCacher) Documents

Documents returns the documents retrieved by the atom.

func (Atom) Query

Query returns the underlying query of the atom.

func (Atom) String

func (a Atom) String() string

String returns the query string.

type Clause

type Clause struct {
	Hash  uint64
	Query cqr.CommonQueryRepresentation
}

Clause is the most basic component of a logical tree.

type Combinator

type Combinator struct {
	Operator
	Clause
	Clauses []LogicalTreeNode
	N       float64
	R       float64
}

Combinator is an operator in a query.

func NewCombinator

func NewCombinator(query cqr.BooleanQuery, operator Operator, clauses ...LogicalTreeNode) Combinator

NewCombinator creates a new combinator.

func (Combinator) Documents

func (c Combinator) Documents(cache QueryCacher) Documents

Documents returns the documents retrieved by the combinator.

func (Combinator) Query

Query returns the underlying query of the combinator.

func (Combinator) String

func (c Combinator) String() string

String is the combinator name.

type DiskvQueryCache

type DiskvQueryCache struct {
	*diskv.Diskv
}

DiskvQueryCache caches results using diskv.

func (DiskvQueryCache) Get

Get looks up results from disk.

func (DiskvQueryCache) Set

Set caches results to disk.

type Document

type Document uint32

Document is a document that has been retrieved.

func (Document) String

func (d Document) String() string

String returns the string representation of the documents.

type Documents

type Documents []Document

Documents are a group of retrieved documents.

func (Documents) Len

func (d Documents) Len() int

func (Documents) Less

func (d Documents) Less(i, j int) bool

func (Documents) Results

func (d Documents) Results(query pipeline.Query, run string) trecresults.ResultList

Results converts the documents from the resulting logical operator tree into eval-compatible trec results.

func (Documents) Set

func (d Documents) Set() map[Document]struct{}

Set creates a map from a slice of documents.

func (Documents) Swap

func (d Documents) Swap(i, j int)

type FileQueryCache

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

FileQueryCache caches results in a flat-file format in a single directory. This cacher will be faster than diskv as it does not use gob encoding.

func (FileQueryCache) Get

Get looks up results from disk.

func (FileQueryCache) Set

Set caches results to disk.

type LogicalTree

type LogicalTree struct {
	Root LogicalTreeNode
	// contains filtered or unexported fields
}

LogicalTree can compute the number of documents retrieved for atomic components.

func NewShallowLogicalTree

func NewShallowLogicalTree(query pipeline.Query, s stats.StatisticsSource, relevant Documents) (LogicalTree, error)

func (LogicalTree) Documents

func (root LogicalTree) Documents(cache QueryCacher) Documents

Documents returns the documents that the tree (query) would return if executed.

func (LogicalTree) ToCQR

ToCQR creates a query backwards from a logical tree.

type LogicalTreeNode

type LogicalTreeNode interface {
	Query() cqr.CommonQueryRepresentation
	Documents(cache QueryCacher) Documents
	String() string
}

LogicalTreeNode is a node in a logical tree.

type MapQueryCache

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

MapQueryCache caches results to memory.

func (MapQueryCache) Get

Get looks up results in a map.

func (MapQueryCache) Set

Set caches results to a map.

type Operator

type Operator interface {
	Combine(clauses []LogicalTreeNode, cache QueryCacher) Documents
	String() string
}

Operator can combine different nodes of a tree together.

type QueryCacher

type QueryCacher interface {
	Get(query cqr.CommonQueryRepresentation) (Documents, error)
	Set(query cqr.CommonQueryRepresentation, docs Documents) error
}

QueryCacher models a way to cache (either persistent or not) queries and the documents they retrieve.

func NewDiskvQueryCache

func NewDiskvQueryCache(dv *diskv.Diskv) QueryCacher

NewDiskvQueryCache creates a new on-disk cache with the specified diskv parameters.

func NewFileQueryCache

func NewFileQueryCache(path string) QueryCacher

NewFileQueryCache creates a new disk-based file query cache.

func NewMapQueryCache

func NewMapQueryCache() QueryCacher

NewMapQueryCache creates a query cache out of a regular go map.

Jump to

Keyboard shortcuts

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