--- trunk/t/5_Node.t 2006/08/06 16:29:34 167 +++ trunk/t/5_Node.t 2008/01/20 16:50:59 198 @@ -3,15 +3,14 @@ use strict; use blib; -my $tests = 272; - use Test::More; use Test::Exception; use Data::Dumper; -BEGIN { use_ok('Search::Estraier') }; - -plan tests => $tests; +BEGIN { + plan tests => 313; + use_ok('Search::Estraier'); +}; my $debug = shift @ARGV; @@ -45,7 +44,7 @@ SKIP: { -skip "can't find estmaster at $estmaster_uri", ($tests - 9) if (! eval { $node->master( action => 'nodelist' ) } ); +skip "can't find estmaster at $estmaster_uri", ( 313 - 10 ) if (! eval { $node->master( action => 'nodelist' ) } ); diag "using $estmaster_uri"; diag("node->master shutdown not tested"); @@ -147,6 +146,7 @@ for ( 1 .. 17 ) { $doc->add_attr('@uri', 'test' . $_); + $doc->set_score( $_ * 10000 ); ok( $node->put_doc($doc), "put_doc test$_"); #diag $doc->dump_draft; cmp_ok( $node->doc_num, '==', ($_ + 1), "node->doc_num " . ($_ + 1)); @@ -157,6 +157,8 @@ my $id; ok($id = $node->uri_to_id( 'data0' ), "uri_to_id(data0)"); +throws_ok { $node->get_doc( 'foo') } qr/id must be number/, 'croak on non-number'; + ok($doc = $node->get_doc( $id ), "get_doc($id) for edit"); $doc->add_attr('foo', 'bar'); #diag Dumper($doc); @@ -191,8 +193,9 @@ ok($cond->set_max($max), "cond set_max($max)"); ok($cond->set_order('@uri ASCD'), 'cond set_order'); ok($cond->add_attr('@title STRINC Material'), 'cond add_attr'); +ok($cond->set_mask(qw/1 2/), 'cond set_mask'); -cmp_ok($node->cond_to_query( $cond ), 'eq' , 'phrase=girl&attr1=%40title%20STRINC%20Material&order=%40uri%20ASCD&max='.$max.'&wwidth=480&hwidth=96&awidth=96', 'cond_to_query'); +cmp_ok($node->cond_to_query( $cond ), 'eq' , 'phrase=girl&attr1=%40title%20STRINC%20Material&order=%40uri%20ASCD&max='.$max.'&wwidth=480&hwidth=96&awidth=96&mask=6', 'cond_to_query'); ok( my $nres = $node->search( $cond, 0 ), 'search'); @@ -220,8 +223,12 @@ } ok( my $id = $node->uri_to_id( $uri ), "uri_to_id($uri)"); - ok( $node->get_doc( $id ), "get_doc($id)"); - ok( $node->get_doc_by_uri( $uri ), "get_doc_by_uri($uri)"); + my $doc; + my $score = $num * 10000; + ok( $doc = $node->get_doc( $id ), "get_doc($id)"); + cmp_ok( $doc->score, '==', $score, "score $score"); + ok( $doc = $node->get_doc_by_uri( $uri ), "get_doc_by_uri($uri)"); + cmp_ok( $doc->score, '==', $score, "score $score"); cmp_ok( $node->get_doc_attr( $id, '@uri' ), 'eq', $uri, "get_doc_attr $id"); cmp_ok( $node->get_doc_attr_by_uri( $uri, '@uri' ), 'eq', $uri, "get_doc_attr $id"); ok( my $k1 = $node->etch_doc( $id ), "etch_doc_by_uri $uri"); @@ -232,6 +239,9 @@ ok(my $hints = $nres->hints, 'hints'); diag Dumper($hints) if ($debug); +foreach my $h (qw/TIME DOCNUM VERSION NODE HIT WORDNUM/) { + ok(defined( $nres->hint($h) ), "have hint $h"); +} ok($node->_set_info, "refresh _set_info"); @@ -266,6 +276,17 @@ } } +# test distinct +ok($cond = new Search::Estraier::Condition, 'new cond'); +ok($cond->set_phrase('girl'), 'cond set_phrase'); +my $distinct = '@title'; +ok($cond->set_distinct( $distinct ), "cond set_distinct($distinct)"); +cmp_ok($cond->distinct, 'eq', $distinct, "distinct is $distinct"); +like($node->cond_to_query( $cond ), qr/distinct=%40title/, 'cond_to_query have distinct'); +ok( $nres = $node->search( $cond, 0 ), 'search with distinct'); +cmp_ok($nres->doc_num, '==', 1, "nres->doc_num"); +cmp_ok($nres->hits, '==', 1, "nres->hits"); +diag "nres = ", Dumper( $nres ) if ($debug); # user doesn't exist ok($node->set_user('foobar', 1), 'set_user');