Qualia lasr
Like lunr, but more focused. Provides search across arrays of objects.
Usage
1import lasr from 'meteor/qualia:lasr'; 2 3const people = [ 4 { 5 _id: 'fireman', 6 name: 'The Fireman', 7 skills: [ 8 { 9 name: 'Firemaking', 10 level: 9000, 11 }, 12 { 13 name: 'Watering', 14 level: 9001, 15 }, 16 ] 17 }, 18 { 19 _id: 'mage', 20 name: 'The Mage', 21 skills: [ 22 { 23 name: 'Magicking', 24 level: 42, 25 }, 26 ] 27 }, 28 { 29 _id: 'wizard', 30 name: 'The Wizard', 31 skills: [ 32 { 33 name: 'Magic', 34 level: 41, 35 }, 36 ] 37 }, 38 { 39 _id: 'developer', 40 name: 'The Developer', 41 skills: [ 42 { 43 name: 'Typing', 44 level: 9000, 45 }, 46 { 47 name: 'Sitting', 48 level: 9001, 49 }, 50 ] 51 }, 52]; 53 54const results = lasr.search({ 55 items: people, 56 query: 'Magic', 57 keys: [ 58 'name', 59 'skills.name', 60 'skills.level', 61 ], 62 limit: 10, 63});
1results = [ 2 { 3 "item": { 4 "_id": "wizard", 5 "name": "The Wizard", 6 "skills": [ 7 { 8 "name": "Magic", 9 "level": 41 10 } 11 ] 12 }, 13 "score": 1, 14 "matches": [ 15 { 16 "key": "skills.name", 17 "value": "Magic", 18 "indices": [ 19 [ 20 0, 21 4 22 ] 23 ], 24 "score": 1 25 } 26 ] 27 }, 28 { 29 "item": { 30 "_id": "mage", 31 "name": "The Mage", 32 "skills": [ 33 { 34 "name": "Magicking", 35 "level": 42 36 } 37 ] 38 }, 39 "score": 0.5555555555555556, 40 "matches": [ 41 { 42 "key": "skills.name", 43 "value": "Magicking", 44 "indices": [ 45 [ 46 0, 47 4 48 ] 49 ], 50 "score": 0.5555555555555556 51 } 52 ] 53 } 54]
Testing this package
This package has TinyTests. To run the tests, first isolate this package from the Meteor app by copying it to its own directory. For example, to put it in your home directory:
rsync -r path/to/qualia_lasr ~/
Then run the tests from within the copied package directory:
cd ~/qualia_lasr meteor test-packages ./