search

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2016 License: Apache-2.0 Imports: 10 Imported by: 1,100

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HighTerm = strings.Repeat(string([]byte{0xff}), 10)
View Source
var LowTerm = string([]byte{0x00})

Functions

func LevenshteinDistance

func LevenshteinDistance(a, b *string) int

func LevenshteinDistanceMax

func LevenshteinDistanceMax(a, b *string, max int) (int, bool)

levenshteinDistanceMax same as levenshteinDistance but attempts to bail early once we know the distance will be greater than max in which case the first return val will be the max and the second will be true, indicating max was exceeded

Types

type Collector

type Collector interface {
	Collect(ctx context.Context, searcher Searcher, reader index.IndexReader) error
	Results() DocumentMatchCollection
	Total() uint64
	MaxScore() float64
	Took() time.Duration
	SetFacetsBuilder(facetsBuilder *FacetsBuilder)
	FacetResults() FacetResults
}

type DateRangeFacet

type DateRangeFacet struct {
	Name  string  `json:"name"`
	Start *string `json:"start,omitempty"`
	End   *string `json:"end,omitempty"`
	Count int     `json:"count"`
}

func (*DateRangeFacet) Same

func (drf *DateRangeFacet) Same(other *DateRangeFacet) bool

type DateRangeFacets

type DateRangeFacets []*DateRangeFacet

func (DateRangeFacets) Add

func (drf DateRangeFacets) Add(dateRangeFacet *DateRangeFacet) DateRangeFacets

func (DateRangeFacets) Len

func (drf DateRangeFacets) Len() int

func (DateRangeFacets) Less

func (drf DateRangeFacets) Less(i, j int) bool

func (DateRangeFacets) Swap

func (drf DateRangeFacets) Swap(i, j int)

type DocumentMatch

type DocumentMatch struct {
	Index           string                `json:"index,omitempty"`
	ID              string                `json:"id"`
	IndexInternalID index.IndexInternalID `json:"-"`
	Score           float64               `json:"score"`
	Expl            *Explanation          `json:"explanation,omitempty"`
	Locations       FieldTermLocationMap  `json:"locations,omitempty"`
	Fragments       FieldFragmentMap      `json:"fragments,omitempty"`
	Sort            []string              `json:"sort,omitempty"`

	// Fields contains the values for document fields listed in
	// SearchRequest.Fields. Text fields are returned as strings, numeric
	// fields as float64s and date fields as time.RFC3339 formatted strings.
	Fields map[string]interface{} `json:"fields,omitempty"`

	// as we learn field terms, we can cache important ones for later use
	// for example, sorting and building facets need these values
	CachedFieldTerms index.FieldTerms `json:"-"`

	// if we load the document for this hit, remember it so we dont load again
	Document *document.Document `json:"-"`

	// used to maintain natural index order
	HitNumber uint64 `json:"-"`
}

func (*DocumentMatch) AddFieldValue

func (dm *DocumentMatch) AddFieldValue(name string, value interface{})

func (*DocumentMatch) Reset added in v0.4.0

func (dm *DocumentMatch) Reset() *DocumentMatch

Reset allows an already allocated DocumentMatch to be reused

func (*DocumentMatch) String added in v0.4.0

func (dm *DocumentMatch) String() string

type DocumentMatchCollection

type DocumentMatchCollection []*DocumentMatch

func (DocumentMatchCollection) Len

func (c DocumentMatchCollection) Len() int

func (DocumentMatchCollection) Less

func (c DocumentMatchCollection) Less(i, j int) bool

func (DocumentMatchCollection) Swap

func (c DocumentMatchCollection) Swap(i, j int)

type DocumentMatchPool added in v0.4.0

type DocumentMatchPool struct {
	TooSmall DocumentMatchPoolTooSmall
	// contains filtered or unexported fields
}

DocumentMatchPool manages use/re-use of DocumentMatch instances it pre-allocates space from a single large block with the expected number of instances. It is not thread-safe as currently all aspects of search take place in a single goroutine.

func NewDocumentMatchPool added in v0.4.0

