On Do, 15 Okt 2020, Yegappan Lakshmanan wrote:

> Hi Christian,
> 
> On Thu, Oct 15, 2020 at 8:55 AM Christian Brabandt <[email protected]> wrote:
> 
> 
>     On Do, 15 Okt 2020, Yegappan Lakshmanan wrote:
> 
>     > Hi,
>     >
>     > On Wed, Oct 14, 2020 at 11:21 PM Maxim Kim <[email protected]> wrote:
>     >
>     >     Hi, I wonder why "better" candidate has lower score than the others:
>     >
>     >     https://i.imgur.com/NPhKNsZ.png
>     >
>     >     tried to search `vimrc` and `.vim/vimrc` has lower score than `.vim/
>     >     vimrc_colors`.
>     >
>     >
>     >
>     >
>     > The reason is that 'vimrc' matches in multiple places in '.vim/vimrc' 
> and
>     > '.vim/vimrc_colors'. The scores for the various matches is below:
>     >
>     > For '.vim/vimrc':
>     >
>     >     'xxxxxvimrc'   140
>     >     'xvxxxximrc'   135
>     >     'xvimxxxxrc'   135
>     >
>     > For '.vim/vimrc_colors':
>     >
>     >     xxxxxvimrxxcxxxxx 148
>     >     xxxxxvimrcxxxxxxx 133
>     >     xvimxxxxrcxxxxxxx 128
>     >
>     > As you can see from the scores above, the match in '.vim/vimrc_colors'
>     > has a higher score because of the "c" that occurs after an underscore.
>     >
>     > The match that occurs immediately after an underscore is given an
>     additional
>     > bonus score.
> 
>     Yeah, but shouldn't a complete match get an additional bonus?
> 
> 
> 
> 
> Yes. A complete sequential match should get an additional bonus. But the
> changes you posted only checks for whether the previous character is matched
> and it doesn't check for a complete match. For example, when searching
> for 'abc' in 'xabcy' and 'axxxxbc', it will give preference to axxxxbc than
> xabcy.

Indeed. Initially I thought adding a bonus for a word boundary would be
needed, therefore my naive attempt to score additionally on the end of
the match. So how about this, which adds an additional bonus only for a
complete match.

iff --git a/src/search.c b/src/search.c
index 349eae035..d7adcc59f 100644
--- a/src/search.c
+++ b/src/search.c
@@ -4257,6 +4257,8 @@ typedef struct
 // bonus if match occurs after a separator
 #define SEPARATOR_BONUS 30
 // bonus if match is uppercase and prev is lower
+#define ENDMATCH_SEQUENTIAL_BONUS 35
+// bonus if match is sequential and ends the match string
 #define CAMEL_BONUS 30
 // bonus if the first letter is matched
 #define FIRST_LETTER_BONUS 15
@@ -4292,6 +4294,7 @@ fuzzy_match_compute_score(
     int                i;
     char_u     *p = str;
     matchidx_T sidx = 0;
+    int                full_match = 0;
 
     // Initialize score
     score = 100;
@@ -4317,7 +4320,10 @@ fuzzy_match_compute_score(
 
            // Sequential
            if (currIdx == (prevIdx + 1))
+           {
                score += SEQUENTIAL_BONUS;
+               full_match++;
+           }
        }
 
        // Check for bonuses based on neighbor character value
@@ -4358,6 +4364,10 @@ fuzzy_match_compute_score(
            score += FIRST_LETTER_BONUS;
        }
     }
+
+    if (full_match == numMatches-1)
+       score += ENDMATCH_SEQUENTIAL_BONUS;
+           // End of match
     return score;
 }
 


Mit freundlichen Grüßen
Christian
-- 
Jede Bedrängnis ist nur ein Engpass zu einer Weite.
                -- Johannes Müller

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20201015163347.GL1656%40256bit.org.

Raspunde prin e-mail lui