3 |
use strict; |
use strict; |
4 |
use blib; |
use blib; |
5 |
|
|
6 |
use Test::More tests => 142; |
use Test::More tests => 246; |
7 |
use Test::Exception; |
use Test::Exception; |
8 |
use Data::Dumper; |
use Data::Dumper; |
9 |
|
|
10 |
BEGIN { use_ok('Search::Estraier') }; |
BEGIN { use_ok('Search::Estraier') }; |
11 |
|
|
12 |
my $debug = 0; |
my $debug = shift @ARGV; |
13 |
|
|
14 |
# name of node for test |
# name of node for test |
15 |
my $test1_node = '_test1_' . $$; |
my $test1_node = '_test1_' . $$; |
36 |
|
|
37 |
my $msg; |
my $msg; |
38 |
|
|
|
ok($msg = $node->master( action => 'sync' ), "sync: $msg"); |
|
|
|
|
39 |
#diag "not testing backup\n"; |
#diag "not testing backup\n"; |
40 |
|
|
41 |
ok(my @users = $node->master( action => 'userlist' ), 'userlist'); |
ok(my @users = $node->master( action => 'userlist' ), 'userlist'); |
121 |
# test document creation |
# test document creation |
122 |
|
|
123 |
my $draft = <<'_END_OF_DRAFT_'; |
my $draft = <<'_END_OF_DRAFT_'; |
124 |
@uri=data001 |
@uri=data0 |
125 |
@title=Material Girl |
@title=Material Girl |
126 |
|
|
127 |
Living in a material world |
Living in a material world |
135 |
|
|
136 |
ok( $node->put_doc($doc), "put_doc data001"); |
ok( $node->put_doc($doc), "put_doc data001"); |
137 |
|
|
138 |
for ( 1 .. 10 ) { |
for ( 1 .. 17 ) { |
139 |
$doc->add_attr('@uri', 'test' . $_); |
$doc->add_attr('@uri', 'test' . $_); |
140 |
ok( $node->put_doc($doc), "put_doc test$_"); |
ok( $node->put_doc($doc), "put_doc test$_"); |
141 |
#diag $doc->dump_draft; |
#diag $doc->dump_draft; |
142 |
} |
} |
143 |
|
|
144 |
my $id; |
ok(! $node->uri_to_id( 'does-not-exists' ), "non-existant uri_to_id"); |
|
ok($id = $node->uri_to_id( 'data001' ), "uri_to_id = $id"); |
|
|
|
|
|
my $data_max = 5; |
|
145 |
|
|
146 |
for ( 1 .. $data_max ) { |
my $id; |
147 |
ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); |
ok($id = $node->uri_to_id( 'data0' ), "uri_to_id(data0)"); |
|
} |
|
148 |
|
|
149 |
ok($doc = $node->get_doc( $id ), 'get_doc for edit'); |
ok($doc = $node->get_doc( $id ), "get_doc($id) for edit"); |
150 |
$doc->add_attr('foo', 'bar'); |
$doc->add_attr('foo', 'bar'); |
151 |
#diag Dumper($doc); |
#diag Dumper($doc); |
152 |
ok( $node->edit_doc( $doc ), 'edit_doc'); |
ok( $node->edit_doc( $doc ), 'edit_doc'); |
153 |
|
|
154 |
ok( $node->out_doc( $id ), "out_doc $id"); |
ok( $node->out_doc( $id ), "out_doc($id)"); |
155 |
|
|
156 |
ok( ! $node->edit_doc( $doc ), "edit removed"); |
ok( ! $node->edit_doc( $doc ), "edit_doc of removed doc"); |
157 |
|
|
158 |
my $max = 3; |
my $doc_num; |
159 |
|
ok( $doc_num = $node->doc_num, "node->doc_num $doc_num"); |
160 |
|
|
161 |
|
my $delete_num = 5; |
162 |
|
|
163 |
|
for ( 1 .. $delete_num ) { |
164 |
|
ok( $node->out_doc_by_uri( 'test' . $_ ), "out_doc_by_uri test$_"); |
165 |
|
} |
166 |
|
|
167 |
|
ok($msg = $node->master( action => 'sync' ), "sync: $msg"); |
168 |
|
|
169 |
|
my $doc_num2 = $doc_num - $delete_num; |
170 |
|
cmp_ok($node->doc_num, '==', $doc_num2, "node->doc_num $doc_num2"); |
171 |
|
|
172 |
|
my $max = int($doc_num2 / 2); |
173 |
|
|
174 |
ok(my $cond = new Search::Estraier::Condition, 'new cond'); |
ok(my $cond = new Search::Estraier::Condition, 'new cond'); |
175 |
ok($cond->set_phrase('girl'), 'cond set_phrase'); |
ok($cond->set_phrase('girl'), 'cond set_phrase'); |
176 |
ok($cond->set_max($max), "cond set_max $max"); |
ok($cond->set_max($max), "cond set_max($max)"); |
177 |
ok($cond->set_order('@uri ASCD'), 'cond set_order'); |
ok($cond->set_order('@uri ASCD'), 'cond set_order'); |
178 |
ok($cond->add_attr('@title STRINC Material'), 'cond add_attr'); |
ok($cond->add_attr('@title STRINC Material'), 'cond add_attr'); |
179 |
|
|
183 |
|
|
184 |
isa_ok( $nres, 'Search::Estraier::NodeResult' ); |
isa_ok( $nres, 'Search::Estraier::NodeResult' ); |
185 |
|
|
186 |
cmp_ok($nres->doc_num, '==', $max, "doc_num = $max"); |
cmp_ok($nres->doc_num, '==', $max, "nres->doc_num $max"); |
187 |
|
|
188 |
cmp_ok($nres->hits, '==', $data_max, "hits"); |
cmp_ok($nres->hits, '==', $doc_num2, "nres->hits $doc_num2"); |
189 |
|
|
190 |
|
# upper limit is $nres->hits and not $nres->doc_num because we |
191 |
|
# check all documents, not just results! |
192 |
for my $i ( 0 .. ($nres->hits - 1) ) { |
for my $i ( 0 .. ($nres->hits - 1) ) { |
193 |
my $uri = 'test' . ($i + $data_max + 1); |
my $num = $i + $delete_num + 1; |
194 |
|
my $uri = 'test' . $num; |
195 |
|
|
196 |
if ($i < $nres->doc_num) { |
if ($i < $nres->doc_num) { |
197 |
ok( my $rdoc = $nres->get_doc( $i ), "get_doc $i"); |
ok( my $rdoc = $nres->get_doc( $i ), "nres->get_doc $i"); |
198 |
|
|
199 |
cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri"); |
cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri"); |
200 |
|
cmp_ok( $node->uri_to_id( $uri ), '==', $num + 1, "uri_to_id($uri)"); |
201 |
|
|
202 |
ok( my $k = $rdoc->keywords( $id ), "rdoc keywords"); |
ok( my $k = $rdoc->keywords( $id ), "rdoc keywords"); |
203 |
|
} else { |
204 |
|
ok( ! $nres->get_doc( $i ), "nres->get_doc doesn't exist"); |
205 |
|
|
206 |
} |
} |
207 |
|
|
208 |
ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri) = $id"); |
ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri)"); |
209 |
ok( $node->get_doc( $id ), "get_doc $id"); |
ok( $node->get_doc( $id ), "get_doc($id)"); |
210 |
ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri $uri"); |
ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri($uri)"); |
211 |
cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id"); |
cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id"); |
212 |
cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id"); |
cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id"); |
213 |
ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri"); |
ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri"); |
230 |
|
|
231 |
ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width"); |
ok($node->set_snippet_width( 100, 10, 10 ), "set_snippet_width"); |
232 |
|
|
233 |
|
# test skip |
234 |
|
my $skip = int($max / 2) || die "skip is zero, can't test"; |
235 |
|
ok($cond->set_skip( $skip ), "cond set_skip($skip)"); |
236 |
|
|
237 |
|
ok( $nres = $node->search( $cond, 0 ), 'search'); |
238 |
|
isa_ok( $nres, 'Search::Estraier::NodeResult' ); |
239 |
|
cmp_ok($nres->doc_num, '==', $max, "nres->doc_num " . ($max - $skip)); |
240 |
|
cmp_ok($nres->hits, '==', $doc_num2, "nres->hits $doc_num2"); |
241 |
|
|
242 |
|
for my $i ( 0 .. ($nres->doc_num - 1) ) { |
243 |
|
my $uri = 'test' . ($i + $delete_num + 1); |
244 |
|
ok( my $rdoc = $nres->get_doc( $i ), "nres->get_doc $i"); |
245 |
|
if ($rdoc) { |
246 |
|
cmp_ok( $rdoc->attr('@uri'), 'eq', $uri, "\@uri = $uri"); |
247 |
|
} else { |
248 |
|
fail('no rdoc'); |
249 |
|
} |
250 |
|
} |
251 |
|
|
252 |
|
|
253 |
# user doesn't exist |
# user doesn't exist |
254 |
ok(! $node->set_user('foobar', 1), 'set_user'); |
ok(! $node->set_user('foobar', 1), 'set_user'); |
255 |
|
|