]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/atom-space-pen-views/node_modules/fuzzaldrin/lib/scorer.js
c9198ed34aba90f670eeb62b1a1322c9284a3bf2
2 var PathSeparator
, queryIsLastPathSegment
;
4 PathSeparator
= require('path').sep
;
6 exports
.basenameScore = function(string
, query
, score
) {
7 var base
, depth
, index
, lastCharacter
, segmentCount
, slashCount
;
8 index
= string
.length
- 1;
9 while (string
[index
] === PathSeparator
) {
13 lastCharacter
= index
;
16 if (string
[index
] === PathSeparator
) {
19 base
= string
.substring(index
+ 1, lastCharacter
+ 1);
21 } else if (index
=== 0) {
22 if (lastCharacter
< string
.length
- 1) {
24 base
= string
.substring(0, lastCharacter
+ 1);
34 if (base
=== string
) {
37 score
+= exports
.score(base
, query
);
39 segmentCount
= slashCount
+ 1;
40 depth
= Math
.max(1, 10 - segmentCount
);
41 score
*= depth
* 0.01;
45 exports
.score = function(string
, query
) {
46 var character
, characterScore
, indexInQuery
, indexInString
, lowerCaseIndex
, minIndex
, queryLength
, queryScore
, stringLength
, totalCharacterScore
, upperCaseIndex
, _ref
;
47 if (string
=== query
) {
50 if (queryIsLastPathSegment(string
, query
)) {
53 totalCharacterScore
= 0;
54 queryLength
= query
.length
;
55 stringLength
= string
.length
;
58 while (indexInQuery
< queryLength
) {
59 character
= query
[indexInQuery
++];
60 lowerCaseIndex
= string
.indexOf(character
.toLowerCase());
61 upperCaseIndex
= string
.indexOf(character
.toUpperCase());
62 minIndex
= Math
.min(lowerCaseIndex
, upperCaseIndex
);
63 if (minIndex
=== -1) {
64 minIndex
= Math
.max(lowerCaseIndex
, upperCaseIndex
);
66 indexInString
= minIndex
;
67 if (indexInString
=== -1) {
71 if (string
[indexInString
] === character
) {
72 characterScore
+= 0.1;
74 if (indexInString
=== 0 || string
[indexInString
- 1] === PathSeparator
) {
75 characterScore
+= 0.8;
76 } else if ((_ref
= string
[indexInString
- 1]) === '-' || _ref
=== '_' || _ref
=== ' ') {
77 characterScore
+= 0.7;
79 string
= string
.substring(indexInString
+ 1, stringLength
);
80 totalCharacterScore
+= characterScore
;
82 queryScore
= totalCharacterScore
/ queryLength
;
83 return ((queryScore
* (queryLength
/ stringLength
)) + queryScore
) / 2;
86 queryIsLastPathSegment = function(string
, query
) {
87 if (string
[string
.length
- query
.length
- 1] === PathSeparator
) {
88 return string
.lastIndexOf(query
) === string
.length
- query
.length
;