-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·55 lines (45 loc) · 1.7 KB
/
index.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
#! /usr/bin/env node
var fs = require('fs');
var _ = require('lodash');
var Table = require('cli-table');
var figures = require('figures');
var algoliasearch = require('algoliasearch');
var each = _.each;
var filter = _.filter;
var map = _.map;
var client = algoliasearch('MI4MSOKC78', '20dc1cdfee4ce4a4573f2a648ea97d79');
var index = client.initIndex('images');
var table = new Table({
head: ['ID', 'Date', 'GID', 'isImageLbb', 'Tags 3', 'Tags 2', 'Tag', 'ETags A', 'ETags B'],
colWidths: [9, 8, 7, 10, 8, 8, 7, 9, 9]
});
function tagsMatchingQuery (tags) {
return filter(map(tags, function (tag) {
switch (tag.matchLevel) {
case 'full':
return figures.circleFilled;
break;
case 'partial':
return figures.circleDotted;
break;
default:
return false;
}
}));
}
function pad (n){
return n < 10 ? '0' + n : n;
}
var currentTime = new Date();
var ym = process.argv[3] || currentTime.getFullYear() + pad(currentTime.getMonth() + 1);
index.search(process.argv[2], {
hitsPerPage: 999,
facetFilters: [
'ym:' + ym
]
}, function searchDone(err, contents) {
each(contents.hits, function (row) {
table.push([row.objectID, row.ym.substring(4, 6) + '/' + row.ym.substring(2, 4), row.gid, row.isImageLbb ? figures.tick : figures.cross, tagsMatchingQuery(row._highlightResult.tags3).join(''), tagsMatchingQuery(row._highlightResult.tags2).join(''), tagsMatchingQuery(row._highlightResult.tags1).join(''), tagsMatchingQuery(row._highlightResult.etagsA).join(''), tagsMatchingQuery(row._highlightResult.etagsB).join('')]);
});
console.log(table.toString());
});