func NewDocumentMatchPool(size, sortsize int) *DocumentMatchPool

NewDocumentMatchPool will build a DocumentMatchPool with memory pre-allocated to accomodate the requested number of DocumentMatch instances

func (*DocumentMatchPool) Get added in v0.4.0

func (p *DocumentMatchPool) Get() *DocumentMatch

Get returns an available DocumentMatch from the pool if the pool was not allocated with sufficient size, an allocation will occur to satisfy this request. As a side-effect this will grow the size of the pool.

func (*DocumentMatchPool) Put added in v0.4.0

func (p *DocumentMatchPool) Put(d *DocumentMatch)

Put returns a DocumentMatch to the pool

type DocumentMatchPoolTooSmall added in v0.4.0

type DocumentMatchPoolTooSmall func(p *DocumentMatchPool) *DocumentMatch

DocumentMatchPoolTooSmall is a callback function that can be executed when the DocumentMatchPool does not have sufficient capacity By default we just perform just-in-time allocation, but you could log a message, or panic, etc.

type Explanation

type Explanation struct {
	Value    float64        `json:"value"`
	Message  string         `json:"message"`
	Children []*Explanation `json:"children,omitempty"`
}

func (*Explanation) String

func (expl *Explanation) String() string

type FacetBuilder

type FacetBuilder interface {
	Update(index.FieldTerms)
	Result() *FacetResult
	Field() string
}

type FacetResult

type FacetResult struct {
	Field         string             `json:"field"`
	Total         int                `json:"total"`
	Missing       int                `json:"missing"`
	Other         int                `json:"other"`
	Terms         TermFacets         `json:"terms,omitempty"`
	NumericRanges NumericRangeFacets `json:"numeric_ranges,omitempty"`
	DateRanges    DateRangeFacets    `json:"date_ranges,omitempty"`
}

func (*FacetResult) Fixup

func (fr *FacetResult) Fixup(size int)

func (*FacetResult) Merge

func (fr *FacetResult) Merge(other *FacetResult)

type FacetResults

type FacetResults map[string]*FacetResult

func (FacetResults) Fixup

func (fr FacetResults) Fixup(name string, size int)

func (FacetResults) Merge

func (fr FacetResults) Merge(other FacetResults)

type FacetsBuilder

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

func NewFacetsBuilder

func NewFacetsBuilder(indexReader index.IndexReader) *FacetsBuilder

func (*FacetsBuilder) Add

func (fb *FacetsBuilder) Add(name string, facetBuilder FacetBuilder)

func (*FacetsBuilder) Results

func (fb *FacetsBuilder) Results() FacetResults

func (*FacetsBuilder) Update

func (fb *FacetsBuilder) Update(docMatch *DocumentMatch) error

type FieldFragmentMap

type FieldFragmentMap map[string][]string

type FieldTermLocationMap

type FieldTermLocationMap map[string]TermLocationMap

func MergeLocations

func MergeLocations(locations []FieldTermLocationMap) FieldTermLocationMap

type Location

type Location struct {
	Pos            float64   `json:"pos"`
	Start          float64   `json:"start"`
	End            float64   `json:"end"`
	ArrayPositions []float64 `json:"array_positions"`
}

func (*Location) SameArrayElement

func (l *Location) SameArrayElement(other *Location) bool

SameArrayElement returns true if two locations are point to the same array element

type Locations

type Locations []*Location

type NumericRangeFacet

type NumericRangeFacet struct {
	Name  string   `json:"name"`
	Min   *float64 `json:"min,omitempty"`
	Max   *float64 `json:"max,omitempty"`
	Count int      `json:"count"`
}

type NumericRangeFacets

type NumericRangeFacets []*NumericRangeFacet

func (NumericRangeFacets) Add

func (nrf NumericRangeFacets) Add(numericRangeFacet *NumericRangeFacet) NumericRangeFacets

func (NumericRangeFacets) Len

func (nrf NumericRangeFacets) Len() int

func (NumericRangeFacets) Less

func (nrf NumericRangeFacets) Less(i, j int) bool

