-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathminisearch.js
57 lines (47 loc) · 1.06 KB
/
minisearch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const MiniSearch = require('minisearch')
const ItemsJS = require('./../index');
const documents = [{
id: 1,
title: 'Moby Dick',
text: 'Call me Ishmael. Some years ago...',
category: 'fiction'
},
{
id: 2,
title: 'Zen and the Art of Motorcycle Maintenance',
text: 'I can see by my watch...',
category: 'fiction'
},
{
id: 3,
title: 'Neuromancer',
text: 'The sky above the port was...',
category: 'fiction'
},
{
id: 4,
title: 'Zen and the Art of Archery',
text: 'At first sight it must seem...',
category: 'non-fiction'
}
];
let miniSearch = new MiniSearch({
fields: ['title', 'text'],
storeFields: ['title', 'category']
});
// Index all documents
miniSearch.addAll(documents);
const itemsjs = require('./../index')(documents, {
aggregations: {
category: {}
}
});
// Search with default options
let results = miniSearch.search('zen art motorcycle')
console.log(results);
const ids = results.map(v => v.id);
console.log(ids);
const result = itemsjs.search({
ids: ids
})
console.log(result);