Documentation
¶
Index ¶
- Constants
- Variables
- func Load(data *segment.Data) (segment.Segment, error)
- func Merge(segments []segment.Segment, drops []*roaring.Bitmap, mergeBufferSize int) segment.Merger
- func New(results []segment.Document, normCalc func(string, int) float32) (segment.Segment, uint64, error)
- type Builder
- type CollectionStats
- type DictEntry
- type Dictionary
- func (d *Dictionary) Close() error
- func (d *Dictionary) Contains(key []byte) (bool, error)
- func (d *Dictionary) Iterator(a segment.Automaton, startKeyInclusive, endKeyExclusive []byte) segment.DictionaryIterator
- func (d *Dictionary) OrPostingsDense(a segment.Automaton, startKeyInclusive, endKeyExclusive []byte, dense []uint64) (bool, error)
- func (d *Dictionary) PostingsList(term []byte, except *roaring.Bitmap, prealloc segment.PostingsList) (segment.PostingsList, error)
- func (d *Dictionary) TermsIterator(a segment.Automaton, startKeyInclusive, endKeyExclusive []byte) segment.DictionaryIterator
- type DictionaryIterator
- type DocumentValueReader
- type Location
- type Merger
- type NumericField
- type NumericValueVisitor
- type Options
- type Posting
- type PostingsIterator
- func (i *PostingsIterator) ActualBitmap() *roaring.Bitmap
- func (i *PostingsIterator) Advance(docNum uint64) (segment.Posting, error)
- func (i *PostingsIterator) BlockBound(docNum uint64) (maxFreq int, minNorm float64, end uint64, ok bool)
- func (i *PostingsIterator) Close() error
- func (i *PostingsIterator) Count() uint64
- func (i *PostingsIterator) DocNum1Hit() (uint64, bool)
- func (i *PostingsIterator) Empty() bool
- func (i *PostingsIterator) LoadOffsets(h uint64, locs []int) error
- func (i *PostingsIterator) Next() (segment.Posting, error)
- func (i *PostingsIterator) NextBatch(docs []uint64, freqs []int, norms []float64) (int, error)
- func (i *PostingsIterator) NextLocBatch(docs []uint64, freqs []int, norms []float64, ends []int, fields []string, ...) (n int, fieldsOut []string, locsOut []int, err error)
- func (i *PostingsIterator) NextPosBatch(docs []uint64, freqs []int, norms []float64, ends []int, offs []uint64, ...) (n int, fieldsOut []string, locsOut []int, err error)
- func (i *PostingsIterator) ReplaceActual(abm *roaring.Bitmap)
- func (i *PostingsIterator) Size() int
- func (i *PostingsIterator) SkipBlocks(competitive func(maxFreq int, minNorm float64) bool) (uint64, error)
- type PostingsList
- type Segment
- func (s *Segment) CRC() uint32
- func (s *Segment) ChunkMode() uint32
- func (s *Segment) CollectionStats(field string) (segment.CollectionStats, error)
- func (s *Segment) Count() uint64
- func (s *Segment) Dictionary(field string) (segment.Dictionary, error)
- func (s *Segment) DocTimeMax() uint64
- func (s *Segment) DocTimeMin() uint64
- func (s *Segment) DocValueOffset() uint64
- func (s *Segment) DocsMatchingTerms(terms []segment.Term) (*roaring.Bitmap, error)
- func (s *Segment) DocumentValueReader(fields []string) (segment.DocumentValueReader, error)
- func (s *Segment) Fields() []string
- func (s *Segment) FieldsIndexOffset() uint64
- func (s *Segment) NumDocs() uint64
- func (s *Segment) NumericRange(field string, lo, hi int64) (bm *roaring.Bitmap, ok bool, err error)
- func (s *Segment) SearchVectors(ctx context.Context, field string, query []float32, k int, metric vec.Metric, ...) ([]vec.Match, error)
- func (s *Segment) Size() int
- func (s *Segment) StoredChunkCacheStats() (hits, misses uint64, entries int)
- func (s *Segment) StoredIndexOffset() uint64
- func (s *Segment) Timestamp() (minimum, maximum int64)
- func (s *Segment) Type() string
- func (s *Segment) Version() uint32
- func (s *Segment) VisitNumericBlocks(field string, visitor func(base uint64, docs []uint64, vals []int64) error) (ok bool, err error)
- func (s *Segment) VisitNumericColumn(field string, visitor func(docNum uint64, value int64) error) (ok bool, err error)
- func (s *Segment) VisitStoredFields(num uint64, visitor segment.StoredFieldVisitor) error
- func (s *Segment) WriteTo(w io.Writer, _ chan struct{}) (int64, error)
Constants ¶
const MinReadableVersion = versionTermDocValues
MinReadableVersion is the oldest segment version this package loads.
const NoOffsets = math.MaxUint64
NoOffsets is the offsets handle NextPosBatch gives a posting whose locations already carry their start and end, or that has none.
const Type string = "ice"
const Version uint32 = 7
Version 7 stores location start/end offsets apart from field and pos (see versionSplitOffsets). Version 6 stores freq/norm and location chunks raw unless s2 shrinks them enough, and delta codes locations (see versionCompactPostings). Version 5 added per-chunk freq/norm bounds (block max) to postings.
Variables ¶
var StoredChunkCacheSize = 100
StoredChunkCacheSize is the default number of decompressed stored-field chunks each segment keeps in its LRU cache; New and Load read it when a segment is opened. A chunk holds defaultDocumentChunkSize documents. Zero disables caching. Use Options to set it per index instead of globally.
Functions ¶
func New ¶
func New(results []segment.Document, normCalc func(string, int) float32) ( segment.Segment, uint64, error)
New creates an in-memory implementation of a segment for the source documents. Large batches are converted by several goroutines at once, so the documents must be safe to visit, and normCalc to call, concurrently.
Types ¶
type Builder ¶ added in v1.5.0
type Builder struct {
// contains filtered or unexported fields
}
Builder builds a segment from documents added one at a time. Add records each term's postings varint encoded in its own chain of blocks (see termStream), the way riot-go's and Tantivy's indexing recorders do, and copies the stored values, so a caller can drop each document (and its analysis) once added. Build sorts the terms and decodes one term's postings at a time as it encodes them, so no inverted copy of the documents is held alongside the records. Build writes the same segment as New over the same documents in the same order.
A Builder is not safe for concurrent use. After an error, Add and Build return that error.
func NewBuilder ¶ added in v1.5.0
NewBuilder returns an empty Builder with the default Options.
func (*Builder) Add ¶ added in v1.5.0
Add adds doc as the next document; doc is not used once Add returns.
func (*Builder) Build ¶ added in v1.5.0
Build returns the segment of the added documents and its size in bytes; the Builder must not be used afterwards. The stored fields are written while the terms are sorted and encoded, and each field's terms are sorted on their own goroutine.
type CollectionStats ¶
type CollectionStats struct {
// contains filtered or unexported fields
}
func (*CollectionStats) DocumentCount ¶
func (c *CollectionStats) DocumentCount() uint64
func (*CollectionStats) Merge ¶
func (c *CollectionStats) Merge(other segment.CollectionStats)
func (*CollectionStats) SumTotalTermFrequency ¶
func (c *CollectionStats) SumTotalTermFrequency() uint64
func (*CollectionStats) TotalDocumentCount ¶
func (c *CollectionStats) TotalDocumentCount() uint64
type Dictionary ¶
type Dictionary struct {
// contains filtered or unexported fields
}
Dictionary is the representation of the term dictionary
func (*Dictionary) Close ¶
func (d *Dictionary) Close() error
func (*Dictionary) Iterator ¶
func (d *Dictionary) Iterator(a segment.Automaton, startKeyInclusive, endKeyExclusive []byte) segment.DictionaryIterator
Iterator returns an iterator which only visits terms having the the vellum automaton and start/end key range
func (*Dictionary) OrPostingsDense ¶ added in v1.3.3
func (d *Dictionary) OrPostingsDense(a segment.Automaton, startKeyInclusive, endKeyExclusive []byte, dense []uint64) (bool, error)
OrPostingsDense ORs the postings of every term the automaton accepts in [startKeyInclusive, endKeyExclusive) into dense, a bitset of the segment's documents, walking the dictionary once. It returns false, leaving dense partly written, if a posting falls outside dense.
func (*Dictionary) PostingsList ¶
func (d *Dictionary) PostingsList(term []byte, except *roaring.Bitmap, prealloc segment.PostingsList) (segment.PostingsList, error)
PostingsList returns the postings list for the specified term
func (*Dictionary) TermsIterator ¶ added in v1.3.3
func (d *Dictionary) TermsIterator(a segment.Automaton, startKeyInclusive, endKeyExclusive []byte) segment.DictionaryIterator
TermsIterator is Iterator without reading each term's postings for its count: entries report a Count of 0. Use it when only terms are needed.
type DictionaryIterator ¶
type DictionaryIterator struct {
// contains filtered or unexported fields
}
DictionaryIterator is an iterator for term dictionary
func (*DictionaryIterator) Close ¶
func (i *DictionaryIterator) Close() error
func (*DictionaryIterator) Next ¶
func (i *DictionaryIterator) Next() (segment.DictionaryEntry, error)
Next returns the next entry in the dictionary
type DocumentValueReader ¶
type DocumentValueReader struct {
// contains filtered or unexported fields
}
func (*DocumentValueReader) VisitDocumentNumbers ¶ added in v1.3.0
func (d *DocumentValueReader) VisitDocumentNumbers(number uint64, visitor segment.DocumentValueVisitor, numVisitor segment.NumericValueVisitor) error
VisitDocumentNumbers is like VisitDocumentValues but numeric column fields go to numVisitor as int64 instead of prefix coded terms.
func (*DocumentValueReader) VisitDocumentValues ¶
func (d *DocumentValueReader) VisitDocumentValues(number uint64, visitor segment.DocumentValueVisitor) error
type Location ¶
type Location struct {
// contains filtered or unexported fields
}
Location represents the location of a single occurrence
func (*Location) Field ¶
Field returns the name of the field (useful in composite fields to know which original field the value came from)
type Merger ¶
type Merger struct {
// contains filtered or unexported fields
}
func (*Merger) DocumentNumbers ¶
type NumericField ¶ added in v1.3.0
type NumericField = segment.NumericField
NumericField is the segment API's typed numeric field; kept as an alias so existing callers in this package keep compiling.
type NumericValueVisitor ¶ added in v1.3.0
type NumericValueVisitor = segment.NumericValueVisitor
NumericValueVisitor receives typed values of numeric column fields.
type Options ¶ added in v1.3.0
type Options struct {
// StoredChunkCacheSize bounds decompressed stored-field chunks kept per
// segment; zero disables caching.
StoredChunkCacheSize int
}
Options tunes segments opened by its New and Load methods, which match the signatures of the package-level New and Load.
func DefaultOptions ¶ added in v1.3.0
func DefaultOptions() Options
DefaultOptions returns Options mirroring the package-level defaults.
func (Options) Load ¶ added in v1.3.0
Load is like the package-level Load but applies o to the segment.
type Posting ¶
type Posting struct {
// contains filtered or unexported fields
}
Posting is a single entry in a postings list
func (*Posting) Frequency ¶
Frequency returns the frequencies of occurrence of this term in this doc/field
type PostingsIterator ¶
type PostingsIterator struct {
Actual roaring.IntPeekable
ActualBM *roaring.Bitmap
// contains filtered or unexported fields
}
PostingsIterator provides a way to iterate through the postings list
func (*PostingsIterator) ActualBitmap ¶
func (i *PostingsIterator) ActualBitmap() *roaring.Bitmap
ActualBitmap returns the underlying actual bitmap which can be used up the stack for optimizations
func (*PostingsIterator) Advance ¶
func (i *PostingsIterator) Advance(docNum uint64) (segment.Posting, error)
Advance returns the posting at the specified docNum or it is not present the next posting, or if the end is reached, nil
func (*PostingsIterator) BlockBound ¶ added in v1.4.0
func (i *PostingsIterator) BlockBound(docNum uint64) (maxFreq int, minNorm float64, end uint64, ok bool)
BlockBound returns the largest freq and smallest norm of the freq/norm chunk holding docNum, and the first docNum past that chunk. ok is false when the segment stores no chunk bounds (before version 5) or the list has no freq/norm chunks.
func (*PostingsIterator) Close ¶
func (i *PostingsIterator) Close() error
func (*PostingsIterator) Count ¶
func (i *PostingsIterator) Count() uint64
func (*PostingsIterator) DocNum1Hit ¶
func (i *PostingsIterator) DocNum1Hit() (uint64, bool)
DocNum1Hit returns the docNum and true if this is "1-hit" optimized and the docNum is available.
func (*PostingsIterator) Empty ¶
func (i *PostingsIterator) Empty() bool
func (*PostingsIterator) LoadOffsets ¶ added in v1.5.0
func (i *PostingsIterator) LoadOffsets(h uint64, locs []int) error
LoadOffsets sets the start and end of the locations of a posting that NextPosBatch returned with offsets handle h, given as that posting's (pos, start, end) triples in locs. It does nothing for NoOffsets.
func (*PostingsIterator) Next ¶
func (i *PostingsIterator) Next() (segment.Posting, error)
Next returns the next posting on the postings list, or nil at the end
func (*PostingsIterator) NextBatch ¶ added in v1.3.3
NextBatch reads up to len(docs) postings into docs, freqs and norms, which must be the same length, and returns how many it read; 0 means the end. It is Next in bulk for iterators without locations.
func (*PostingsIterator) NextLocBatch ¶ added in v1.5.0
func (i *PostingsIterator) NextLocBatch(docs []uint64, freqs []int, norms []float64, ends []int, fields []string, locs []int) (n int, fieldsOut []string, locsOut []int, err error)
NextLocBatch is NextBatch with locations: it reads up to len(docs) postings into docs, freqs and norms, appends the field of each of their locations to fields and its pos, start and end to locs, and sets ends[k] to len(fields) after posting k. ends must be as long as docs. It returns how many postings it read, 0 meaning the end, and the grown fields/locs.
func (*PostingsIterator) NextPosBatch ¶ added in v1.5.0
func (i *PostingsIterator) NextPosBatch(docs []uint64, freqs []int, norms []float64, ends []int, offs []uint64, fields []string, locs []int) (n int, fieldsOut []string, locsOut []int, err error)
NextPosBatch is NextLocBatch that may leave the start and end of the locations of a posting zero: then offs[k], else NoOffsets, is the handle that LoadOffsets fills them in with, until the iterator is reused. offs must be as long as docs. Version 7+ segments, which keep the offsets apart, read them only when asked.
func (*PostingsIterator) ReplaceActual ¶
func (i *PostingsIterator) ReplaceActual(abm *roaring.Bitmap)
ReplaceActual replaces the ActualBM with the provided bitmap
func (*PostingsIterator) Size ¶
func (i *PostingsIterator) Size() int
func (*PostingsIterator) SkipBlocks ¶ added in v1.4.0
func (i *PostingsIterator) SkipBlocks(competitive func(maxFreq int, minNorm float64) bool) (uint64, error)
SkipBlocks skips, from the next posting on, the rest of every freq/norm chunk whose bounds competitive rejects, stopping at the first chunk it accepts, and returns how many postings it skipped. competitive gets the chunk's largest freq and smallest norm. Chunk bounds exist in version 5+ segments; elsewhere, and on lists with deletions, it skips nothing.
type PostingsList ¶
type PostingsList struct {
// contains filtered or unexported fields
}
PostingsList is an in-memory representation of a postings list
func (*PostingsList) Count ¶
func (p *PostingsList) Count() uint64
Count returns the number of items on this postings list
func (*PostingsList) Iterator ¶
func (p *PostingsList) Iterator(includeFreq, includeNorm, includeLocs bool, prealloc segment.PostingsIterator) (segment.PostingsIterator, error)
Iterator returns an iterator for this postings list
func (*PostingsList) OrInto ¶
func (p *PostingsList) OrInto(receiver *roaring.Bitmap)
func (*PostingsList) Size ¶
func (p *PostingsList) Size() int
type Segment ¶
type Segment struct {
// contains filtered or unexported fields
}
func (*Segment) CollectionStats ¶
func (s *Segment) CollectionStats(field string) (segment.CollectionStats, error)
func (*Segment) Dictionary ¶
func (s *Segment) Dictionary(field string) (segment.Dictionary, error)
DictionaryReader returns the term dictionary for the specified field
func (*Segment) DocTimeMax ¶
DocTimeMax returns the maximum timestamp of documents in the file footer
func (*Segment) DocTimeMin ¶
DocTimeMin returns the minimum timestamp of documents in the file footer
func (*Segment) DocValueOffset ¶
DocValueOffset returns the docValue offset in the file footer
func (*Segment) DocsMatchingTerms ¶
func (*Segment) DocumentValueReader ¶
func (s *Segment) DocumentValueReader(fields []string) (segment.DocumentValueReader, error)
func (*Segment) FieldsIndexOffset ¶
FieldsIndexOffset returns the fields index offset in the file footer
func (*Segment) NumericRange ¶ added in v1.5.0
NumericRange returns the documents of field with a value in [lo, hi]. Blocks outside the range are skipped by their bounds and dense blocks fully inside it are added without decoding. ok is false when field has no numeric column in this segment, or when the column does not hold exactly the documents indexed in field, so it would match otherwise than the field's terms.
func (*Segment) SearchVectors ¶
func (s *Segment) SearchVectors(ctx context.Context, field string, query []float32, k int, metric vec.Metric, accept func(uint64) bool) ([]vec.Match, error)
SearchVectors exhaustively searches encoded vectors in stored field values. Repeated fields contribute their best score per document. Results are ordered by descending score, then ascending segment-local document number. accept is an optional prefilter; callers must use it to exclude live-index deletions. Every matching value in an accepted document must be valid, even outside top k.
func (*Segment) StoredChunkCacheStats ¶ added in v1.3.0
StoredChunkCacheStats returns hits, misses and resident entries of the decompressed stored-field chunk cache.
func (*Segment) StoredIndexOffset ¶
StoredIndexOffset returns the stored value index offset in the file footer
func (*Segment) VisitNumericBlocks ¶ added in v1.5.0
func (s *Segment) VisitNumericBlocks(field string, visitor func(base uint64, docs []uint64, vals []int64) error) (ok bool, err error)
VisitNumericBlocks is VisitNumericColumn a block at a time: docs and vals are parallel, docs is nil when the block is dense (doc numbers base, base+1, ...), and both are reused between calls. ok is false when field has no numeric column in this segment.
func (*Segment) VisitNumericColumn ¶ added in v1.5.0
func (s *Segment) VisitNumericColumn(field string, visitor func(docNum uint64, value int64) error) (ok bool, err error)
VisitNumericColumn calls visitor for every (docNum, value) of field in doc order, decoding the column block by block. ok is false when field has no numeric column in this segment.
func (*Segment) VisitStoredFields ¶
func (s *Segment) VisitStoredFields(num uint64, visitor segment.StoredFieldVisitor) error
VisitStoredFields invokes the DocFieldValueVistor for each stored field for the specified doc number