From 93ddb893f80f34b4df1b09442c531cb8f64f23cc Mon Sep 17 00:00:00 2001 From: Bastian Rihm Date: Thu, 23 Nov 2023 14:07:32 +0100 Subject: [PATCH] Close unclosed quotes in question (#66) --- pkg/search/textindex.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/search/textindex.go b/pkg/search/textindex.go index e38f2e2..c857310 100644 --- a/pkg/search/textindex.go +++ b/pkg/search/textindex.go @@ -396,6 +396,22 @@ func filterExactMatchTerms(question string) string { return exactmatchFiltered.String() } +// Terminates unclosed quotes +func cleanupQuestion(question string) string { + hasUnclosedQuote := false + for _, w := range question { + if w == '"' { + hasUnclosedQuote = !hasUnclosedQuote + } + } + + if hasUnclosedQuote { + return question + "\"" + } + + return question +} + // Search queries the internal index for hits. func (ti *TextIndex) Search(question string, collections []string, meetingID int) (map[string]Answer, error) { start := time.Now() @@ -403,6 +419,7 @@ func (ti *TextIndex) Search(question string, collections []string, meetingID int log.Debugf("searching for %q took %v\n", question, time.Since(start)) }() + question = cleanupQuestion(question) wildcardQuestion := bytes.Buffer{} for _, w := range strings.Split(filterExactMatchTerms(question), " ") { if len(w) > 2 && w[0] != byte('*') && w[len(w)-1] != byte('*') {