forked from hackervera/node-lucene
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
57 lines (52 loc) · 1.37 KB
/
test.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
var assert = require("assert");
var cl = require("./clucene").CLucene;
var lucene = new cl.Lucene();
var doc = new cl.Document();
lucene.addDocument(doc, "/private/var/virusmails/test.lc", function(err, indexTime) {
assert.ok(err != null);
});
var hadError = false;
try {
doc.addField(1, "test", 65);
} catch (E) {
hadError = true;
}
assert.ok(hadError);
hadError = false;
try {
doc.addField("correct", 1, 65);
} catch (E) {
hadError = true;
}
assert.ok(hadError);
hadError = false;
try {
doc.addField("correct", "correct", "test");
} catch (E) {
hadError = true;
}
assert.ok(hadError);
hadError = false;
try {
doc.addField("id", "", 100);
} catch(E) {
hadError = true;
}
assert.ok(hadError);
hadError = false;
doc.addField("_id", "1234", 65);
doc.addField("name", "Thomas Muldowney", 33);
lucene.addDocument(doc, "test.lc", function(err, indexTime) {
console.log("Time to index: " + indexTime + " ms.");
lucene.search("bad.lc", "*:*", function(err, results) {
assert.equal(results, null);
lucene.search("test.lc", "bad:bad:bad", function(err, results) {
assert.equal(results, null);
lucene.search("test.lc", "name:Muld*", function(err, results) {
assert.ifError(err);
console.log("Results:");
console.dir(results);
});
});
});
});