Skip to content

Commit

Permalink
Merge 84c8dde into 367c740
Browse files Browse the repository at this point in the history
  • Loading branch information
sreekanth-cb committed Dec 3, 2018
2 parents 367c740 + 84c8dde commit d240a15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions search/searcher/search_fuzzy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func NewFuzzySearcher(indexReader index.IndexReader, term string,
return nil, fmt.Errorf("fuzziness exceeds max (%d)", MaxFuzziness)
}

if fuzziness < 0 {
return nil, fmt.Errorf("invalid fuzziness, negative")
}

// Note: we don't byte slice the term for a prefix because of runes.
prefixTerm := ""
for i, r := range term {
Expand Down
13 changes: 13 additions & 0 deletions search/searcher/search_fuzzy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,16 @@ func TestFuzzySearch(t *testing.T) {
}
}
}

func TestFuzzySearchLimitErrors(t *testing.T) {
explainTrue := search.SearcherOptions{Explain: true}
_, err := NewFuzzySearcher(nil, "water", 3, 3, "desc", 1.0, explainTrue)
if err == nil {
t.Fatal("`fuzziness exceeds max (2)` error expected")
}

_, err = NewFuzzySearcher(nil, "water", 3, -1, "desc", 1.0, explainTrue)
if err == nil {
t.Fatal("`invalid fuzziness, negative` error expected")
}
}

0 comments on commit d240a15

Please sign in to comment.