analysis

package
v1.80.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 13 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTermFromRunes

func BuildTermFromRunes(runes []rune) []byte

func BuildTermFromRunesOptimistic

func BuildTermFromRunesOptimistic(buf []byte, runes []rune) []byte

BuildTermFromRunesOptimistic will build a term from the provided runes AND optimistically attempt to encode into the provided buffer if at any point it appears the buffer is too small, a new buffer is allocated and that is used instead this should be used in cases where frequently the new term is the same length or shorter than the original term (in number of bytes)

func DeleteRune

func DeleteRune(in []rune, pos int) []rune

func InsertRune

func InsertRune(in []rune, pos int, r rune) []rune

func Loc32 added in v1.70.0

func Loc32(v int) int32

Loc32 converts a location value for TokenLocation: -1 when it does not fit an int32.

func ReleaseFreqBlock added in v1.70.0

func ReleaseFreqBlock(blk *FreqBlock)

ReleaseFreqBlock recycles blk; nothing may use its results afterwards.

func RunesEndsWith

func RunesEndsWith(input []rune, suffix string) bool

func TokenFrequencyPooled added in v1.70.0

func TokenFrequencyPooled(tokens TokenStream, includeTermVectors bool, startOffset int) (
	tfs []TokenFreq, position int, blk *FreqBlock)

TokenFrequencyPooled is TokenFrequencySlice into recycled storage. The result is valid until blk is passed to ReleaseFreqBlock.

func TruncateRunes

func TruncateRunes(input []byte, num int) []byte

Types

type Analyzer

type Analyzer struct {
	CharFilters  []CharFilter
	Tokenizer    Tokenizer
	TokenFilters []TokenFilter
}

func (*Analyzer) Analyze

func (a *Analyzer) Analyze(input []byte) TokenStream

type CharFilter

type CharFilter interface {
	Filter([]byte) []byte
}

type FreqBlock added in v1.70.0

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

FreqBlock is the storage behind a TokenFrequencyPooled result.

func NewFreqBlock added in v1.80.0

func NewFreqBlock() *FreqBlock

NewFreqBlock returns recycled storage for TokenFrequency and CopyText.

func (*FreqBlock) CopyText added in v1.80.0

func (blk *FreqBlock) CopyText(text []byte) []byte

CopyText copies text into blk, so tokens may alias and modify the copy; it is valid until blk is passed to ReleaseFreqBlock.

func (*FreqBlock) TokenFrequency added in v1.80.0

func (blk *FreqBlock) TokenFrequency(tokens TokenStream, includeTermVectors bool, startOffset int) (
	tfs []TokenFreq, position int)

TokenFrequency is TokenFrequencySlice into blk. The result is valid until blk is passed to ReleaseFreqBlock.

type Token

type Token struct {
	// Start specifies the byte offset of the beginning of the term in the
	// field.
	Start int

	// End specifies the byte offset of the end of the term in the field.
	End  int
	Term []byte

	// PositionIncr specifies the position of this token relative to the previous.
	PositionIncr int
	Type         TokenType
	KeyWord      bool
}

Token represents one occurrence of a term at a particular location in a field.

func (*Token) String

func (t *Token) String() string

type TokenFilter

type TokenFilter interface {
	Filter(TokenStream) TokenStream
}

A TokenFilter adds, transforms or removes tokens from a token stream.

type TokenFreq

type TokenFreq struct {
	TermVal   []byte
	Locations []TokenLocation
	// contains filtered or unexported fields
}

TokenFreq represents all the occurrences of a term in all fields of a document. Locations holds the values, not pointers, so a term's locations are one allocation (or a window of one shared by the field).

func AppendTerm added in v1.70.0

func AppendTerm(tfs []TokenFreq, term []byte) []TokenFreq

AppendTerm adds one occurrence of term, without a location, to tfs: as TokenFrequencySlice does for a short stream without term vectors.

func SingleTokenFrequency added in v1.70.0

func SingleTokenFrequency(term []byte, includeTermVectors bool, startOffset int) (
	tfs []TokenFreq, position int)

SingleTokenFrequency is TokenFrequencySlice for a stream of one token spanning all of term (position increment 1), without building the stream.

