Skip to content

Commit

Permalink
Close unclosed quotes in question (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjoel authored Nov 23, 2023
1 parent 762554a commit 93ddb89
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/search/textindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,30 @@ 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()
defer func() {
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('*') {
Expand Down

0 comments on commit 93ddb89

Please sign in to comment.