Skip to content

Commit

Permalink
make it configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
CascadingRadium committed Nov 19, 2024
1 parent bc1f7d3 commit fedbf78
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions search/searcher/search_fuzzy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ import (

var MaxFuzziness = 2

// AutoFuzzinessHighThreshold is the threshold for the term length
// above which the fuzziness is set to MaxFuzziness when the fuzziness
// mode is set to AutoFuzziness.
var AutoFuzzinessHighThreshold = 5

// AutoFuzzinessLowThreshold is the threshold for the term length
// below which the fuzziness is set to zero when the fuzziness mode
// is set to AutoFuzziness.
// For terms with length between AutoFuzzinessLowThreshold and
// AutoFuzzinessHighThreshold, the fuzziness is set to
// MaxFuzziness - 1.
var AutoFuzzinessLowThreshold = 2

func NewFuzzySearcher(ctx context.Context, indexReader index.IndexReader, term string,
prefix, fuzziness int, field string, boost float64,
options search.SearcherOptions) (search.Searcher, error) {
Expand Down Expand Up @@ -86,10 +99,10 @@ func NewFuzzySearcher(ctx context.Context, indexReader index.IndexReader, term s

func getAutoFuzziness(term string) int {
termLength := len(term)
if termLength > 5 {
return 2
} else if termLength > 2 {
return 1
if termLength > AutoFuzzinessHighThreshold {
return MaxFuzziness
} else if termLength > AutoFuzzinessLowThreshold {
return MaxFuzziness - 1
}
return 0
}
Expand Down

0 comments on commit fedbf78

Please sign in to comment.