fts

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: MIT Imports: 10 Imported by: 1

README

fts

Basic full text search for Go.

Usage

// Create new index or open existing from file
index, err := Open("fileName.bin") // specify "" parameter if you need only memory index

// Add data to index.
index.Add(1, "first document text")
index.Add(2, "second document text")
index.Add(3, "third document text")

// Execute query
ids, err := index.Search("first") // ids holds IDs of documents

// Save index to disk
err = index.Save()

Index file structure

Index file is a MessagePack encoded file:

[]
    word string // single word
    ids  []int  // IDs of documents that contains this word

Used libraries

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Index

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

Index holds basic indexes of documents.

func Open

func Open(filePath string) (*Index, error)

Opens creates new index or read index from disk.

func (*Index) Add

func (index *Index) Add(id int, text string)

Add adds data to index.

func (*Index) Save

func (index *Index) Save() error

Save saves index to disk.

func (*Index) Search

func (index *Index) Search(text string) ([]int, error)

Search queries index for the given text.

Jump to

Keyboard shortcuts

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