fulltext

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package fulltext uses a full-text search engine to index, and search the content of the markdown textfiles used within the application.

Currently, the index is built at startup and stored in RAM as the number of files to catalog is low. However, if we were to expand the indexing to file downloads a different approach is needed.

Index

Constants

View Source
const Window = 40 // Window is number of characters to display either side of a snippet

Variables

View Source
var (
	ErrNoBody  = errors.New("body is empty or only contains white space")
	ErrNoIndex = errors.New("the blaze index is empty and must be created before using this func")
	ErrNoName  = errors.New("filename is empty")
)

Functions

func Snippet

func Snippet(query, body string, wordWindow int) string

Snippet finds the query in the body of text and returns the match with its surrounding text.

The wordWindow is the number of words to display either side of the match.

If no match is found, an empty string is returned.

Types

type Index

type Index struct {
	Name string // Name of the indexed file
	Body string // Body or text content of the indexed file
}

type Result

type Result struct {
	ID    int     // ID of the matching file
	Name  string  // Name of the matching file
	Score float64 // Score is the match relevancy
	Snip  string  // Snip is an snippet of text that was matched
}

type Tidbits

type Tidbits struct {
	TotalDocs  int   // Total number of indexed documents
	TotalTerms int64 // Total number of terms across all docs
	// contains filtered or unexported fields
}

Tidbits are the index for the group biographies stored as markdown texts.

func (*Tidbits) Add

func (ts *Tidbits) Add(filename, body string) error

Add both the filename and body to the Tidbits index. There are no checks for the validity of the arguments,

However, errors will return when:

  • the index has not been created
  • the filename is empty
  • the body trimmed of white space is empty

func (*Tidbits) Body

func (ts *Tidbits) Body(docID int) string

Body value of the document id is returned from the index. If the id doesn't exist, an empty string is returned.

func (*Tidbits) Name

func (ts *Tidbits) Name(docID int) string

Name value of the document id is returned from the index. If the id doesn't exist, an "error" string is returned.

func (*Tidbits) New

func (ts *Tidbits) New()

New creates an empty inverted index.

func (*Tidbits) NewIndex

func (ts *Tidbits) NewIndex(fsys embed.FS, root string) error

NewIndex indexes all the files found in the root directory of the fsys embed file system.

Note, it will overwrite any existing indexing. The blaze library annoyingly slogs every index added, so this func temporary mutes all slogs while indexing.

func (*Tidbits) Search

func (ts *Tidbits) Search(query string, maxResults int) []Result

Search the tidbits index for the query and return the results. An empty Result means no results were found.

func (*Tidbits) Stores

func (ts *Tidbits) Stores() int

Stores returns the number of items in the index store.

Jump to

Keyboard shortcuts

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