Documentation
¶
Index ¶
- Constants
- Variables
- func LowercaseFilter(tokens []string) (filteredTokens []string)
- func PunctuationFilter(tokens []string) (filteredTokens []string)
- func StopWordFilter(tokens []string) (filteredTokens []string)
- type Empty
- type Hit
- type IDScores
- type Index
- func Load(indexName string) (index *Index, err error)
- func LoadDeferred(indexName string) (index *Index, err error)
- func LoadDeferredFS(f fs.FS, indexName string) (index *Index, err error)
- func LoadFS(f fs.FS, indexName string) (index *Index, err error)
- func LoadWithProgressFS(f fs.FS, indexName string, progressCallback ProgressCallback, ...) (index *Index, err error)
- func New() (index *Index)
- func (index *Index) Analyze(s string) (tokens []string)
- func (index *Index) CalculateScore(documentID string, tokens []string) (score float64, err error)
- func (index *Index) CalculateShardID(s string) (shardID uint32)
- func (index *Index) Delete(documentID string) (err error)
- func (index *Index) Fetch(documentID string) (document map[string]interface{}, err error)
- func (index *Index) Index(document map[string]interface{}) (documentID string, err error)
- func (index *Index) IndexData(data []byte, dataType string) (err error)
- func (index *Index) IndexDataWithIDField(data []byte, dataType, idField string) (err error)
- func (index *Index) IndexFilePath(filePath, dataType string) (err error)
- func (index *Index) IndexFilePathWithIDField(filePath, dataType, idField string) (err error)
- func (index *Index) IndexReader(r io.Reader, dataType string) (err error)
- func (index *Index) IndexReaderWithIDField(r io.Reader, dataType, idField string) (err error)
- func (index *Index) IndexWithID(document map[string]interface{}, desiredDocumentID string) (documentID string, err error)
- func (index *Index) LoadAllShards(progressCallback ProgressCallback, sleepDuration time.Duration) (err error)
- func (index *Index) Save(indexName string) (err error)
- func (index *Index) SaveToShards(indexName string, shardCount int) (err error)
- func (index *Index) Search(s string) (res SearchResult, err error)
- func (index *Index) SearchWithOptions(s string, opts SearchOptions) (res SearchResult, err error)
- func (index *Index) Update(documentID string, document map[string]interface{}) (err error)
- type ProgressCallback
- type SearchOptions
- type SearchResult
- type SearchTime
- type StringSet
- type TermStat
Constants ¶
const ( FieldNamesFileExtension = "fns" DocumentsFileExtension = "dcs" TermStatsFileExtension = "tst" ShardCountFileName = "shard_count" )
Variables ¶
var DefaultSearchOptions = SearchOptions{ UseCache: true, Size: 10, From: 0, }
DefaultSearchOptions returns the default search options.
var ( // ErrDocumentMissingIDField is returned when the document being indexed is missing a field that // is specified by the user to be used as the document ID. ErrDocumentMissingIDField = errors.New("document missing id field") )
Functions ¶
func LowercaseFilter ¶
LowercaseFilter converts the tokens into their lowercase counterparts
func PunctuationFilter ¶
PunctuationFilter removes punctuations from tokens
func StopWordFilter ¶
StopWordFilter removes tokens that are stop words
Types ¶
type Hit ¶
Hit contains metadata of a document such as its ID and score, and also the document iself.
type IDScores ¶
type IDScores struct {
IDs sort.StringSlice
Scores sort.Float64Slice
}
IDScores is a structure used for sorting document IDs using their respective scores.
type Index ¶
type Index struct {
Name string
FieldNames []string
Documents map[string]map[string]interface{}
TermStats map[string]TermStat
LoadedDocumentsShards map[uint32]struct{}
LoadedTermStatsShards map[uint32]struct{}
ShardCount int
// contains filtered or unexported fields
}
Index contains all the information needed to search and return matching documents.
func LoadDeferred ¶
LoadDeferred loads an index metadata only the rest of the data is loaded when needed.
func LoadDeferredFS ¶
LoadDeferredFS loads an index metadata only the rest of the data is loaded when needed.
func LoadWithProgressFS ¶
func LoadWithProgressFS(f fs.FS, indexName string, progressCallback ProgressCallback, sleepDuration time.Duration) (index *Index, err error)
LoadWithProgressFS loads the entire index however user can monitor progress by passing a progress callback and also specify sleep duration between each shard.
func (*Index) Analyze ¶
AnalyzeString breaks down string into list of tokens with some metadata such positions.
func (*Index) CalculateScore ¶
func (*Index) CalculateShardID ¶
func (*Index) IndexData ¶
IndexData indexes an array of bytes and assumes a certain data type such as text, JSON, or JSONL.
func (*Index) IndexDataWithIDField ¶
IndexDataWithIDField performs similar operation as IndexData but user can provide which document field value to be used as the document ID. This is only compatible with "json" and "jsonl" data types.
func (*Index) IndexFilePath ¶
IndexFilePath indexes a file or directory containing files and assumes a certain data type such as text, JSON, or JSONL.
func (*Index) IndexFilePathWithIDField ¶
IndexFilePathWithIDField performs similar operation as IndexFilePath but user can provide which document field value to be used as the document ID. This is only compatible with "json" and "jsonl" data types.
func (*Index) IndexReader ¶
IndexReader indexes a reader and assumes a certain data type such as text, JSON, or JSONL.
func (*Index) IndexReaderWithIDField ¶
IndexReaderWithIDField performs similar operation as IndexReader but user can provide which document field value to be used as the document ID. This is only compatible with "json" and "jsonl" data types.
func (*Index) IndexWithID ¶
func (index *Index) IndexWithID(document map[string]interface{}, desiredDocumentID string) (documentID string, err error)
IndexWithID indexes a document into the index but with user-specified document ID.
func (*Index) LoadAllShards ¶
func (index *Index) LoadAllShards(progressCallback ProgressCallback, sleepDuration time.Duration) (err error)
func (*Index) SaveToShards ¶
func (*Index) Search ¶
func (index *Index) Search(s string) (res SearchResult, err error)
Search searches terms in an index and returns matching documents from the index along with some metadata. It is equivalent to SearchWithOptions using the default search options.
func (*Index) SearchWithOptions ¶
func (index *Index) SearchWithOptions(s string, opts SearchOptions) (res SearchResult, err error)
SearchWithOptions searches a term just like Search but it also accepts user-provided SearchOptions.
type ProgressCallback ¶
type ProgressCallback func(loadedShardsCount, totalShardsCount int)
type SearchOptions ¶
type SearchOptions struct {
UseCache bool // Whether to use and/or keep relevant data in memory
Size int // Number of documents to return
From int // Starting offset for returned documents
}
SearchOptions contains options that can be used to alter the search operation and result.
type SearchResult ¶
type SearchResult struct {
Count int
Hits []Hit
Time SearchTime
}
SearchResult contains the result of a search such as matching document count, the documents themselves with some metadata (a.k.a. the hits), and the search statistics.
type SearchTime ¶
SearchTime contains the elapsed times during various stages in the search process.
type StringSet ¶
type StringSet struct {
// contains filtered or unexported fields
}