func (NumericRangeFacets) Swap

func (nrf NumericRangeFacets) Swap(i, j int)

type SearchContext added in v0.4.0

type SearchContext struct {
	DocumentMatchPool *DocumentMatchPool
}

SearchContext represents the context around a single search

type SearchSort added in v0.4.0

type SearchSort interface {
	Value(a *DocumentMatch) string
	Descending() bool

	RequiresDocID() bool
	RequiresScoring() bool
	RequiresFields() []string
}

func ParseSearchSortJSON added in v0.4.0

func ParseSearchSortJSON(input json.RawMessage) (SearchSort, error)

func ParseSearchSortObj added in v0.4.0

func ParseSearchSortObj(input map[string]interface{}) (SearchSort, error)

func ParseSearchSortString added in v0.4.0

func ParseSearchSortString(input string) SearchSort

type Searcher

type Searcher interface {
	Next(ctx *SearchContext) (*DocumentMatch, error)
	Advance(ctx *SearchContext, ID index.IndexInternalID) (*DocumentMatch, error)
	Close() error
	Weight() float64
	SetQueryNorm(float64)
	Count() uint64
	Min() int

	DocumentMatchPoolSize() int
}

type SortDocID added in v0.4.0

type SortDocID struct {
	Desc bool
}

SortDocID will sort results by the document identifier

func (*SortDocID) Descending added in v0.4.0

func (s *SortDocID) Descending() bool

Descending determines the order of the sort

func (*SortDocID) MarshalJSON added in v0.4.0

func (s *SortDocID) MarshalJSON() ([]byte, error)

func (*SortDocID) RequiresDocID added in v0.4.0

func (s *SortDocID) RequiresDocID() bool

RequiresDocID says this SearchSort does require the DocID be loaded

func (*SortDocID) RequiresFields added in v0.4.0

func (s *SortDocID) RequiresFields() []string

RequiresFields says this SearchStore does not require any stored fields

func (*SortDocID) RequiresScoring added in v0.4.0

func (s *SortDocID) RequiresScoring() bool

RequiresScoring says this SearchStore does not require scoring

func (*SortDocID) Value added in v0.4.0

func (s *SortDocID) Value(i *DocumentMatch) string

Value returns the sort value of the DocumentMatch

type SortField added in v0.4.0

type SortField struct {
	Field   string
	Desc    bool
	Type    SortFieldType
	Mode    SortFieldMode
	Missing SortFieldMissing
}

SortField will sort results by the value of a stored field

Field is the name of the field
Descending reverse the sort order (default false)
Type allows forcing of string/number/date behavior (default auto)
Mode controls behavior for multi-values fields (default first)
Missing controls behavior of missing values (default last)

func (*SortField) Descending added in v0.4.0

func (s *SortField) Descending() bool

Descending determines the order of the sort

func (*SortField) MarshalJSON added in v0.4.0

func (s *SortField) MarshalJSON() ([]byte, error)

func (*SortField) RequiresDocID added in v0.4.0

func (s *SortField) RequiresDocID() bool

RequiresDocID says this SearchSort does not require the DocID be loaded

func (*SortField) RequiresFields added in v0.4.0

func (s *SortField) RequiresFields() []string

RequiresFields says this SearchStore requires the specified stored field

func (*SortField) RequiresScoring added in v0.4.0

func (s *SortField) RequiresScoring() bool

RequiresScoring says this SearchStore does not require scoring

func (*SortField) Value added in v0.4.0

func (s *SortField) Value(i *DocumentMatch) string

Value returns the sort value of the DocumentMatch

type SortFieldMissing added in v0.4.0

type SortFieldMissing int

SortFieldMissing controls where documents missing a field value should be sorted

const (
	// SortFieldMissingLast sorts documents missing a field at the end
	SortFieldMissingLast SortFieldMissing = iota

	// SortFieldMissingFirst sorts documents missing a field at the beginning
	SortFieldMissingFirst
)

type SortFieldMode added in v0.4.0

type SortFieldMode int

