[KinoSearch] seeking in search results

Marvin Humphrey marvin at rectangular.com
Tue Jun 13 12:53:52 PDT 2006




On Jun 13, 2006, at 8:22 AM, Brian Phillips wrote:

> It does appear to fail in the secondary doc ID sorting.

Sure enough!  The existing test wasn't stringent enough.

Thanks for the bug report.  Please try repository revision 960.

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/


slothbear:~/Desktop/ksfixhits marvin$ svn diff
Index: t/505-hit_queue.t
===================================================================
--- t/505-hit_queue.t   (revision 947)
+++ t/505-hit_queue.t   (working copy)
@@ -6,18 +6,31 @@
BEGIN { use_ok('KinoSearch::Search::HitQueue') }
-my $hq = KinoSearch::Search::HitQueue->new( max_size => 3 );
+my $hq = KinoSearch::Search::HitQueue->new( max_size => 10 );
-my @docs_and_scores = ( [ 1.0, 0 ], [ 0.1, 5 ], [ 0.1, 10 ], [ 0.9,  
1000 ] );
+my @docs_and_scores = (
+    [ 1.0, 0 ],
+    [ 0.1, 5 ],
+    [ 0.1, 10 ],
+    [ 0.9, 1000 ],
+    [ 1.0, 3000 ],
+    [ 1.0, 2000 ],
+);
+
my @scoredocs
      = map { dualvar( $_->[0], pack( 'N', $_->[1] ) ) }  
@docs_and_scores;
+my @correct_order = sort { $b <=> $a or $a cmp $b } @scoredocs;
+my @correct_docs   = map { unpack( 'N', "$_" ) } @correct_order;
+my @correct_scores = map { 0 + $_ } @correct_order;
+
my $hit_docs;
$hq->insert($_) for @scoredocs;
$hit_docs = $hq->hits;
my @scores = map { $_->get_score } @$hit_docs;
-is_deeply( \@scores, [ 1, 0.9, 0.1 ], "collect the three high  
scores" );
+is_deeply( \@scores, \@correct_scores, "rank by scores first" );
-is( $hit_docs->[2]->get_id, 5, "rank by doc_num after score" );
+my @doc_nums = map { $_->get_id } @$hit_docs;
+is_deeply( \@doc_nums, \@correct_docs, "rank by doc_num after score" );
Index: lib/KinoSearch/Search/HitQueue.pm
===================================================================
--- lib/KinoSearch/Search/HitQueue.pm   (revision 948)
+++ lib/KinoSearch/Search/HitQueue.pm   (working copy)
@@ -78,7 +78,7 @@
          ptr_a = SvPVX(a);
          ptr_b = SvPVX(b);
          /* sort by doc_num second */
-        return (bool)memcmp(ptr_b, ptr_a, 4);
+        return (bool)(memcmp(ptr_b, ptr_a, 4) < 0);
      }
      /* sort by score first */
      return SvNV(a) < SvNV(b);
slothbear:~/Desktop/ksfixhits marvin$



_______________________________________________
KinoSearch mailing list
KinoSearch at rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch




More information about the kinosearch mailing list