Skip to content

Commit

Permalink
Improve IndicPhone tsquery algorithm for better results.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Nov 12, 2023
1 parent a6caf93 commit cde7b57
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tokenizers/indicphone/indicphone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package indicphone
import (
"errors"
"fmt"
"slices"
"strings"

"github.com/knadh/dictpress/internal/data"
Expand Down Expand Up @@ -75,9 +76,16 @@ func (ip *IndicPhone) ToQuery(s string, lang string) (string, error) {
return "", nil
}

if key0 != key1 {
tokens := slices.Compact([]string{key2, key1, key0})

switch len(tokens) {
case 1:
return tokens[0], nil
case 2:
return fmt.Sprintf("%s | %s ", tokens[0], tokens[1]), nil
case 3:
return fmt.Sprintf("%s | (%s & %s) ", key2, key1, key0), nil
}

return fmt.Sprintf("%s", key0), nil
return key0, nil
}

0 comments on commit cde7b57

Please sign in to comment.