example.js (1018B)
1 const lucene = require('./src/index')(require('lucene')); 2 let result; 3 4 const data = [ 5 { name: 'C-3PO' , description: 'Protocol droid.' , species: 'Droid' }, 6 { name: 'R2-D2' , description: 'Astromech droid built on Naboo.', species: 'Droid' }, 7 { name: 'Anakin Skywalker', description: 'Fallen Jedi, the chosen one.' , species: 'Human' }, 8 { name: 'Obi-Wan Kenobi' , description: 'Jedi Master.' , species: 'Human' }, 9 { name: 'Moon Moon' , description: 'Mentally challenged wolf.' , species: 'Wolf' }, 10 ]; 11 12 // Prints an array with both R2-D2 and C-3PO 13 console.log(data.filter(lucene('species: droid'))); 14 15 // Prints an array with only R2-D2 16 console.log(data.filter(lucene('astromech'))); 17 18 // Prints an array with both jedi 19 console.log(data.filter(lucene('jedi'))); 20 21 // Prints an array with only the outcast 22 console.log(data.filter(lucene('name: "moon moon"'))); 23 24 // Prints Obi-Wan 25 console.log(data.filter(lucene('species: human AND master')));