Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Increase the boost for prefix matches. #3493

Merged
merged 3 commits into from
Apr 24, 2013
Merged

Conversation

dangoor
Copy link
Contributor

@dangoor dangoor commented Apr 19, 2013

This is a fix for #3411 and is going to be useful for code hinting.

I'll note that this also improves an older test case where "jsu" matches JSLintUtils.js before "JSUtils.js".

This is a fix for #3411 and is going to be useful for code hinting
@ghost ghost assigned peterflynn Apr 19, 2013
// of the name
if (c - numConsecutive === lastSegmentStart) {
newPoints += BEGINNING_OF_NAME_POINTS;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little confused about how to interpret numConsecutive. If I'm reading the code correctly, it only means "number of consecutive characters" if the consecutive run started on a special char -- otherwise it is always 1.

I think the code here still works correctly, since segment start is always a special (I can't think of any way to get a false positive or negative). But it does make the code more confusing.

What if we change it so numConsecutive is always incremented, so it means what it says, and then have something like:

var pointMultiplier = currentRangeStartedOnSpecial ? numConsecutive : 1;
...
newPoints += CONSECUTIVE_MATCHES_POINTS * pointMultiplier;

@peterflynn
Copy link
Member

I found a couple cases where the order seems worse than before:

  • "trange" used to place "TextRange" at the top; now it's 5th. At the top is "src/extensions/default/JavaScriptQuickEdit/unittest-files/jquery-ui/demos/slider/range.html" which seems much more tenuous.
  • "smatch" used to place "StringMatch" at the top; now it's 4th, behind things like "src/thirdparty/CodeMirror2/addon/edit/matchhighlighter.html"
  • "fim" now ranks "FileSyncManager" above "FileIndexManager"

I think you could fix the first two by limiting the new bonus to just the first match range. That should preserve the contiguous-prefix weighting we want for code hinting.

The last case doesn't bother me as much since the ideal match only fell one slot and the one above it isn't that different. I think for cases like that we could eventually give a bonus to consecutive special matches that leave no unmatched specials between them (e.g. credit them with some percentage of the bonus you'd get for a contiguous match spanning all the chars between those two specials, since the way we're interpreting it that's what the user meant to match when they typed the two specials in a row). But certainly not needed now :-)

@peterflynn
Copy link
Member

@dangoor done reviewing

In the process, I tweaked the bonuses to keep things ordered well.
@dangoor
Copy link
Contributor Author

dangoor commented Apr 23, 2013

Thanks for the feedback!

I think that the meaning of numConsecutive must have been inadvertently changed during the initial review cycle for StringMatch. I've just committed a change which makes numConsecutive actually mean number of consecutive matches and not just number of consecutive matches since a special. There is an added bonus for consecutive matches after a special. I had to tweak the bonuses a bit to go along with the new definition, and the existing test cases pass.

My tweaks fixed the "trange" case that you cite, and I added a test case for that.

I agree that the "fim" case is not clearly in favor of one over the other and we could probably fashion a boost that helps there..

"smatch" is trickier. My tweaks moved StringMatch to 3rd place, giving the edge to matches that have the "s" at the beginning and "match" at the beginning of the name. Though we know that almost everything we care about is in the "src" directory and don't care much about that "s" match at the beginning, that wouldn't necessarily be true of other projects and those top two matches for "smatch" are perfectly reasonable.

I like the idea of a "contiguous specials" bonus, but I worry that such a bonus would push "scrollTop" back over "str" when searching for "st". It makes me wonder if there should be some small amount of configuration of stringMatch scoring so that the rules could be tweaked for code hinting vs. filename matching. Or, maybe the rules are different if the string being matched is just a name without a path?

if (DEBUG_SCORES) {
scoreDebug.beginning += BEGINNING_OF_NAME_POINTS;
}
newPoints += BEGINNING_OF_NAME_POINTS;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the order of these two additions is the opposite of the other pairs here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops sorry, that comment was intended for the next block of code, on line 579...

@peterflynn
Copy link
Member

@dangoor New scoring works great for me! Two nits above but that's it.

@dangoor
Copy link
Contributor Author

dangoor commented Apr 24, 2013

@peterflynn Good suggestions! It does make the code more readable. Changes implemented in 1552890

@peterflynn
Copy link
Member

Sweet! Merging.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants