fuzzyset.js
Advanced tools
Comparing version 0.0.2 to 0.0.3
(function() { | ||
var FuzzySet = function(arr, useLevenshtein, gramSizeLower, gramSizeUpper) { | ||
var fuzzyset = {}; | ||
var fuzzyset = { | ||
version: '0.0.1' | ||
}; | ||
@@ -86,5 +88,8 @@ // default options | ||
// the main functions | ||
fuzzyset.get = function(value, defaultValue) { | ||
fuzzyset.get = function(value, defaultValue, minMatchScore) { | ||
// check for value in set, returning defaultValue or null if none found | ||
var result = this._get(value); | ||
if (minMatchScore === undefined) { | ||
minMatchScore = .33 | ||
} | ||
var result = this._get(value, minMatchScore); | ||
if (!result && typeof defaultValue !== 'undefined') { | ||
@@ -96,3 +101,3 @@ return defaultValue; | ||
fuzzyset._get = function(value) { | ||
fuzzyset._get = function(value, minMatchScore) { | ||
var normalizedValue = this._normalizeStr(value), | ||
@@ -107,3 +112,3 @@ result = this.exactSet[normalizedValue]; | ||
for (var gramSize = this.gramSizeUpper; gramSize >= this.gramSizeLower; --gramSize) { | ||
results = this.__get(value, gramSize); | ||
results = this.__get(value, gramSize, minMatchScore); | ||
if (results) { | ||
@@ -116,3 +121,3 @@ return results; | ||
fuzzyset.__get = function(value, gramSize) { | ||
fuzzyset.__get = function(value, gramSize, minMatchScore) { | ||
var normalizedValue = this._normalizeStr(value), | ||
@@ -186,7 +191,7 @@ matches = {}, | ||
var newResults = []; | ||
for (var i = 0; i < results.length; ++i) { | ||
if (results[i][0] == results[0][0]) { | ||
newResults.push([results[i][0], this.exactSet[results[i][1]]]); | ||
results.forEach(function(scoreWordPair) { | ||
if (scoreWordPair[0] >= minMatchScore) { | ||
newResults.push([scoreWordPair[0], this.exactSet[scoreWordPair[1]]]); | ||
} | ||
} | ||
}.bind(this)) | ||
return newResults; | ||
@@ -193,0 +198,0 @@ }; |
{ | ||
"name":"fuzzyset.js", | ||
"description":"A fuzzy string set for JavaScript", | ||
"version":"0.0.2", | ||
"version":"0.0.3", | ||
"homepage":"http://Glench.github.com/fuzzyset.js", | ||
@@ -6,0 +6,0 @@ "repository":"git://github.com/Glench/fuzzyset.js.git", |
Sorry, the diff of this file is not supported yet
14972
264