indexer

package
v0.0.0-...-e083d15 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package indexer implements the core indexing engine. It maintains an in-memory inverted index backed by on-disk segments that are periodically flushed. Searches fan out across the memory index and all segment readers, and results are deduplicated before being returned.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

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

Engine is the primary indexing data structure. It buffers documents in a MemoryIndex and flushes them to immutable on-disk segments when the configured size threshold is reached.

func NewEngine

func NewEngine(cfg config.IndexerConfig) (*Engine, error)

NewEngine creates a new Engine, creating the data directory if necessary and loading any previously-flushed segments from disk.

func (*Engine) Close

func (e *Engine) Close() error

Close flushes any remaining data and closes all segment readers.

func (*Engine) Flush

func (e *Engine) Flush() error

Flush writes the current memory index snapshot to a new on-disk segment and opens a reader for it.

func (*Engine) GetAvgDocLength

func (e *Engine) GetAvgDocLength() float64

GetAvgDocLength returns the average document length across all indexed docs.

func (*Engine) GetDocLength

func (e *Engine) GetDocLength(docID string) int

GetDocLength returns the token count for the given document.

func (*Engine) GetTotalDocs

func (e *Engine) GetTotalDocs() int64

GetTotalDocs returns the total number of documents indexed by this engine.

func (*Engine) IndexDocument

func (e *Engine) IndexDocument(docID string, title string, body string) error

IndexDocument tokenises the document and adds it to the memory index. If the memory index exceeds SegmentMaxSize the buffer is flushed to disk.

func (*Engine) ReloadSegments

func (e *Engine) ReloadSegments() int

ReloadSegments re-scans the data directory for .spdx segment files and opens any that are not already loaded. This allows a searcher process to pick up segments flushed by a separate indexer process sharing the same data volume.

func (*Engine) Search

func (e *Engine) Search(term string) (index.PostingList, error)

Search tokenises the query term, queries the memory index and all segment readers, and returns deduplicated postings.

func (*Engine) StartFlushLoop

func (e *Engine) StartFlushLoop(ctx context.Context)

StartFlushLoop starts a background goroutine that flushes the memory index at the configured interval. It performs a final flush when ctx is cancelled.

Directories

Path Synopsis
Package consumer reads ingestion events from Kafka and indexes them via the indexer engine, optionally routing documents through the shard router for partitioned indexing.
Package consumer reads ingestion events from Kafka and indexes them via the indexer engine, optionally routing documents through the shard router for partitioned indexing.
Package index defines the in-memory inverted-index data structures used by the indexer.
Package index defines the in-memory inverted-index data structures used by the indexer.
Package segment implements a custom binary segment file format (.spdx) for persisting inverted-index data to disk.
Package segment implements a custom binary segment file format (.spdx) for persisting inverted-index data to disk.
Package shard provides hash-based shard routing for index engines.
Package shard provides hash-based shard routing for index engines.
Package tokenizer provides text tokenisation for the search engine.
Package tokenizer provides text tokenisation for the search engine.

Jump to

Keyboard shortcuts

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