trie-search
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -6,3 +6,3 @@ { | ||
"description": "A trie implementation that maps keys to objects for rapid retrieval by phrases. Most common use will be for typeahead searches.", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "index.js", | ||
@@ -12,2 +12,8 @@ "url": "https://github.com/joshjung/trie-search", | ||
"email": "joshua.p.jung@gmail.com", | ||
"scripts": { | ||
"test": "mocha", | ||
"release:major": "npm version major && git push --follow-tags && npm publish", | ||
"release:minor": "npm version minor && git push --follow-tags && npm publish", | ||
"release:patch": "npm version patch && git push --follow-tags && npm publish" | ||
}, | ||
"repository": { | ||
@@ -14,0 +20,0 @@ "type": "git", |
@@ -25,9 +25,11 @@ var HashArray = require('hasharray'); | ||
TrieSearch.prototype = { | ||
add: function (obj) { | ||
add: function (obj, customKeys) { | ||
if (this.options.cache) | ||
this.clearCache(); | ||
for (var k in this.keyFields) | ||
var keyFields = customKeys || this.keyFields; | ||
for (var k in keyFields) | ||
{ | ||
var key = this.keyFields[k], | ||
var key = keyFields[k], | ||
isKeyArr = key instanceof Array, | ||
@@ -34,0 +36,0 @@ val = isKeyArr ? deepLookup(obj, key) : obj[key]; |
@@ -457,2 +457,33 @@ var assert = require('assert'), | ||
}); | ||
describe('TrieSearch::add(...) and TrieSearch::get(...) should work with customKeys', function() { | ||
var ts = new TrieSearch('key', {min: 2}), | ||
item1 = {customKey1: 'I am item1!', customKey2: '123'}, | ||
item2 = {customKey1: 'I am item2!', customKey2: '456'}; | ||
ts.add(item1, ['customKey1']); | ||
ts.add(item2, ['customKey1', 'customKey2']); | ||
it('add(item1) and add(item2) should build map of nodes', function() { | ||
assert(ts.root['i'] === undefined, 'I should not exist!'); | ||
assert(ts.root['am'] !== undefined, 'am does not exist'); | ||
assert(ts.root['it']['e']['m']['1'] !== undefined, 'item1 does not exist'); | ||
assert(ts.root['it']['e']['m']['2'] !== undefined, 'item2 does not exist'); | ||
assert(ts.root['12'] === undefined, 'item1 should not exist on search for 123'); | ||
assert(ts.root['45']['6'] !== undefined, 'item2 does not exist on search for 456'); | ||
}); | ||
it('get(\'i\') should return 0 items', function() { | ||
assert(ts.get('i').length == 0, 'did not return 0 items!'); | ||
assert(ts.get('item').length == 2, 'did not return 2 items!'); | ||
}); | ||
it('get(\'123\') should return 0 items', function() { | ||
assert(ts.get('123').length == 0, 'did not return 0 items!'); | ||
}); | ||
it('get(\'45\') should return 1 items', function() { | ||
assert(ts.get('456').length == 1, 'did not return 0 items!'); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8991850
1568