Skip to content

Commit bf3aa51

Browse files
committed
Close unclosed quotes in question
1 parent 762554a commit bf3aa51

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/search/textindex.go

+17
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,30 @@ func filterExactMatchTerms(question string) string {
396396
return exactmatchFiltered.String()
397397
}
398398

399+
// Terminates unclosed quotes
400+
func cleanupQuestion(question string) string {
401+
hasUnclosedQuote := false
402+
for _, w := range question {
403+
if w == '"' {
404+
hasUnclosedQuote = !hasUnclosedQuote
405+
}
406+
}
407+
408+
if hasUnclosedQuote {
409+
return question + "\""
410+
}
411+
412+
return question
413+
}
414+
399415
// Search queries the internal index for hits.
400416
func (ti *TextIndex) Search(question string, collections []string, meetingID int) (map[string]Answer, error) {
401417
start := time.Now()
402418
defer func() {
403419
log.Debugf("searching for %q took %v\n", question, time.Since(start))
404420
}()
405421

422+
question = cleanupQuestion(question)
406423
wildcardQuestion := bytes.Buffer{}
407424
for _, w := range strings.Split(filterExactMatchTerms(question), " ") {
408425
if len(w) > 2 && w[0] != byte('*') && w[len(w)-1] != byte('*') {

0 commit comments

Comments
 (0)