From 2f6d23b91e845f53e746e7cf74477a735ec88a85 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 16 Apr 2016 14:02:43 +0900 Subject: Enhanced ranking algorithm Based on the patch by Matt Westcott (@mjwestcott). But with a more conservative approach: - Does not use linearly increasing penalties; It is agreed upon that we should prefer matching characters at the beginnings of the words, but it's not always clear that the relevance is inversely proportional to the distance from the beginning. - The approach here is more conservative in that the bonus is never large enough to override the matchlen, so it can be thought of as the first implicit tiebreak criterion. - One may argue the change breaks the contract of --tiebreak, but the judgement depends on the definition of "tie". --- src/pattern_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/pattern_test.go') diff --git a/src/pattern_test.go b/src/pattern_test.go index 6bf571cd..2f27fdab 100644 --- a/src/pattern_test.go +++ b/src/pattern_test.go @@ -70,10 +70,10 @@ func TestExact(t *testing.T) { clearPatternCache() pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("'abc")) - sidx, eidx := algo.ExactMatchNaive( + res := algo.ExactMatchNaive( pattern.caseSensitive, pattern.forward, []rune("aabbcc abc"), pattern.termSets[0][0].text) - if sidx != 7 || eidx != 10 { - t.Errorf("%s / %d / %d", pattern.termSets, sidx, eidx) + if res.Start != 7 || res.End != 10 { + t.Errorf("%s / %d / %d", pattern.termSets, res.Start, res.End) } } @@ -82,11 +82,11 @@ func TestEqual(t *testing.T) { clearPatternCache() pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("^AbC$")) - match := func(str string, sidxExpected int, eidxExpected int) { - sidx, eidx := algo.EqualMatch( + match := func(str string, sidxExpected int32, eidxExpected int32) { + res := algo.EqualMatch( pattern.caseSensitive, pattern.forward, []rune(str), pattern.termSets[0][0].text) - if sidx != sidxExpected || eidx != eidxExpected { - t.Errorf("%s / %d / %d", pattern.termSets, sidx, eidx) + if res.Start != sidxExpected || res.End != eidxExpected { + t.Errorf("%s / %d / %d", pattern.termSets, res.Start, res.End) } } match("ABC", -1, -1) -- cgit v1.2.3