-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsimple_query_fulltext_api.d
72 lines (60 loc) · 1.67 KB
/
simple_query_fulltext_api.d
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
70
71
72
import reed.database;
import std.array;
import std.algorithm;
import std.stdio;
void cleanupCollections()
{
auto database = new Database();
foreach (collection; database.collections(true))
database.deleteCollection(collection.name);
}
struct Doc
{
string text;
long id;
}
void main()
{
cleanupCollections();
auto database = new Database();
auto collection = database.createCollection(Database.CollectionProperty("fulltext_collection"));
auto skiplist = collection.createIndex(FulltextIndexOption(["text"]));
void putDocuments()
{
import std.conv;
foreach (i; 0..100)
collection.putDocument(Doc("word 0 a", i));
foreach (i; 0..100)
collection.putDocument(Doc("1 ward b", i));
foreach (i; 0..100)
collection.putDocument(Doc("c word 2", i));
}
writeln("Put documents");
putDocuments();
writeln("simple/fulltext with word");
{
FulltextOption option = FulltextOption("text", "word");
auto cursor = collection.queryFulltext!Doc(option);
{
size_t i;
foreach (doc; cursor) i++;
assert(i == 200);
}
}
writeln("simple/fulltext with ward");
{
FulltextOption option = FulltextOption("text", "ward");
auto cursor = collection.queryFulltext!Doc(option);
{
size_t i;
foreach (doc; cursor) i++;
assert(i == 100);
}
}
writeln("simple/fulltext with unknown");
{
FulltextOption option = FulltextOption("text", "unknown");
assert(collection.queryFulltext!Doc(option).empty);
}
cleanupCollections();
}