提交 d6bf8879 编写于 作者: J Johannes Rieken

remove old scorer

上级 89568273
......@@ -395,88 +395,6 @@ export function createMatches(position: number[]): IMatch[] {
return ret;
}
export function fuzzyMatchAndScore(pattern: string, word: string): [number, number[]] {
if (!pattern) {
return [-1, []];
}
if (pattern.length > word.length) {
return undefined;
}
let matches: number[] = [];
let score = _matchRecursive(
pattern, pattern.toLowerCase(), pattern.toUpperCase(), 0,
word, word.toLowerCase(), 0,
matches
);
if (score <= 0) {
return undefined;
}
score -= Math.min(matches[0], 3) * 3; // penalty for first matching character
score -= (1 + matches[matches.length - 1]) - (pattern.length); // penalty for all non matching characters between first and last
return [score, matches];
}
export function _matchRecursive(
pattern: string, lowPattern: string, upPattern: string, patternPos: number,
word: string, lowWord: string, wordPos: number,
matches: number[]
): number {
if (patternPos >= lowPattern.length) {
return 0;
}
const lowPatternChar = lowPattern[patternPos];
let idx = -1;
let value = 0;
if ((patternPos === wordPos
&& lowPatternChar === lowWord[wordPos])
&& ((value = _matchRecursive(pattern, lowPattern, upPattern, patternPos + 1, word, lowWord, wordPos + 1, matches)) >= 0)
) {
matches.unshift(wordPos);
return (pattern[patternPos] === word[wordPos] ? 17 : 11) + value;
}
if ((idx = word.indexOf(upPattern[patternPos], wordPos)) >= 0
&& ((value = _matchRecursive(pattern, lowPattern, upPattern, patternPos + 1, word, lowWord, idx + 1, matches)) >= 0)
) {
matches.unshift(idx);
return (pattern[patternPos] === word[idx] ? 17 : 11) + value;
}
if ((idx = lowWord.indexOf(`_${lowPatternChar}`, wordPos)) >= 0
&& ((value = _matchRecursive(pattern, lowPattern, upPattern, patternPos + 1, word, lowWord, idx + 2, matches)) >= 0)
) {
matches.unshift(idx + 1);
return (pattern[patternPos] === word[idx + 1] ? 17 : 11) + value;
}
if ((idx = lowWord.indexOf(`.${lowPatternChar}`, wordPos)) >= 0
&& ((value = _matchRecursive(pattern, lowPattern, upPattern, patternPos + 1, word, lowWord, idx + 2, matches)) >= 0)
) {
matches.unshift(idx + 1);
return 11 + value;
}
if (patternPos > 0
&& (idx = lowWord.indexOf(lowPatternChar, wordPos)) >= 0
&& ((value = _matchRecursive(pattern, lowPattern, upPattern, patternPos + 1, word, lowWord, idx + 1, matches)) >= 0)
) {
matches.unshift(idx);
return 1 + value;
}
return -1;
}
function initTable() {
const table: number[][] = [];
const row: number[] = [0];
......
......@@ -40,7 +40,6 @@ perfSuite('Performance - fuzzyMatch', function () {
perfTest('matchesFuzzy', filters.matchesFuzzy);
perfTest('fuzzyContiguousFilter', filters.fuzzyContiguousFilter);
perfTest('matchesFuzzy2', filters.matchesFuzzy2);
perfTest('fuzzyMatchAndScore', filters.fuzzyMatchAndScore);
perfTest('fuzzyScore', filters.fuzzyScore);
});
......
......@@ -5,7 +5,7 @@
'use strict';
import * as assert from 'assert';
import { IFilter, or, matchesPrefix, matchesStrictPrefix, matchesCamelCase, matchesSubString, matchesContiguousSubString, matchesWords, fuzzyMatchAndScore, fuzzyScore } from 'vs/base/common/filters';
import { IFilter, or, matchesPrefix, matchesStrictPrefix, matchesCamelCase, matchesSubString, matchesContiguousSubString, matchesWords, fuzzyScore } from 'vs/base/common/filters';
function filterOk(filter: IFilter, word: string, wordToMatchAgainst: string, highlights?: { start: number; end: number; }[]) {
let r = filter(word, wordToMatchAgainst);
......@@ -193,7 +193,7 @@ suite('Filters', () => {
assert.deepEqual(matchesWords('pu', 'Category: Git: Pull', true), [{ start: 15, end: 17 }]);
});
function assertMatches(pattern: string, word: string, decoratedWord: string, filter: typeof fuzzyMatchAndScore) {
function assertMatches(pattern: string, word: string, decoratedWord: string, filter: typeof fuzzyScore) {
let r = filter(pattern, word);
assert.ok(Boolean(r) === Boolean(decoratedWord));
if (r) {
......@@ -208,36 +208,6 @@ suite('Filters', () => {
}
}
test('fuzzyMatchAndScore', function () {
assertMatches('no', 'match', undefined, fuzzyMatchAndScore);
assertMatches('no', '', undefined, fuzzyMatchAndScore);
assertMatches('BK', 'the_black_knight', 'the_^black_^knight', fuzzyMatchAndScore);
assertMatches('bkn', 'the_black_knight', 'the_^black_^k^night', fuzzyMatchAndScore);
assertMatches('bt', 'the_black_knight', 'the_^black_knigh^t', fuzzyMatchAndScore);
assertMatches('bti', 'the_black_knight', undefined, fuzzyMatchAndScore);
assertMatches('LLL', 'SVisualLoggerLogsList', 'SVisual^Logger^Logs^List', fuzzyMatchAndScore);
assertMatches('LLLL', 'SVisualLoggerLogsList', undefined, fuzzyMatchAndScore);
assertMatches('sllll', 'SVisualLoggerLogsList', '^SVisua^l^Logger^Logs^List', fuzzyMatchAndScore);
assertMatches('sl', 'SVisualLoggerLogsList', '^SVisual^LoggerLogsList', fuzzyMatchAndScore);
assertMatches('foobar', 'foobar', '^f^o^o^b^a^r', fuzzyMatchAndScore);
assertMatches('fob', 'foobar', '^f^oo^bar', fuzzyMatchAndScore);
assertMatches('ob', 'foobar', undefined, fuzzyMatchAndScore);
assertMatches('gp', 'Git: Pull', '^Git: ^Pull', fuzzyMatchAndScore);
assertMatches('gp', 'Git_Git_Pull', '^Git_Git_^Pull', fuzzyMatchAndScore);
assertMatches('g p', 'Git: Pull', '^Git:^ ^Pull', fuzzyMatchAndScore);
assertMatches('gip', 'Git: Pull', '^G^it: ^Pull', fuzzyMatchAndScore);
assertMatches('is', 'isValid', '^i^sValid', fuzzyMatchAndScore);
assertMatches('is', 'ImportStatement', '^Import^Statement', fuzzyMatchAndScore);
assertMatches('lowrd', 'lowWord', '^l^o^wWo^r^d', fuzzyMatchAndScore);
assertMatches('ccm', 'cacmelCase', '^ca^c^melCase', fuzzyMatchAndScore);
assertMatches('ccm', 'camelCase', undefined, fuzzyMatchAndScore);
assertMatches('ccm', 'camelCasecm', '^camel^Casec^m', fuzzyMatchAndScore);
assertMatches('myvable', 'myvariable', '^m^y^v^aria^b^l^e', fuzzyMatchAndScore);
assertMatches('fdm', 'findModel', '^fin^d^Model', fuzzyMatchAndScore);
assertMatches('form', 'editor.formatOnSave', 'editor.^f^o^r^matOnSave', fuzzyMatchAndScore);
assertMatches('KeyboardLayoutEventChange=', 'KeyboardLayoutEventChange', undefined, fuzzyMatchAndScore);
});
test('fuzzyScore', function () {
assertMatches('ab', 'abA', '^a^bA', fuzzyScore);
assertMatches('ccm', 'cacmelCase', '^ca^c^melCase', fuzzyScore);
......@@ -283,7 +253,7 @@ suite('Filters', () => {
assertMatches('Three', 'Three', '^T^h^r^e^e', fuzzyScore);
});
function assertTopScore(filter: typeof fuzzyMatchAndScore, pattern: string, expected: number, ...words: string[]) {
function assertTopScore(filter: typeof fuzzyScore, pattern: string, expected: number, ...words: string[]) {
let topScore = Number.MIN_VALUE;
let topIdx = 0;
for (let i = 0; i < words.length; i++) {
......@@ -300,44 +270,8 @@ suite('Filters', () => {
assert.equal(topIdx, expected, `${pattern} -> actual=${words[topIdx]} <> expected=${words[expected]}`);
}
test('topScore - fuzzyMatchAndScore', function () {
assertTopScore(fuzzyMatchAndScore, 'cons', 2, 'ArrayBufferConstructor', 'Console', 'console');
assertTopScore(fuzzyMatchAndScore, 'Foo', 1, 'foo', 'Foo', 'foo');
assertTopScore(fuzzyMatchAndScore, 'CC', 1, 'camelCase', 'CamelCase');
assertTopScore(fuzzyMatchAndScore, 'cC', 0, 'camelCase', 'CamelCase');
assertTopScore(fuzzyMatchAndScore, 'cC', 1, 'ccfoo', 'camelCase');
assertTopScore(fuzzyMatchAndScore, 'cC', 1, 'ccfoo', 'camelCase', 'foo-cC-bar');
// issue #17836
assertTopScore(fuzzyMatchAndScore, 'p', 0, 'parse', 'posix', 'pafdsa', 'path', 'p');
assertTopScore(fuzzyMatchAndScore, 'pa', 0, 'parse', 'pafdsa', 'path');
// issue #14583
assertTopScore(fuzzyMatchAndScore, 'log', 3, 'HTMLOptGroupElement', 'ScrollLogicalPosition', 'SVGFEMorphologyElement', 'log');
assertTopScore(fuzzyMatchAndScore, 'e', 2, 'AbstractWorker', 'ActiveXObject', 'else');
// issue #14446
assertTopScore(fuzzyMatchAndScore, 'workbench.sideb', 1, 'workbench.editor.defaultSideBySideLayout', 'workbench.sideBar.location');
// issue #11423
assertTopScore(fuzzyMatchAndScore, 'editor.r', 2, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
// assertTopScore(fuzzyMatchAndScore, 'editor.R', 1, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
// assertTopScore(fuzzyMatchAndScore, 'Editor.r', 0, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
assertTopScore(fuzzyMatchAndScore, '-mo', 1, '-ms-ime-mode', '-moz-columns');
// // dupe, issue #14861
assertTopScore(fuzzyMatchAndScore, 'convertModelPosition', 0, 'convertModelPositionToViewPosition', 'convertViewToModelPosition');
// // dupe, issue #14942
assertTopScore(fuzzyMatchAndScore, 'is', 0, 'isValidViewletId', 'import statement');
});
test('topScore - fuzzyScore', function () {
assertTopScore(fuzzyScore, 'TEdit', 1, 'TextEditorDecorationType', 'TextEdit', 'TextEditor');
assertTopScore(fuzzyScore, 'cons', 2, 'ArrayBufferConstructor', 'Console', 'console');
assertTopScore(fuzzyScore, 'Foo', 1, 'foo', 'Foo', 'foo');
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册