Mailing List Archive

r3730 - in trunk: c_src/KinoSearch perl/t
Author: creamyg
Date: 2008-08-16 19:29:16 -0700 (Sat, 16 Aug 2008)
New Revision: 3730

Modified:
trunk/c_src/KinoSearch/InvIndexer.c
trunk/perl/t/213-segment_merging.t
Log:
Add test to verify that index optimization works. Simplify the optimization
logic slightly.


Modified: trunk/c_src/KinoSearch/InvIndexer.c
===================================================================
--- trunk/c_src/KinoSearch/InvIndexer.c 2008-08-11 05:21:54 UTC (rev 3729)
+++ trunk/c_src/KinoSearch/InvIndexer.c 2008-08-17 02:29:16 UTC (rev 3730)
@@ -246,7 +246,7 @@
VArray *seg_readers = IxReader_SegReaders(reader);
UNUSED_VAR(self);

- if (!all || seg_readers->size > 0) {
+ if (!all) {
u32_t i;
u32_t total_docs = 0;
u32_t threshold = 0;

Modified: trunk/perl/t/213-segment_merging.t
===================================================================
--- trunk/perl/t/213-segment_merging.t 2008-08-11 05:21:54 UTC (rev 3729)
+++ trunk/perl/t/213-segment_merging.t 2008-08-17 02:29:16 UTC (rev 3730)
@@ -18,12 +18,13 @@
sub analyzer { KinoSearch::Analysis::Tokenizer->new }

package main;
-use Test::More tests => 6;
+use Test::More tests => 7;

use KinoSearch::InvIndexer;
use KinoSearch::InvIndex;
use KinoSearch::Searcher;
use KinoSearch::Index::IndexReader;
+use KinoSearch::Store::RAMFolder;

use TestSchema;
use KinoTestUtils qw( create_invindex init_test_invindex_loc );
@@ -32,6 +33,40 @@

my ( $invindex, $invindexer, $searcher, $hits );

+ # Verify that optimization truly cuts down on the number of segments.
+ my $num_reps;
+ my $folder = KinoSearch::Store::RAMFolder->new;
+ $invindex = KinoSearch::InvIndex->clobber(
+ folder => $folder,
+ schema => TestSchema->new,
+ );
+ for ( $num_reps = 1;; $num_reps++ ) {
+ $invindexer = KinoSearch::InvIndexer->new( invindex => $invindex );
+ $invindexer->add_doc( { content => $_ } ) for 1 .. 5;
+ $invindexer->finish;
+ undef $invindexer;
+ my $num_cf_files = grep {/\.cf$/} @{ $folder->list };
+ last if ( $num_reps > 2 and $num_cf_files > 1 );
+ }
+ for ( my $i = 1; $i <= $num_reps; $i++ ) {
+ my $folder = KinoSearch::Store::RAMFolder->new;
+ $invindex = KinoSearch::InvIndex->clobber(
+ folder => $folder,
+ schema => TestSchema->new,
+ );
+ $invindexer = KinoSearch::InvIndexer->new( invindex => $invindex );
+ $invindexer->add_doc( { content => $_ } ) for 1 .. 5;
+ if ( $i == $num_reps ) {
+ $invindexer->finish( optimize => 1 );
+ my $num_cf_files = grep {/\.cf$/} @{ $folder->list };
+ is( $num_cf_files, 1, 'finish with optimize' );
+ }
+ else {
+ $invindexer->finish;
+ }
+ undef $invindexer;
+ }
+
my $invindex_loc = init_test_invindex_loc();
TestSchema->clobber($invindex_loc);



_______________________________________________
kinosearch-commits mailing list
kinosearch-commits@rectangular.com
http://www.rectangular.com/mailman/listinfo/kinosearch-commits