forked from LockerProject/Locker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearcher.js
69 lines (65 loc) · 2.64 KB
/
searcher.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
58
59
60
61
62
63
64
65
66
67
68
69
var repl = require('repl');
require.paths.push('./Common/node');
var lconfig = require('lconfig');
lconfig.load('Config/config.json');
var lsearch = require('lsearch');
lsearch.setIndexPath('./Me/search/search.index');
lsearch.setEngine(lsearch.engines.CLucene);
var myrepl = repl.start('lockersearch> ');
var ctx = myrepl.context;
ctx.search = lsearch;
ctx.indexType = function(type, object) {
lsearch.indexType(type, object,
function(err, time) {
if (err) {
console.log('Error: ' + err);
return;
}
console.log('Indexed document in ' + time);
});
};
ctx.queryType = function(type, query) {
lsearch.queryType(type, query, {}, function(err, results) {
if (err) {
console.log('Error: ' + err);
return;
}
console.log('Found ' + results.length + ' results:');
for (var i in results) {
console.log(results[i]);
}
});
};
ctx.setIndexPath = function(path) {
lsearch.setIndexPath(path);
console.log("OK");
};
ctx.queryAll = function(query) {
lsearch.queryAll(query, {}, function(err, results) {
if (err) {
console.log('Error: ' + err);
return;
}
console.log('Found ' + results.length + ' results:');
for (var i in results) {
console.log(results[i]);
}
});
};
ctx.query = ctx.queryAll;
ctx.help = function() {
console.log('\n'+
'LOCKERSEARCH HELP:\n\n'+
' - help() -- shows this help screen\n\n'+
// ' - queryAll("query") -- will search "query" across all types\n\n'+
' - queryType("type", "query") -- will search "query" for only the given top-level service type\n\n'+
' - indexType("type", object) -- will index the object for the given type.\n\n\n'+
' NOTES:\n\n'+
' - Query strings *almost* adhere to version 2.3 of the Lucene queryparser syntax. The only thing that diverges from the spec is the handling of field names. For more information on the Lucene query parser syntax, see: http://lucene.apache.org/java/2_3_2/queryparsersyntax.html\n'+
' - Currently, the only types supported are the following: contact, message\n'+
' - In order to index an object of a given type, you must follow the mapping rules for that given type. Below are the mappings for the three types:\n'+
' contact: {"_id":<string>, "name":<string>, "nickname":<string>, "email":[{"type":<string>, "value":<string>}]}\n'+
' - In addition to each type\'s required fields, you must include one global field called _id. _id is the Locker UUID of the particular object you are indexing\n');
myrepl.displayPrompt();
};
ctx.help();