Skip to content

Commit

Permalink
Remove exact match from wildcard (#64)
Browse files Browse the repository at this point in the history
* Do not add exact match terms to wildcard question

* Ignore words shorter than 3 letters in wildcard query
  • Loading branch information
bastianjoel authored Nov 22, 2023
1 parent ee0b502 commit 762554a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions pkg/search/textindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,16 +382,30 @@ type Answer struct {
MatchedWords map[string][]string
}

func filterExactMatchTerms(question string) string {
exactmatchFiltered := bytes.Buffer{}
throwAway := false
for _, w := range question {
if w == '"' {
throwAway = !throwAway
} else if !throwAway {
exactmatchFiltered.WriteRune(w)
}
}

return exactmatchFiltered.String()
}

// 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))
}()

var wildcardQuestion bytes.Buffer
for _, w := range strings.Split(question, " ") {
if w[0] != byte('*') && w[len(w)-1] != byte('*') {
wildcardQuestion := bytes.Buffer{}
for _, w := range strings.Split(filterExactMatchTerms(question), " ") {
if len(w) > 2 && w[0] != byte('*') && w[len(w)-1] != byte('*') {
wildcardQuestion.WriteString("*" + strings.ToLower(w) + "* ")
}
}
Expand Down

0 comments on commit 762554a

Please sign in to comment.