func TokenFrequencySlice added in v1.60.0

func TokenFrequencySlice(tokens TokenStream, includeTermVectors bool, startOffset int) (
	tfs []TokenFreq, position int)

TokenFrequencySlice is TokenFrequency without the map: the distinct terms in first occurrence order. As with TokenFrequency, position is only tracked (from startOffset) when includeTermVectors is set.

func (*TokenFreq) EachLocation

func (tf *TokenFreq) EachLocation(location segment.VisitLocation)

func (*TokenFreq) Frequency

func (tf *TokenFreq) Frequency() int

func (*TokenFreq) Size

func (tf *TokenFreq) Size() int

func (*TokenFreq) Term

func (tf *TokenFreq) Term() []byte

type TokenFrequencies

type TokenFrequencies map[string]*TokenFreq

TokenFrequencies maps document terms to their combined frequencies from all fields.

func NewTokenFrequencies added in v1.60.0

func NewTokenFrequencies(tfs []TokenFreq) TokenFrequencies

NewTokenFrequencies indexes tfs by term; the map points into tfs.

func TokenFrequency

func TokenFrequency(tokens TokenStream, includeTermVectors bool, startOffset int) (
	tokenFreqs TokenFrequencies, position int)

func (TokenFrequencies) MergeAll

func (tfs TokenFrequencies) MergeAll(remoteField string, other TokenFrequencies)

func (TokenFrequencies) MergeOneBytes

func (tfs TokenFrequencies) MergeOneBytes(remoteField string, tfk []byte, tf *TokenFreq)

func (TokenFrequencies) Size

func (tfs TokenFrequencies) Size() int

type TokenLocation

type TokenLocation struct {
	FieldVal    string
	StartVal    int32
	EndVal      int32
	PositionVal int32
}

TokenLocation represents one occurrence of a term at a particular location in a field. Start, End and Position have the same meaning as in analysis.Token. Field and ArrayPositions identify the field value in the source document. See document.Field for details. Values beyond int32 are stored as -1, which segments reject as a negative location.

func (*TokenLocation) End

func (tl *TokenLocation) End() int

func (*TokenLocation) Field

func (tl *TokenLocation) Field() string

func (*TokenLocation) Pos

func (tl *TokenLocation) Pos() int

func (*TokenLocation) Size

func (tl *TokenLocation) Size() int

func (*TokenLocation) Start

func (tl *TokenLocation) Start() int

type TokenMap

type TokenMap map[string]bool

func NewTokenMap

func NewTokenMap() TokenMap

func (TokenMap) AddToken

func (t TokenMap) AddToken(token string)

func (TokenMap) LoadBytes

func (t TokenMap) LoadBytes(data []byte)

LoadBytes reads in a list of tokens from memory, one per line. Comments are supported using `#` or `|`

func (TokenMap) LoadFile

func (t TokenMap) LoadFile(filename string) error

LoadFile reads in a list of tokens from a text file, one per line. Comments are supported using `#` or `|`

func (TokenMap) LoadLine

func (t TokenMap) LoadLine(line string)

type TokenStream

type TokenStream []*Token

type TokenType

type TokenType int
const (
	AlphaNumeric TokenType = iota
	Ideographic
	Numeric
	DateTime
	Shingle
	Single
	Double
	Boolean
	IP
)

type Tokenizer

type Tokenizer interface {
	Tokenize([]byte) TokenStream
}

A Tokenizer splits an input string into tokens, the usual behavior being to map words to tokens.

Directories

Path Synopsis
Package lang is the registry of language analyzers selected by code, for example riot.Config.WithLang("de").
Package lang is the registry of language analyzers selected by code, for example riot.Config.WithLang("de").
ar
bg
ca
cjk
ckb
cs
da
de
el
en
Package en implements an analyzer with reasonable defaults for processing English text.
Package en implements an analyzer with reasonable defaults for processing English text.
es
eu
fa
fi
fr
ga
gl
hi
hu
hy
id
in
it
nl
no
pt
ro
ru
sv
tr
Package lowercase implements a TokenFilter which converts tokens to lower case according to unicode rules.
Package lowercase implements a TokenFilter which converts tokens to lower case according to unicode rules.

Jump to

Keyboard shortcuts

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