SortFieldMode describes the behavior if the field has multiple values

const (
	// SortFieldDefault uses the first (or only) value, this is the default zero-value
	SortFieldDefault SortFieldMode = iota // FIXME name is confusing
	// SortFieldMin uses the minimum value
	SortFieldMin
	// SortFieldMax uses the maximum value
	SortFieldMax
)

type SortFieldType added in v0.4.0

type SortFieldType int

SortFieldType lets you control some internal sort behavior normally leaving this to the zero-value of SortFieldAuto is fine

const (
	// SortFieldAuto applies heuristics attempt to automatically sort correctly
	SortFieldAuto SortFieldType = iota
	// SortFieldAsString forces sort as string (no prefix coded terms removed)
	SortFieldAsString
	// SortFieldAsNumber forces sort as string (prefix coded terms with shift > 0 removed)
	SortFieldAsNumber
	// SortFieldAsDate forces sort as string (prefix coded terms with shift > 0 removed)
	SortFieldAsDate
)

type SortOrder added in v0.4.0

type SortOrder []SearchSort

func ParseSortOrderJSON added in v0.4.0

func ParseSortOrderJSON(in []json.RawMessage) (SortOrder, error)

func ParseSortOrderStrings added in v0.4.0

func ParseSortOrderStrings(in []string) SortOrder

func (SortOrder) CacheDescending added in v0.4.0

func (so SortOrder) CacheDescending() []bool

func (SortOrder) CacheIsScore added in v0.4.0

func (so SortOrder) CacheIsScore() []bool

func (SortOrder) Compare added in v0.4.0

func (so SortOrder) Compare(cachedScoring, cachedDesc []bool, i, j *DocumentMatch) int

Compare will compare two document matches using the specified sort order if both are numbers, we avoid converting back to term

func (SortOrder) RequiredFields added in v0.4.0

func (so SortOrder) RequiredFields() []string

func (SortOrder) RequiresDocID added in v0.4.0

func (so SortOrder) RequiresDocID() bool

func (SortOrder) RequiresScore added in v0.4.0

func (so SortOrder) RequiresScore() bool

func (SortOrder) Value added in v0.4.0

func (so SortOrder) Value(doc *DocumentMatch)

type SortScore added in v0.4.0

type SortScore struct {
	Desc bool
}

SortScore will sort results by the document match score

func (*SortScore) Descending added in v0.4.0

func (s *SortScore) Descending() bool

Descending determines the order of the sort

func (*SortScore) MarshalJSON added in v0.4.0

func (s *SortScore) MarshalJSON() ([]byte, error)

func (*SortScore) RequiresDocID added in v0.4.0

func (s *SortScore) RequiresDocID() bool

RequiresDocID says this SearchSort does not require the DocID be loaded

func (*SortScore) RequiresFields added in v0.4.0

func (s *SortScore) RequiresFields() []string

RequiresFields says this SearchStore does not require any store fields

func (*SortScore) RequiresScoring added in v0.4.0

func (s *SortScore) RequiresScoring() bool

RequiresScoring says this SearchStore does require scoring

func (*SortScore) Value added in v0.4.0

func (s *SortScore) Value(i *DocumentMatch) string

Value returns the sort value of the DocumentMatch

type TermFacet

type TermFacet struct {
	Term  string `json:"term"`
	Count int    `json:"count"`
}

type TermFacets

type TermFacets []*TermFacet

func (TermFacets) Add

func (tf TermFacets) Add(termFacet *TermFacet) TermFacets

func (TermFacets) Len

func (tf TermFacets) Len() int

func (TermFacets) Less

func (tf TermFacets) Less(i, j int) bool

func (TermFacets) Swap

func (tf TermFacets) Swap(i, j int)

type TermLocationMap

type TermLocationMap map[string]Locations

func MergeTermLocationMaps

func MergeTermLocationMaps(rv, other TermLocationMap) TermLocationMap

func (TermLocationMap) AddLocation

func (t TermLocationMap) AddLocation(term string, location *Location)

Jump to

Keyboard shortcuts

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