{"modulePath":"github.com/Defacto2/server","version":"v1.16.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package fulltext\n\nPackage fulltext uses a full-text search engine to index, and search the content of the markdown textfiles used within the application.\n\nCurrently, 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.\n\n## Constants\n\n```go\nconst Window = 40 // Window is number of characters to display either side of a snippet\n\n```\n\n## Variables\n\n```go\nvar (\n\tErrNoBody  = errors.New(\"fulltext: body is empty or only contains white space\")\n\tErrNoIndex = errors.New(\"fulltext: the blaze index is empty and must be created before using this func\")\n\tErrNoName  = errors.New(\"fulltext: filename is empty\")\n)\n```\n\n## Functions\n\n```go\nfunc Snippet(query, body string, wordWindow int) string\n```\nSnippet finds the query in the body of text and returns the match with its surrounding text.\n\nThe wordWindow is the number of words to display either side of the match.\n\nIf the query is empty, an empty string is returned. If no match is found, the beginning of body is returned truncated to wordWindow\\*2 words.\n\n## Types\n\n```go\ntype Index struct {\n\tName string // Name of the indexed file\n\tBody string // Body or text content of the indexed file\n}\n```\n\n```go\ntype Result struct {\n\tID    int     // ID of the matching file\n\tName  string  // Name of the matching file\n\tScore float64 // Score is the match relevancy\n\tSnip  string  // Snip is a snippet of text that was matched\n}\n```\n\n```go\ntype Tidbits struct {\n\tTotalDocs  int   // Total number of indexed documents\n\tTotalTerms int64 // Total number of terms across all docs\n\t// contains filtered or unexported fields\n}\n```\nTidbits are the index for the group biographies stored as markdown texts.\n\n```go\nfunc (ts *Tidbits) Add(filename, body string) error\n```\nAdd both the filename and body to the Tidbits index. There are no checks for the validity of the arguments,\n\nHowever, errors will return when:\n\n  - the index has not been created\n  - the filename is empty\n  - the body trimmed of white space is empty\n\n```go\nfunc (ts *Tidbits) Body(docID int) string\n```\nBody value of the document id is returned from the index. If the id doesn't exist, an empty string is returned.\n\n```go\nfunc (ts *Tidbits) Name(docID int) string\n```\nName value of the document id is returned from the index. If the id doesn't exist, an \"error\" string is returned.\n\n```go\nfunc (ts *Tidbits) New()\n```\nNew creates an empty inverted index.\n\n```go\nfunc (ts *Tidbits) NewIndex(fsys fs.FS, root string) error\n```\nNewIndex indexes all the files found in the root directory of the fsys embed file system.\n\nNote, it will overwrite any existing indexing. The blaze library annoyingly slogs every index added, so this func temporarily mutes all slogs while indexing.\n\n```go\nfunc (ts *Tidbits) Search(query string, maxResults int) []Result\n```\nSearch the tidbits index for the query and return the results. An empty Result means no results were found.\n\n```go\nfunc (ts *Tidbits) Stats() (int, int64)\n```\nStats returns the total indexed documents and search terms safely.\n\n```go\nfunc (ts *Tidbits) Stores() int\n```\nStores returns the number of items in the index store.\n\n","path":"github.com/Defacto2/server/handler/fulltext","name":"fulltext","synopsis":"Package fulltext uses a full-text search engine to index, and search the content of the markdown textfiles used within the application.","isRedistributable":true}
