added privacy policy page and about section, improved dir check, fixed crash when idexer is disabled

This commit is contained in:
partisan 2025-01-05 19:23:53 +01:00
parent 61266c461a
commit 5ae97da6d0
18 changed files with 698 additions and 107 deletions

View file

@ -9,7 +9,6 @@ import (
"strconv"
"strings"
"sync"
"time"
"github.com/blevesearch/bleve/v2"
"golang.org/x/net/publicsuffix"
@ -73,17 +72,17 @@ func indexDocImmediately(link, title, tags, desc, rank string) error {
return nil
}
// StartBatchIndexing spawns a goroutine that flushes the buffer every interval.
func StartBatchIndexing() {
go func() {
ticker := time.NewTicker(config.IndexRefreshInterval)
defer ticker.Stop()
// // StartBatchIndexing spawns a goroutine that flushes the buffer every interval.
// func StartBatchIndexing() {
// go func() {
// ticker := time.NewTicker(config.IndexRefreshInterval)
// defer ticker.Stop()
for range ticker.C {
flushDocBuffer()
}
}()
}
// for range ticker.C {
// flushDocBuffer()
// }
// }()
// }
func flushDocBuffer() {
docBufferMu.Lock()
@ -264,6 +263,11 @@ func IndexFile(filePath string) error {
// SearchIndex performs a full-text search on the indexed data.
func SearchIndex(queryStr string, page, pageSize int) ([]Document, error) {
// Check if the indexer is enabled
if !config.IndexerEnabled {
return nil, fmt.Errorf("indexer is disabled")
}
exactMatch := bleve.NewMatchQuery(queryStr) // Exact match
fuzzyMatch := bleve.NewFuzzyQuery(queryStr) // Fuzzy match
fuzzyMatch.Fuzziness = 2