Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
svera committed Feb 6, 2024
1 parent 670cb2b commit 7821862
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 11 additions & 6 deletions internal/index/bleve_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,34 @@ func (b *BleveIndexer) Search(keywords string, page, resultsPerPage int) (result
return b.runPaginatedQuery(compound, page, resultsPerPage)
}

func composeQuery(keywords string, languages []string) *query.DisjunctionQuery {
func composeQuery(keywords string, analyzers []string) *query.DisjunctionQuery {
langCompoundQuery := bleve.NewDisjunctionQuery()

for _, lang := range languages {
for _, analyzer := range analyzers {
noStopWordsAnalyzer := analyzer
if analyzer != defaultAnalyzer {
noStopWordsAnalyzer = analyzer + "_no_stop_words"
}

qt := bleve.NewMatchPhraseQuery(keywords)
qt.Analyzer = lang + "_no_stop_words"
qt.Analyzer = noStopWordsAnalyzer
qt.SetField("Title")
langCompoundQuery.AddQuery(qt)

qs := bleve.NewMatchQuery(keywords)
qs.Analyzer = lang + "_no_stop_words"
qs.Analyzer = noStopWordsAnalyzer
qs.SetField("Series")
qs.Operator = query.MatchQueryOperatorAnd
langCompoundQuery.AddQuery(qs)

qu := bleve.NewMatchQuery(keywords)
qu.Analyzer = lang
qu.Analyzer = analyzer
qu.SetField("Subjects")
qu.Operator = query.MatchQueryOperatorAnd
langCompoundQuery.AddQuery(qu)

qd := bleve.NewMatchQuery(keywords)
qd.Analyzer = lang
qd.Analyzer = analyzer
qd.SetField("Description")
qd.Operator = query.MatchQueryOperatorAnd
langCompoundQuery.AddQuery(qd)
Expand Down
8 changes: 6 additions & 2 deletions internal/index/bleve_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"log"
"os"
"path/filepath"
"slices"
"strings"

"github.com/gosimple/slug"
Expand Down Expand Up @@ -62,7 +63,6 @@ func (b *BleveIndexer) AddLibrary(fs afero.Fs, batchSize int) error {
batchSlugs[document.Slug] = struct{}{}
languages = addLanguage(meta.Language, languages)

fmt.Printf("File: %s, Slug: %s\n", document.ID, document.Slug)
err = batch.Index(document.ID, document)
if err != nil {
log.Printf("Error indexing file %s: %s\n", fullPath, err)
Expand All @@ -83,7 +83,11 @@ func (b *BleveIndexer) AddLibrary(fs afero.Fs, batchSize int) error {
}

func addLanguage(lang string, languages []string) []string {
if _, ok := noStopWordsFilters[lang]; lang != "" && ok {
if !slices.Contains(languages, defaultAnalyzer) && lang == "" {
return append(languages, defaultAnalyzer)
}

if _, ok := noStopWordsFilters[lang]; ok {
found := false
for i := range languages {
if languages[i] == lang {
Expand Down

0 comments on commit 7821862

Please sign in to comment.