whistlepig 0.9.1 → 0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README +40 -12
- data/ext/whistlepig/extconf.rb +1 -1
- data/ext/whistlepig/index.c +201 -62
- data/ext/whistlepig/index.h +11 -2
- data/ext/whistlepig/lock.c +153 -0
- data/ext/whistlepig/lock.h +18 -0
- data/ext/whistlepig/mmap-obj.c +36 -20
- data/ext/whistlepig/mmap-obj.h +12 -7
- data/ext/whistlepig/search.c +7 -6
- data/ext/whistlepig/segment.c +97 -47
- data/ext/whistlepig/segment.h +19 -3
- data/ext/whistlepig/stringmap.c +61 -56
- data/ext/whistlepig/stringmap.h +7 -14
- data/ext/whistlepig/termhash.c +60 -62
- data/ext/whistlepig/termhash.h +4 -6
- data/ext/whistlepig/whistlepig.c +5 -1
- data/ext/whistlepig/whistlepig.h +1 -0
- metadata +29 -38
- data/ext/whistlepig/dump.c +0 -65
- data/ext/whistlepig/extconf.h +0 -3
- data/ext/whistlepig/test-segment.c +0 -404
- data/ext/whistlepig/test-stringmap.c +0 -82
- data/ext/whistlepig/test-stringpool.c +0 -67
- data/ext/whistlepig/test-termhash.c +0 -95
- data/ext/whistlepig/test-tokenizer.c +0 -55
- data/ext/whistlepig/test.h +0 -38
- data/ext/whistlepig/timer.h +0 -28
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whistlepig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.10'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
13
|
-
default_executable:
|
12
|
+
date: 2012-04-01 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
14
|
description: Whistlepig is a minimalist realtime full-text search index. Its goal
|
16
15
|
is to be as small and minimally-featured as possible, while still remaining useful,
|
@@ -28,48 +27,40 @@ files:
|
|
28
27
|
- COPYING
|
29
28
|
- ext/whistlepig/extconf.rb
|
30
29
|
- lib/whistlepig.rb
|
31
|
-
- ext/whistlepig/query-parser.lex.h
|
32
|
-
- ext/whistlepig/entry.h
|
33
|
-
- ext/whistlepig/stringmap.c
|
34
|
-
- ext/whistlepig/tokenizer.lex.h
|
35
|
-
- ext/whistlepig/whistlepig.h
|
36
30
|
- ext/whistlepig/error.c
|
37
|
-
- ext/whistlepig/
|
38
|
-
- ext/whistlepig/stringmap.h
|
39
|
-
- ext/whistlepig/timer.h
|
40
|
-
- ext/whistlepig/query-parser.lex.c
|
41
|
-
- ext/whistlepig/defaults.h
|
31
|
+
- ext/whistlepig/lock.h
|
42
32
|
- ext/whistlepig/tokenizer.lex.c
|
43
|
-
- ext/whistlepig/
|
44
|
-
- ext/whistlepig/
|
45
|
-
- ext/whistlepig/
|
46
|
-
- ext/whistlepig/
|
47
|
-
- ext/whistlepig/
|
48
|
-
- ext/whistlepig/test-termhash.c
|
33
|
+
- ext/whistlepig/query-parser.tab.c
|
34
|
+
- ext/whistlepig/defaults.h
|
35
|
+
- ext/whistlepig/stringmap.h
|
36
|
+
- ext/whistlepig/query.c
|
37
|
+
- ext/whistlepig/stringmap.c
|
49
38
|
- ext/whistlepig/query.h
|
50
|
-
- ext/whistlepig/
|
51
|
-
- ext/whistlepig/
|
52
|
-
- ext/whistlepig/mmap-obj.c
|
53
|
-
- ext/whistlepig/whistlepig.c
|
39
|
+
- ext/whistlepig/segment.h
|
40
|
+
- ext/whistlepig/entry.c
|
54
41
|
- ext/whistlepig/search.c
|
55
|
-
- ext/whistlepig/
|
56
|
-
- ext/whistlepig/query.c
|
57
|
-
- ext/whistlepig/dump.c
|
42
|
+
- ext/whistlepig/mmap-obj.c
|
58
43
|
- ext/whistlepig/query-parser.tab.h
|
59
|
-
- ext/whistlepig/
|
44
|
+
- ext/whistlepig/query-parser.lex.c
|
45
|
+
- ext/whistlepig/query-parser.c
|
46
|
+
- ext/whistlepig/stringpool.c
|
47
|
+
- ext/whistlepig/stringpool.h
|
48
|
+
- ext/whistlepig/whistlepig.h
|
60
49
|
- ext/whistlepig/khash.h
|
61
|
-
- ext/whistlepig/
|
62
|
-
- ext/whistlepig/entry.c
|
63
|
-
- ext/whistlepig/index.h
|
64
|
-
- ext/whistlepig/segment.h
|
65
|
-
- ext/whistlepig/test-stringmap.c
|
66
|
-
- ext/whistlepig/mmap-obj.h
|
67
|
-
- ext/whistlepig/segment.c
|
68
|
-
- ext/whistlepig/test-segment.c
|
50
|
+
- ext/whistlepig/index.c
|
69
51
|
- ext/whistlepig/search.h
|
70
|
-
- ext/whistlepig/
|
52
|
+
- ext/whistlepig/query-parser.lex.h
|
53
|
+
- ext/whistlepig/mmap-obj.h
|
54
|
+
- ext/whistlepig/tokenizer.lex.h
|
55
|
+
- ext/whistlepig/index.h
|
56
|
+
- ext/whistlepig/entry.h
|
57
|
+
- ext/whistlepig/termhash.h
|
71
58
|
- ext/whistlepig/error.h
|
72
|
-
|
59
|
+
- ext/whistlepig/whistlepig.c
|
60
|
+
- ext/whistlepig/termhash.c
|
61
|
+
- ext/whistlepig/segment.c
|
62
|
+
- ext/whistlepig/query-parser.h
|
63
|
+
- ext/whistlepig/lock.c
|
73
64
|
homepage: http://masanjin.net/whistlepig
|
74
65
|
licenses: []
|
75
66
|
post_install_message:
|
@@ -96,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
87
|
version: '0'
|
97
88
|
requirements: []
|
98
89
|
rubyforge_project:
|
99
|
-
rubygems_version: 1.
|
90
|
+
rubygems_version: 1.8.11
|
100
91
|
signing_key:
|
101
92
|
specification_version: 3
|
102
93
|
summary: a minimalist realtime full-text search index
|
data/ext/whistlepig/dump.c
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
#include <stdio.h>
|
2
|
-
#include "whistlepig.h"
|
3
|
-
|
4
|
-
#define isempty(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&2)
|
5
|
-
#define isdel(flag, i) ((flag[i>>4]>>((i&0xfU)<<1))&1)
|
6
|
-
#define KEY(h, i) &(h->pool[h->keys[i]])
|
7
|
-
|
8
|
-
RAISING_STATIC(dump_posting_list(wp_segment* s, uint32_t offset)) {
|
9
|
-
posting po;
|
10
|
-
|
11
|
-
while(offset != OFFSET_NONE) {
|
12
|
-
RELAY_ERROR(wp_segment_read_posting(s, offset, &po, 1));
|
13
|
-
|
14
|
-
printf(" @%u doc %u:", offset, po.doc_id);
|
15
|
-
for(uint32_t i = 0; i < po.num_positions; i++) {
|
16
|
-
printf(" %d", po.positions[i]);
|
17
|
-
}
|
18
|
-
printf("\n");
|
19
|
-
|
20
|
-
offset = po.next_offset;
|
21
|
-
free(po.positions);
|
22
|
-
}
|
23
|
-
|
24
|
-
return NO_ERROR;
|
25
|
-
}
|
26
|
-
|
27
|
-
RAISING_STATIC(dump(wp_segment* segment)) {
|
28
|
-
termhash* th = MMAP_OBJ(segment->termhash, termhash);
|
29
|
-
stringmap* sh = MMAP_OBJ(segment->stringmap, stringmap);
|
30
|
-
|
31
|
-
for(uint32_t i = 0; i < th->n_buckets; i++) {
|
32
|
-
if(isempty(th->flags, i)); // do nothing
|
33
|
-
else if(isdel(th->flags, i)) printf("%u: [deleted]", i);
|
34
|
-
else {
|
35
|
-
term t = th->keys[i];
|
36
|
-
const char* field = stringmap_int_to_string(sh, t.field_s);
|
37
|
-
const char* word = stringmap_int_to_string(sh, t.word_s);
|
38
|
-
printf("%u: %s:'%s'\n", i, field, word);
|
39
|
-
RELAY_ERROR(dump_posting_list(segment, th->vals[i]));
|
40
|
-
}
|
41
|
-
}
|
42
|
-
|
43
|
-
return NO_ERROR;
|
44
|
-
}
|
45
|
-
|
46
|
-
int main(int argc, char* argv[]) {
|
47
|
-
if(argc != 2) {
|
48
|
-
fprintf(stderr, "Usage: %s <segment filename>\n", argv[0]);
|
49
|
-
return -1;
|
50
|
-
}
|
51
|
-
|
52
|
-
wp_index* index;
|
53
|
-
DIE_IF_ERROR(wp_index_load(&index, argv[1]));
|
54
|
-
DIE_IF_ERROR(wp_index_dumpinfo(index, stdout));
|
55
|
-
|
56
|
-
for(int i = 0; i < index->num_segments; i++) {
|
57
|
-
printf("\nsegment %d details:\n", i);
|
58
|
-
DIE_IF_ERROR(dump(&index->segments[i]));
|
59
|
-
}
|
60
|
-
|
61
|
-
DIE_IF_ERROR(wp_index_unload(index));
|
62
|
-
|
63
|
-
return 0;
|
64
|
-
}
|
65
|
-
|
data/ext/whistlepig/extconf.h
DELETED
@@ -1,404 +0,0 @@
|
|
1
|
-
#include "test.h"
|
2
|
-
#include "segment.h"
|
3
|
-
#include "tokenizer.lex.h"
|
4
|
-
#include "query.h"
|
5
|
-
#include "index.h"
|
6
|
-
|
7
|
-
#define SEGMENT_PATH "/tmp/segment-test"
|
8
|
-
|
9
|
-
wp_error* setup(wp_segment* segment) {
|
10
|
-
RELAY_ERROR(wp_segment_delete(SEGMENT_PATH));
|
11
|
-
RELAY_ERROR(wp_segment_create(segment, SEGMENT_PATH));
|
12
|
-
return NO_ERROR;
|
13
|
-
}
|
14
|
-
|
15
|
-
#define ADD_DOC(word, pos) \
|
16
|
-
positions[0] = pos; \
|
17
|
-
RELAY_ERROR(wp_segment_ensure_fit(segment, postings_bytes, 0, &success)); \
|
18
|
-
if(success != 1) RAISE_ERROR("couldn't ensure segment fit"); \
|
19
|
-
RELAY_ERROR(wp_segment_add_posting(segment, "body", word, doc_id, 1, positions));
|
20
|
-
|
21
|
-
wp_error* add_docs(wp_segment* segment) {
|
22
|
-
docid_t doc_id;
|
23
|
-
pos_t positions[10];
|
24
|
-
uint32_t postings_bytes;
|
25
|
-
int success;
|
26
|
-
|
27
|
-
RELAY_ERROR(wp_segment_sizeof_posarray(segment, 1, NULL, &postings_bytes));
|
28
|
-
|
29
|
-
RELAY_ERROR(wp_segment_grab_docid(segment, &doc_id));
|
30
|
-
ADD_DOC("one", 0);
|
31
|
-
ADD_DOC("two", 1);
|
32
|
-
ADD_DOC("three", 2);
|
33
|
-
|
34
|
-
RELAY_ERROR(wp_segment_grab_docid(segment, &doc_id));
|
35
|
-
ADD_DOC("two", 0);
|
36
|
-
ADD_DOC("three", 1);
|
37
|
-
ADD_DOC("four", 2);
|
38
|
-
|
39
|
-
RELAY_ERROR(wp_segment_grab_docid(segment, &doc_id));
|
40
|
-
ADD_DOC("three", 0);
|
41
|
-
ADD_DOC("four", 1);
|
42
|
-
ADD_DOC("five", 2);
|
43
|
-
|
44
|
-
return NO_ERROR;
|
45
|
-
}
|
46
|
-
|
47
|
-
TEST(initial_state) {
|
48
|
-
wp_segment segment;
|
49
|
-
RELAY_ERROR(setup(&segment));
|
50
|
-
|
51
|
-
postings_region* pr = MMAP_OBJ(segment.postings, postings_region);
|
52
|
-
ASSERT(pr->num_docs == 0);
|
53
|
-
ASSERT(pr->num_postings == 0);
|
54
|
-
|
55
|
-
RELAY_ERROR(wp_segment_unload(&segment));
|
56
|
-
return NO_ERROR;
|
57
|
-
}
|
58
|
-
|
59
|
-
TEST(adding_a_doc_increments_counts) {
|
60
|
-
wp_segment segment;
|
61
|
-
pos_t positions[10];
|
62
|
-
docid_t doc_id;
|
63
|
-
|
64
|
-
RELAY_ERROR(setup(&segment));
|
65
|
-
RELAY_ERROR(wp_segment_grab_docid(&segment, &doc_id));
|
66
|
-
|
67
|
-
positions[0] = 0;
|
68
|
-
RELAY_ERROR(wp_segment_add_posting(&segment, "body", "hello", doc_id, 1, positions));
|
69
|
-
positions[0] = 1;
|
70
|
-
RELAY_ERROR(wp_segment_add_posting(&segment, "body", "there", doc_id, 1, positions));
|
71
|
-
|
72
|
-
postings_region* pr = MMAP_OBJ(segment.postings, postings_region);
|
73
|
-
ASSERT(pr->num_docs == 1);
|
74
|
-
ASSERT(pr->num_postings == 2);
|
75
|
-
|
76
|
-
RELAY_ERROR(wp_segment_unload(&segment));
|
77
|
-
return NO_ERROR;
|
78
|
-
}
|
79
|
-
|
80
|
-
#define RUN_QUERY(query) \
|
81
|
-
RELAY_ERROR(wp_search_init_search_state(query, &segment)); \
|
82
|
-
RELAY_ERROR(wp_search_run_query_on_segment(query, &segment, 10, &num_results, &results[0])); \
|
83
|
-
RELAY_ERROR(wp_search_release_search_state(query));
|
84
|
-
|
85
|
-
TEST(simple_term_queries) {
|
86
|
-
wp_segment segment;
|
87
|
-
uint32_t num_results;
|
88
|
-
search_result results[10];
|
89
|
-
wp_query* query;
|
90
|
-
|
91
|
-
RELAY_ERROR(setup(&segment));
|
92
|
-
RELAY_ERROR(add_docs(&segment));
|
93
|
-
|
94
|
-
query = wp_query_new_term("body", "one");
|
95
|
-
RUN_QUERY(query);
|
96
|
-
|
97
|
-
ASSERT(num_results == 1);
|
98
|
-
ASSERT(results[0].doc_id == 1);
|
99
|
-
|
100
|
-
query = wp_query_new_term("body", "two");
|
101
|
-
RUN_QUERY(query);
|
102
|
-
|
103
|
-
ASSERT(num_results == 2);
|
104
|
-
ASSERT(results[0].doc_id == 2);
|
105
|
-
ASSERT(results[1].doc_id == 1);
|
106
|
-
|
107
|
-
RELAY_ERROR(wp_segment_unload(&segment));
|
108
|
-
return NO_ERROR;
|
109
|
-
}
|
110
|
-
|
111
|
-
TEST(simple_conjunctive_queries) {
|
112
|
-
wp_segment segment;
|
113
|
-
uint32_t num_results;
|
114
|
-
search_result results[10];
|
115
|
-
wp_query* query;
|
116
|
-
|
117
|
-
RELAY_ERROR(setup(&segment));
|
118
|
-
RELAY_ERROR(add_docs(&segment));
|
119
|
-
|
120
|
-
query = wp_query_new_conjunction();
|
121
|
-
query = wp_query_add(query, wp_query_new_term("body", "one"));
|
122
|
-
query = wp_query_add(query, wp_query_new_term("body", "two"));
|
123
|
-
|
124
|
-
RUN_QUERY(query);
|
125
|
-
|
126
|
-
ASSERT(num_results == 1);
|
127
|
-
ASSERT(results[0].doc_id == 1);
|
128
|
-
|
129
|
-
query = wp_query_new_conjunction();
|
130
|
-
query = wp_query_add(query, wp_query_new_term("body", "four"));
|
131
|
-
query = wp_query_add(query, wp_query_new_term("body", "two"));
|
132
|
-
|
133
|
-
RUN_QUERY(query);
|
134
|
-
|
135
|
-
ASSERT(num_results == 1);
|
136
|
-
ASSERT(results[0].doc_id == 2);
|
137
|
-
|
138
|
-
// <empty>
|
139
|
-
query = wp_query_new_conjunction();
|
140
|
-
RUN_QUERY(query);
|
141
|
-
ASSERT(num_results == 0);
|
142
|
-
|
143
|
-
RELAY_ERROR(wp_segment_unload(&segment));
|
144
|
-
return NO_ERROR;
|
145
|
-
}
|
146
|
-
|
147
|
-
TEST(simple_phrasal_queries) {
|
148
|
-
wp_segment segment;
|
149
|
-
uint32_t num_results;
|
150
|
-
search_result results[10];
|
151
|
-
wp_query* query;
|
152
|
-
|
153
|
-
RELAY_ERROR(setup(&segment));
|
154
|
-
RELAY_ERROR(add_docs(&segment));
|
155
|
-
|
156
|
-
query = wp_query_new_phrase();
|
157
|
-
query = wp_query_add(query, wp_query_new_term("body", "one"));
|
158
|
-
query = wp_query_add(query, wp_query_new_term("body", "two"));
|
159
|
-
RUN_QUERY(query);
|
160
|
-
ASSERT(num_results == 1);
|
161
|
-
ASSERT(results[0].doc_id == 1);
|
162
|
-
|
163
|
-
query = wp_query_new_phrase();
|
164
|
-
query = wp_query_add(query, wp_query_new_term("body", "two"));
|
165
|
-
query = wp_query_add(query, wp_query_new_term("body", "one"));
|
166
|
-
RUN_QUERY(query);
|
167
|
-
ASSERT(num_results == 0);
|
168
|
-
|
169
|
-
query = wp_query_new_phrase();
|
170
|
-
query = wp_query_add(query, wp_query_new_term("body", "two"));
|
171
|
-
query = wp_query_add(query, wp_query_new_term("body", "three"));
|
172
|
-
RUN_QUERY(query);
|
173
|
-
ASSERT(num_results == 2);
|
174
|
-
ASSERT(results[0].doc_id == 2);
|
175
|
-
ASSERT(results[1].doc_id == 1);
|
176
|
-
|
177
|
-
query = wp_query_new_phrase();
|
178
|
-
query = wp_query_add(query, wp_query_new_term("body", "one"));
|
179
|
-
query = wp_query_add(query, wp_query_new_term("body", "two"));
|
180
|
-
query = wp_query_add(query, wp_query_new_term("body", "three"));
|
181
|
-
RUN_QUERY(query);
|
182
|
-
ASSERT(num_results == 1);
|
183
|
-
ASSERT(results[0].doc_id == 1);
|
184
|
-
|
185
|
-
RELAY_ERROR(wp_segment_unload(&segment));
|
186
|
-
return NO_ERROR;
|
187
|
-
}
|
188
|
-
|
189
|
-
TEST(segment_conjuction_of_phrase_queries) {
|
190
|
-
wp_segment segment;
|
191
|
-
uint32_t num_results;
|
192
|
-
search_result results[10];
|
193
|
-
wp_query* query;
|
194
|
-
wp_query* subquery;
|
195
|
-
|
196
|
-
RELAY_ERROR(setup(&segment));
|
197
|
-
RELAY_ERROR(add_docs(&segment));
|
198
|
-
|
199
|
-
// one "two three"
|
200
|
-
subquery = wp_query_new_phrase();
|
201
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "two"));
|
202
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "three"));
|
203
|
-
query = wp_query_new_conjunction();
|
204
|
-
query = wp_query_add(query, wp_query_new_term("body", "one"));
|
205
|
-
query = wp_query_add(query, subquery);
|
206
|
-
|
207
|
-
RUN_QUERY(query);
|
208
|
-
ASSERT(num_results == 1);
|
209
|
-
ASSERT(results[0].doc_id == 1);
|
210
|
-
|
211
|
-
// "two three" one
|
212
|
-
subquery = wp_query_new_phrase();
|
213
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "two"));
|
214
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "three"));
|
215
|
-
query = wp_query_new_conjunction();
|
216
|
-
query = wp_query_add(query, subquery);
|
217
|
-
query = wp_query_add(query, wp_query_new_term("body", "one"));
|
218
|
-
|
219
|
-
RUN_QUERY(query);
|
220
|
-
ASSERT(num_results == 1);
|
221
|
-
ASSERT(results[0].doc_id == 1);
|
222
|
-
|
223
|
-
// one "three two"
|
224
|
-
subquery = wp_query_new_phrase();
|
225
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "three"));
|
226
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "two"));
|
227
|
-
query = wp_query_new_conjunction();
|
228
|
-
query = wp_query_add(query, wp_query_new_term("body", "one"));
|
229
|
-
query = wp_query_add(query, subquery);
|
230
|
-
|
231
|
-
RUN_QUERY(query);
|
232
|
-
ASSERT(num_results == 0);
|
233
|
-
|
234
|
-
// two "two three"
|
235
|
-
subquery = wp_query_new_phrase();
|
236
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "two"));
|
237
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "three"));
|
238
|
-
query = wp_query_new_conjunction();
|
239
|
-
query = wp_query_add(query, wp_query_new_term("body", "two"));
|
240
|
-
query = wp_query_add(query, subquery);
|
241
|
-
|
242
|
-
RUN_QUERY(query);
|
243
|
-
ASSERT(num_results == 2);
|
244
|
-
ASSERT(results[0].doc_id == 2);
|
245
|
-
ASSERT(results[1].doc_id == 1);
|
246
|
-
|
247
|
-
RELAY_ERROR(wp_segment_unload(&segment));
|
248
|
-
return NO_ERROR;
|
249
|
-
}
|
250
|
-
|
251
|
-
TEST(negation_queries) {
|
252
|
-
wp_segment segment;
|
253
|
-
uint32_t num_results;
|
254
|
-
search_result results[10];
|
255
|
-
wp_query* query;
|
256
|
-
wp_query* subquery;
|
257
|
-
|
258
|
-
RELAY_ERROR(setup(&segment));
|
259
|
-
RELAY_ERROR(add_docs(&segment));
|
260
|
-
|
261
|
-
// one "two three"
|
262
|
-
subquery = wp_query_new_phrase();
|
263
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "two"));
|
264
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "three"));
|
265
|
-
query = wp_query_new_conjunction();
|
266
|
-
query = wp_query_add(query, wp_query_new_term("body", "one"));
|
267
|
-
query = wp_query_add(query, subquery);
|
268
|
-
|
269
|
-
RUN_QUERY(query);
|
270
|
-
ASSERT(num_results == 1);
|
271
|
-
ASSERT(results[0].doc_id == 1);
|
272
|
-
|
273
|
-
// "two three" one
|
274
|
-
subquery = wp_query_new_phrase();
|
275
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "two"));
|
276
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "three"));
|
277
|
-
query = wp_query_new_conjunction();
|
278
|
-
query = wp_query_add(query, subquery);
|
279
|
-
query = wp_query_add(query, wp_query_new_term("body", "one"));
|
280
|
-
|
281
|
-
RUN_QUERY(query);
|
282
|
-
ASSERT(num_results == 1);
|
283
|
-
ASSERT(results[0].doc_id == 1);
|
284
|
-
|
285
|
-
// one "three two"
|
286
|
-
subquery = wp_query_new_phrase();
|
287
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "three"));
|
288
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "two"));
|
289
|
-
query = wp_query_new_conjunction();
|
290
|
-
query = wp_query_add(query, wp_query_new_term("body", "one"));
|
291
|
-
query = wp_query_add(query, subquery);
|
292
|
-
|
293
|
-
RUN_QUERY(query);
|
294
|
-
ASSERT(num_results == 0);
|
295
|
-
|
296
|
-
// two "two three"
|
297
|
-
subquery = wp_query_new_phrase();
|
298
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "two"));
|
299
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "three"));
|
300
|
-
query = wp_query_new_conjunction();
|
301
|
-
query = wp_query_add(query, wp_query_new_term("body", "two"));
|
302
|
-
query = wp_query_add(query, subquery);
|
303
|
-
|
304
|
-
RUN_QUERY(query);
|
305
|
-
ASSERT(num_results == 2);
|
306
|
-
ASSERT(results[0].doc_id == 2);
|
307
|
-
ASSERT(results[1].doc_id == 1);
|
308
|
-
|
309
|
-
// <empty>
|
310
|
-
query = wp_query_new_conjunction();
|
311
|
-
RUN_QUERY(query);
|
312
|
-
ASSERT(num_results == 0);
|
313
|
-
|
314
|
-
// -one
|
315
|
-
subquery = wp_query_new_term("body", "one");
|
316
|
-
query = wp_query_new_negation();
|
317
|
-
query = wp_query_add(query, subquery);
|
318
|
-
RUN_QUERY(query);
|
319
|
-
ASSERT(num_results == 2);
|
320
|
-
ASSERT(results[0].doc_id == 3);
|
321
|
-
ASSERT(results[1].doc_id == 2);
|
322
|
-
|
323
|
-
// -two
|
324
|
-
subquery = wp_query_new_term("body", "two");
|
325
|
-
query = wp_query_new_negation();
|
326
|
-
query = wp_query_add(query, subquery);
|
327
|
-
RUN_QUERY(query);
|
328
|
-
ASSERT(num_results == 1);
|
329
|
-
ASSERT(results[0].doc_id == 3);
|
330
|
-
|
331
|
-
// -three
|
332
|
-
subquery = wp_query_new_term("body", "three");
|
333
|
-
query = wp_query_new_negation();
|
334
|
-
query = wp_query_add(query, subquery);
|
335
|
-
RUN_QUERY(query);
|
336
|
-
ASSERT(num_results == 0);
|
337
|
-
|
338
|
-
// -potato
|
339
|
-
subquery = wp_query_new_term("body", "potato");
|
340
|
-
query = wp_query_new_negation();
|
341
|
-
query = wp_query_add(query, subquery);
|
342
|
-
RUN_QUERY(query);
|
343
|
-
ASSERT(num_results == 3);
|
344
|
-
ASSERT(results[0].doc_id == 3);
|
345
|
-
ASSERT(results[1].doc_id == 2);
|
346
|
-
ASSERT(results[2].doc_id == 1);
|
347
|
-
|
348
|
-
// -"one two"
|
349
|
-
subquery = wp_query_new_conjunction();
|
350
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "one"));
|
351
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "two"));
|
352
|
-
query = wp_query_new_negation();
|
353
|
-
query = wp_query_add(query, subquery);
|
354
|
-
RUN_QUERY(query);
|
355
|
-
ASSERT(num_results == 2);
|
356
|
-
ASSERT(results[0].doc_id == 3);
|
357
|
-
ASSERT(results[1].doc_id == 2);
|
358
|
-
|
359
|
-
// -(AND one three)
|
360
|
-
subquery = wp_query_new_conjunction();
|
361
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "one"));
|
362
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "three"));
|
363
|
-
query = wp_query_new_negation();
|
364
|
-
query = wp_query_add(query, subquery);
|
365
|
-
RUN_QUERY(query);
|
366
|
-
ASSERT(num_results == 2);
|
367
|
-
ASSERT(results[0].doc_id == 3);
|
368
|
-
ASSERT(results[1].doc_id == 2);
|
369
|
-
|
370
|
-
// -"one three"
|
371
|
-
subquery = wp_query_new_phrase();
|
372
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "one"));
|
373
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "three"));
|
374
|
-
query = wp_query_new_negation();
|
375
|
-
query = wp_query_add(query, subquery);
|
376
|
-
RUN_QUERY(query);
|
377
|
-
ASSERT(num_results == 3);
|
378
|
-
|
379
|
-
// (AND -one three)
|
380
|
-
subquery = wp_query_new_negation();
|
381
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "one"));
|
382
|
-
query = wp_query_new_conjunction();
|
383
|
-
query = wp_query_add(query, subquery);
|
384
|
-
query = wp_query_add(query, wp_query_new_term("body", "three"));
|
385
|
-
RUN_QUERY(query);
|
386
|
-
ASSERT(num_results == 2);
|
387
|
-
ASSERT(results[0].doc_id == 3);
|
388
|
-
ASSERT(results[1].doc_id == 2);
|
389
|
-
|
390
|
-
// (AND three -one)
|
391
|
-
subquery = wp_query_new_negation();
|
392
|
-
subquery = wp_query_add(subquery, wp_query_new_term("body", "one"));
|
393
|
-
query = wp_query_new_conjunction();
|
394
|
-
query = wp_query_add(query, wp_query_new_term("body", "three"));
|
395
|
-
query = wp_query_add(query, subquery);
|
396
|
-
RUN_QUERY(query);
|
397
|
-
ASSERT(num_results == 2);
|
398
|
-
ASSERT(results[0].doc_id == 3);
|
399
|
-
ASSERT(results[1].doc_id == 2);
|
400
|
-
|
401
|
-
RELAY_ERROR(wp_segment_unload(&segment));
|
402
|
-
return NO_ERROR;
|
403
|
-
}
|
404
|
-
|
@@ -1,82 +0,0 @@
|
|
1
|
-
#include <string.h>
|
2
|
-
#include "stringmap.h"
|
3
|
-
#include "error.h"
|
4
|
-
#include "test.h"
|
5
|
-
|
6
|
-
static stringmap* setup() {
|
7
|
-
stringpool* p = malloc(stringpool_initial_size());
|
8
|
-
stringpool_init(p);
|
9
|
-
stringmap* q = malloc(stringmap_initial_size());
|
10
|
-
stringmap_init(q, p);
|
11
|
-
return q;
|
12
|
-
}
|
13
|
-
|
14
|
-
TEST(stringmap_initial_state) {
|
15
|
-
stringmap* q = setup();
|
16
|
-
ASSERT(q->n_occupied == 0);
|
17
|
-
ASSERT(!stringmap_needs_bump(q));
|
18
|
-
|
19
|
-
free(q);
|
20
|
-
return NO_ERROR;
|
21
|
-
}
|
22
|
-
|
23
|
-
TEST(stringmap_lookups_on_empty) {
|
24
|
-
stringmap* q = setup();
|
25
|
-
|
26
|
-
ASSERT(stringmap_string_to_int(q, "hot potato") == (uint32_t)-1);
|
27
|
-
ASSERT(stringmap_int_to_string(q, 0) == NULL);
|
28
|
-
ASSERT(stringmap_int_to_string(q, 1234) == NULL);
|
29
|
-
|
30
|
-
free(q);
|
31
|
-
return NO_ERROR;
|
32
|
-
}
|
33
|
-
|
34
|
-
TEST(stringmap_multiple_adds) {
|
35
|
-
stringmap* q = setup();
|
36
|
-
|
37
|
-
ASSERT(stringmap_string_to_int(q, "hot potato") == (uint32_t)-1);
|
38
|
-
uint32_t x, y;
|
39
|
-
RELAY_ERROR(stringmap_add(q, "hot potato", &x));
|
40
|
-
ASSERT(x != (uint32_t)-1);
|
41
|
-
RELAY_ERROR(stringmap_add(q, "hot potato", &y));
|
42
|
-
ASSERT(y != (uint32_t)-1);
|
43
|
-
ASSERT(x == y);
|
44
|
-
|
45
|
-
free(q);
|
46
|
-
return NO_ERROR;
|
47
|
-
}
|
48
|
-
|
49
|
-
TEST(stringmap_hashing_is_preserved) {
|
50
|
-
stringmap* q = setup();
|
51
|
-
|
52
|
-
uint32_t x, y;
|
53
|
-
RELAY_ERROR(stringmap_add(q, "hello there", &x));
|
54
|
-
ASSERT(x != (uint32_t)-1);
|
55
|
-
const char* a = stringmap_int_to_string(q, x);
|
56
|
-
ASSERT(strcmp(a, "hello there") == 0);
|
57
|
-
|
58
|
-
RELAY_ERROR(stringmap_add(q, "how are you?", &y));
|
59
|
-
const char* b = stringmap_int_to_string(q, y);
|
60
|
-
ASSERT(strcmp(b, "how are you?") == 0);
|
61
|
-
|
62
|
-
ASSERT(x != y);
|
63
|
-
|
64
|
-
free(q);
|
65
|
-
return NO_ERROR;
|
66
|
-
}
|
67
|
-
|
68
|
-
TEST(stringmap_detects_out_of_room) {
|
69
|
-
stringmap* q = setup();
|
70
|
-
|
71
|
-
uint32_t x, y, z, w;
|
72
|
-
RELAY_ERROR(stringmap_add(q, "one", &x));
|
73
|
-
RELAY_ERROR(stringmap_add(q, "two", &y));
|
74
|
-
RELAY_ERROR(stringmap_add(q, "three", &z));
|
75
|
-
|
76
|
-
wp_error* e = stringmap_add(q, "four", &w);
|
77
|
-
ASSERT(e != NULL);
|
78
|
-
wp_error_free(e);
|
79
|
-
|
80
|
-
free(q);
|
81
|
-
return NO_ERROR;
|
82
|
-
}
|