From b7305897f1c6d6f499003657b352ccbe6ed1faba Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sat, 30 Aug 2014 19:26:22 -0700 Subject: scoring: Prefer consecutive matches --- README.md | 4 ++-- fzytest.c | 8 ++++---- match.c | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 32b1f7a..587ebc1 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,10 @@ nnoremap s :call FzyCommand("ag . --no-color -l -g ''", ":sp") fzy attempts to present the best matches first. The following considerations are weighted when sorting: -It prefers matching the beginning of words: `amo` is likely to match app/models/order.rb. - It prefers consecutive characters: `file` will match file over filter. +It prefers matching the beginning of words: `amp` is likely to match app/models/posts.rb. + It prefers shorter matches: `abce` matches abcdef over abc de. It prefers shorter candidates: `test` matches tests over testing. diff --git a/fzytest.c b/fzytest.c index a0620f5..3842920 100644 --- a/fzytest.c +++ b/fzytest.c @@ -29,8 +29,8 @@ int test_match(){ } int test_scoring(){ - /* App/Models/Order is better than App/MOdels/foo */ - assert(match("amo", "app/models/foo") < match("amo", "app/models/order")); + /* App/Models/Order is better than App/MOdels/zRder */ + assert(match("amor", "app/models/order") > match("amor", "app/models/zrder")); /* App/MOdels/foo is better than App/M/fOo */ assert(match("amo", "app/m/foo") < match("amo", "app/models/foo")); @@ -72,8 +72,8 @@ int test_positions_2(){ * We should prefer matching the 'o' in order, since it's the beginning * of a word. */ - size_t positions[3]; - match_positions("amo", "app/models/order", positions); + size_t positions[4]; + match_positions("amor", "app/models/order", positions); assert(positions[0] == 0); assert(positions[1] == 4); assert(positions[2] == 11); diff --git a/match.c b/match.c index ee0b066..0c50eb7 100644 --- a/match.c +++ b/match.c @@ -77,10 +77,10 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio #define SCORE_GAP_TRAILING -0.005 #define SCORE_GAP_INNER -0.01 #define SCORE_MATCH_CONSECUTIVE 1.0 -#define SCORE_MATCH_SLASH 1.5 -#define SCORE_MATCH_WORD 1.2 -#define SCORE_MATCH_CAPITAL 1.1 -#define SCORE_MATCH_DOT 0.8 +#define SCORE_MATCH_SLASH 0.9 +#define SCORE_MATCH_WORD 0.8 +#define SCORE_MATCH_CAPITAL 0.7 +#define SCORE_MATCH_DOT 0.6 /* Which positions are beginning of words */ char last_ch = '\0'; -- cgit v1.2.3