Mailing List Archive

r3651 - in trunk/perl/lib: . KinoSearch KinoSearch/Doc KinoSearch/FieldSpec KinoSearch/Highlight KinoSearch/Schema
Author: creamyg
Date: 2008-07-27 19:00:28 -0700 (Sun, 27 Jul 2008)
New Revision: 3651

Modified:
trunk/perl/lib/KinoSearch.pm
trunk/perl/lib/KinoSearch/Doc.pm
trunk/perl/lib/KinoSearch/Doc/HitDoc.pm
trunk/perl/lib/KinoSearch/FieldSpec.pm
trunk/perl/lib/KinoSearch/FieldSpec/text.pm
trunk/perl/lib/KinoSearch/Highlight/HeatMap.pm
trunk/perl/lib/KinoSearch/Highlight/HighlightSpan.pm
trunk/perl/lib/KinoSearch/Highlight/Highlighter.pm
trunk/perl/lib/KinoSearch/InvIndex.pm
trunk/perl/lib/KinoSearch/InvIndexer.pm
trunk/perl/lib/KinoSearch/Schema.pm
trunk/perl/lib/KinoSearch/Schema/FieldSpec.pm
trunk/perl/lib/KinoSearch/Searcher.pm
Log:
Migrate Perl code from various modules into KinoSearch.pm.


Modified: trunk/perl/lib/KinoSearch/Doc/HitDoc.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Doc/HitDoc.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/Doc/HitDoc.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,16 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::Doc::HitDoc;
-use KinoSearch::base qw( KinoSearch::Doc );
-
-our %new_defaults = (
- score => undef,
- doc_num => undef,
- boost => undef,
- fields => undef,
-);
-
1;

__END__
@@ -26,7 +15,7 @@
{
kino_HitDoc *self;
HV *args_hash = build_args_hash( &(ST(0)), 1, items,
- "KinoSearch::Doc::HitDoc::new_defaults");
+ "KinoSearch::Doc::HitDoc::new_PARAMS");
HV *fields = maybe_extract_hv(args_hash, SNL("fields"));
SV *doc_num_sv = maybe_extract_sv(args_hash, SNL("doc_num"));
SV *score_sv = maybe_extract_sv(args_hash, SNL("score"));

Modified: trunk/perl/lib/KinoSearch/Doc.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Doc.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/Doc.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,32 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::Doc;
-use KinoSearch::Util::ToolSet qw( nfreeze thaw );
-use KinoSearch::base qw( KinoSearch::Obj );
-
-use overload
- fallback => 1,
- '%{}' => \&get_fields;
-
-our %new_PARAMS = (
- boost => 1.0,
- doc_num => 0,
- fields => undef,
-);
-
-sub serialize_fields {
- my ( $self, $outstream ) = @_;
- my $buf = nfreeze( $self->get_fields );
- $outstream->write_buf($buf);
-}
-
-sub deserialize_fields {
- my ( $self, $instream ) = @_;
- my $buf = $instream->read_buf;
- $self->set_fields( thaw($buf) );
-}
-
1;

__END__

Modified: trunk/perl/lib/KinoSearch/FieldSpec/text.pm
===================================================================
--- trunk/perl/lib/KinoSearch/FieldSpec/text.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/FieldSpec/text.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,30 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::FieldSpec::text;
-use KinoSearch::Util::ToolSet qw( confess a_isa_b );
-use KinoSearch::base qw( KinoSearch::FieldSpec );
-use KinoSearch::Posting::ScorePosting;
-use KinoSearch::Search::Similarity;
-
-use constant TRUE => 1;
-use constant FALSE => 0;
-
-sub indexed {TRUE}
-sub stored {TRUE}
-sub analyzed {TRUE}
-sub vectorized {TRUE}
-sub binary {FALSE}
-sub compressed {FALSE}
-
-sub posting {
- shift;
- my %args = @_ == 1 ? ( similarity => $_[0] ) : (@_);
- confess("missing required argument 'similarity'")
- unless a_isa_b( $args{similarity}, "KinoSearch::Search::Similarity" );
- return KinoSearch::Posting::ScorePosting->new(%args);
-}
-
1;

__END__

Modified: trunk/perl/lib/KinoSearch/FieldSpec.pm
===================================================================
--- trunk/perl/lib/KinoSearch/FieldSpec.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/FieldSpec.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,19 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::FieldSpec;
-use KinoSearch::base qw( KinoSearch::Obj );
-use KinoSearch::Search::Similarity;
-
-sub boost {1.0}
-sub indexed { shift->abstract_death }
-sub stored { shift->abstract_death }
-sub analyzed { shift->abstract_death }
-sub vectorized { shift->abstract_death }
-sub binary { shift->abstract_death }
-sub compressed { shift->abstract_death }
-sub sortsub { shift->abstract_death }
-
1;

__END__

Modified: trunk/perl/lib/KinoSearch/Highlight/HeatMap.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Highlight/HeatMap.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/Highlight/HeatMap.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,55 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::Highlight::HeatMap;
-use KinoSearch::Util::ToolSet qw( to_kino to_perl );
-use KinoSearch::base qw( KinoSearch::Obj );
-
-our %instance_vars = __PACKAGE__->init_instance_vars(
- # members
- heat_map => \our %heat_map,
- sorted_loc => \our %sorted_loc,
-);
-
-sub new {
- my ( $either, %args ) = @_;
- $args{spans} = to_kino( $args{spans} );
- my $self = $either->_new(%args);
- my $locations = $heat_map{$$self}
- = { map { ( $_->get_start_offset => $_->get_weight ) }
- @{ $self->get_spans->to_perl } };
-
- # Sort by temperature, lowest to highest.
- $sorted_loc{$$self}
- = [ sort { $locations->{$a} <=> $locations->{$b} } keys %$locations ];
-
- return $self;
-}
-
-sub _hottest {
- return $sorted_loc{ ${ +shift } }[-1];
-}
-
-sub as_hashref {
- return $heat_map{ ${ +shift } };
-}
-
-sub hot_to_cold {
- return [ reverse @{ $sorted_loc{ ${ +shift } } } ];
-}
-
-sub flatten_spans {
- my ( $self, $spans ) = @_;
- my $flattened = $self->_flatten_spans( to_kino($spans) );
- return to_perl($flattened);
-}
-
-sub generate_proximity_boosts {
- my ( $self, $spans ) = @_;
- my $flattened = $self->_generate_proximity_boosts( to_kino($spans) );
- return to_perl($flattened);
-}
-
1;

__END__

Modified: trunk/perl/lib/KinoSearch/Highlight/HighlightSpan.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Highlight/HighlightSpan.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/Highlight/HighlightSpan.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,9 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::Highlight::HighlightSpan;
-use KinoSearch::base qw( KinoSearch::Obj );
-
1;

__END__

Modified: trunk/perl/lib/KinoSearch/Highlight/Highlighter.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Highlight/Highlighter.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/Highlight/Highlighter.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,40 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::Highlight::Highlighter;
-use KinoSearch::Util::ToolSet qw( confess a_isa_b );
-use KinoSearch::base qw( KinoSearch::Obj Exporter );
-
-our %instance_vars = __PACKAGE__->init_instance_vars(
- # members
- token_re => \our %token_re,
-);
-
-use HTML::Entities qw( encode_entities );
-use KinoSearch::Highlight::HeatMap;
-
-sub new {
- my ( $either, %args ) = @_;
- my $query = delete $args{query};
- my $searchable = $args{searchable};
- confess 'searchable is mandatory'
- unless a_isa_b( $searchable, "KinoSearch::Search::Searchable" );
- # Turn a query string into an object.
- if ( !a_isa_b( $query, 'KinoSearch::Search::Query' ) ) {
- $query = $searchable->prepare_simple_search($query);
- }
- my $self = $either->_new( %args, query => $query );
- $token_re{$$self} = qr/\b\w+(?:'\w+)?\b/;
- return $self;
-}
-
-sub do_encode { return encode_entities( $_[1] ) }
-
-sub find_sentence_boundaries {
- my $self = shift;
- return $self->_fsb(@_)->to_arrayref;
-}
-
1;

__END__

Modified: trunk/perl/lib/KinoSearch/InvIndex.pm
===================================================================
--- trunk/perl/lib/KinoSearch/InvIndex.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/InvIndex.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,37 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::InvIndex;
-use KinoSearch::Util::ToolSet qw( confess a_isa_b );
-use KinoSearch::base qw( KinoSearch::Obj );
-
-use KinoSearch::Index::Snapshot;
-
-sub new { confess("InvIndex's constructors are clobber, open, and read") }
-
-sub _process_args {
- my ( $either, %args ) = @_;
-
- # Confirm Schema.
- confess("Missing required parameter 'schema'")
- unless a_isa_b( $args{schema}, "KinoSearch::Schema" );
-
- # Confirm or create a Folder object.
- if ( !defined $args{folder} ) {
- confess("Missing required parameter 'folder'");
- }
- elsif ( !a_isa_b( $args{folder}, 'KinoSearch::Store::Folder' ) ) {
- $args{folder}
- = KinoSearch::Store::FSFolder->new( path => $args{folder} );
- }
-
- return ( $either, %args );
-}
-
-sub open { return _open( _process_args(@_) ) }
-sub read { return _read( _process_args(@_) ) }
-sub clobber { return _clobber( _process_args(@_) ) }
-
1;

__END__

Modified: trunk/perl/lib/KinoSearch/InvIndexer.pm
===================================================================
--- trunk/perl/lib/KinoSearch/InvIndexer.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/InvIndexer.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,29 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::InvIndexer;
-use KinoSearch::Util::ToolSet qw( confess );
-use KinoSearch::base qw( KinoSearch::Obj );
-
-use KinoSearch::Doc;
-use KinoSearch::Index::IndexReader;
-use KinoSearch::Index::SegInfo;
-use KinoSearch::Index::Snapshot;
-use KinoSearch::Index::SegWriter;
-use KinoSearch::Index::FilePurger;
-
-sub add_doc {
- confess('usage: $invindexer->add_doc($doc)') unless @_ == 2;
- my ( $self, $doc ) = @_;
- $self->get_seg_writer->add_doc($doc);
-}
-
-sub delete_docs_by_term {
- confess( "delete_docs_by_term() has been replaced by delete_by_term(), "
- . "which has slightly different behavior -- see InvIndexer's docs"
- );
-}
-
1;

__END__

Modified: trunk/perl/lib/KinoSearch/Schema/FieldSpec.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Schema/FieldSpec.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/Schema/FieldSpec.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,5 +1,4 @@
-package KinoSearch::Schema::FieldSpec;
-use KinoSearch::base qw( KinoSearch::FieldSpec::text );
+use KinoSearch;

1;


Modified: trunk/perl/lib/KinoSearch/Schema.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Schema.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/Schema.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,81 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::Schema;
-use KinoSearch::Util::ToolSet qw( confess blessed );
-use KinoSearch::base qw( KinoSearch::Obj );
-
-use KinoSearch::InvIndex;
-use KinoSearch::Search::Similarity;
-use KinoSearch::Util::Hash;
-use KinoSearch::FieldSpec;
-use KinoSearch::Schema::FieldSpec;
-
-#-----------------------------------------------------------------------
-# CLASS METHODS
-#-----------------------------------------------------------------------
-
-sub analyzer { shift->abstract_death }
-sub similarity { KinoSearch::Search::Similarity->new }
-sub index_interval {128}
-sub skip_interval {16}
-
-our %instance_vars = __PACKAGE__->init_instance_vars(
- # private constructor params
- similarity => undef,
- analyzer => undef,
- index_interval => undef,
- skip_interval => undef,
-);
-
-sub new {
- my $either = shift;
- my $class = ref($either) || $either;
- my $self = $class->_new(@_);
-
- # Register all the fields in %fields.
- my $fields = _retrieve_fields_hashref( $class . '::fields' );
- confess("Can't find \%$class\::fields hash") unless defined $fields;
- while ( my ( $field_name, $fspec_class ) = each %$fields ) {
- $self->add_field( field => $field_name, spec => $fspec_class );
- }
-
- return $self;
-}
-
-sub clobber {
- my ( $either, $path ) = @_;
- my $self = blessed $either ? $either : $either->new;
- return KinoSearch::InvIndex->clobber(
- schema => $self,
- folder => $path,
- );
-}
-
-sub open {
- my ( $either, $path ) = @_;
- my $self = blessed $either ? $either : $either->new;
- return KinoSearch::InvIndex->open(
- schema => $self,
- folder => $path,
- );
-}
-
-sub read {
- my ( $either, $path ) = @_;
- my $self = blessed $either ? $either : $either->new;
- return KinoSearch::InvIndex->read(
- schema => $self,
- folder => $path,
- );
-}
-
-#-----------------------------------------------------------------------
-# INSTANCE METHODS
-#-----------------------------------------------------------------------
-
-sub all_fields { shift->_all_fields->to_perl }
-
1;

__END__

Modified: trunk/perl/lib/KinoSearch/Searcher.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Searcher.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch/Searcher.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -1,35 +1,5 @@
-use strict;
-use warnings;
+use KinoSearch;

-package KinoSearch::Searcher;
-use KinoSearch::Util::ToolSet qw( a_isa_b confess );
-use KinoSearch::base qw( KinoSearch::Search::Searchable );
-
-use KinoSearch::Index::IndexReader;
-use KinoSearch::Search::HitCollector;
-use KinoSearch::Search::TopDocCollector;
-use KinoSearch::Search::ScoreDoc;
-use KinoSearch::Search::SortCollector;
-use KinoSearch::Search::TopDocs;
-
-sub new {
- my ( $either, %args ) = @_;
-
- # Require either invindex or reader.
- if ( a_isa_b( $args{reader}, 'KinoSearch::Index::IndexReader' ) ) {
- $args{invindex} = $args{reader}->get_invindex;
- }
- elsif ( a_isa_b( $args{invindex}, 'KinoSearch::InvIndex' ) ) {
- $args{reader} = KinoSearch::Index::IndexReader->open(
- invindex => $args{invindex} );
- }
- else {
- confess("Either 'invindex' or 'reader' is required");
- }
-
- return $either->_new(%args);
-}
-
1;

__END__

Modified: trunk/perl/lib/KinoSearch.pm
===================================================================
--- trunk/perl/lib/KinoSearch.pm 2008-07-28 01:29:11 UTC (rev 3650)
+++ trunk/perl/lib/KinoSearch.pm 2008-07-28 02:00:28 UTC (rev 3651)
@@ -26,6 +26,221 @@
our @EXPORT_OK = qw( kdump );

{
+ package KinoSearch::Doc;
+ use KinoSearch::Util::ToolSet qw( nfreeze thaw );
+ use KinoSearch::base qw( KinoSearch::Obj );
+
+ use overload
+ fallback => 1,
+ '%{}' => \&get_fields;
+
+ our %new_PARAMS = (
+ boost => 1.0,
+ doc_num => 0,
+ fields => undef,
+ );
+
+ sub serialize_fields {
+ my ( $self, $outstream ) = @_;
+ my $buf = nfreeze( $self->get_fields );
+ $outstream->write_buf($buf);
+ }
+
+ sub deserialize_fields {
+ my ( $self, $instream ) = @_;
+ my $buf = $instream->read_buf;
+ $self->set_fields( thaw($buf) );
+ }
+}
+
+{
+ package KinoSearch::Doc::HitDoc;
+ use KinoSearch::base qw( KinoSearch::Doc );
+
+ our %new_PARAMS = (
+ score => undef,
+ doc_num => undef,
+ boost => undef,
+ fields => undef,
+ );
+}
+
+{
+ package KinoSearch::FieldSpec;
+ use KinoSearch::base qw( KinoSearch::Obj );
+ use KinoSearch::Search::Similarity;
+
+ sub boost {1.0}
+ sub indexed { shift->abstract_death }
+ sub stored { shift->abstract_death }
+ sub analyzed { shift->abstract_death }
+ sub vectorized { shift->abstract_death }
+ sub binary { shift->abstract_death }
+ sub compressed { shift->abstract_death }
+ sub sortsub { shift->abstract_death }
+}
+
+{
+ package KinoSearch::FieldSpec::text;
+ use KinoSearch::Util::ToolSet qw( confess a_isa_b );
+ use KinoSearch::base qw( KinoSearch::FieldSpec );
+ use KinoSearch::Posting::ScorePosting;
+ use KinoSearch::Search::Similarity;
+
+ use constant TRUE => 1;
+ use constant FALSE => 0;
+
+ sub indexed {TRUE}
+ sub stored {TRUE}
+ sub analyzed {TRUE}
+ sub vectorized {TRUE}
+ sub binary {FALSE}
+ sub compressed {FALSE}
+
+ sub posting {
+ shift;
+ my %args = @_ == 1 ? ( similarity => $_[0] ) : (@_);
+ confess("missing required argument 'similarity'")
+ unless a_isa_b( $args{similarity},
+ "KinoSearch::Search::Similarity" );
+ return KinoSearch::Posting::ScorePosting->new(%args);
+ }
+}
+
+{
+ package KinoSearch::Highlight::HeatMap;
+ use KinoSearch::Util::ToolSet qw( to_kino to_perl );
+ use KinoSearch::base qw( KinoSearch::Obj );
+
+ our %instance_vars = __PACKAGE__->init_instance_vars(
+ # members
+ heat_map => \our %heat_map,
+ sorted_loc => \our %sorted_loc,
+ );
+
+ sub new {
+ my ( $either, %args ) = @_;
+ $args{spans} = to_kino( $args{spans} );
+ my $self = $either->_new(%args);
+ my $locations = $heat_map{$$self}
+ = { map { ( $_->get_start_offset => $_->get_weight ) }
+ @{ $self->get_spans->to_perl } };
+
+ # Sort by temperature, lowest to highest.
+ $sorted_loc{$$self} = [ sort { $locations->{$a} <=> $locations->{$b} }
+ keys %$locations ];
+
+ return $self;
+ }
+
+ sub _hottest {
+ return $sorted_loc{ ${ +shift } }[-1];
+ }
+
+ sub as_hashref {
+ return $heat_map{ ${ +shift } };
+ }
+
+ sub hot_to_cold {
+ return [ reverse @{ $sorted_loc{ ${ +shift } } } ];
+ }
+
+ sub flatten_spans {
+ my ( $self, $spans ) = @_;
+ my $flattened = $self->_flatten_spans( to_kino($spans) );
+ return to_perl($flattened);
+ }
+
+ sub generate_proximity_boosts {
+ my ( $self, $spans ) = @_;
+ my $flattened = $self->_generate_proximity_boosts( to_kino($spans) );
+ return to_perl($flattened);
+ }
+}
+
+{
+ package KinoSearch::Highlight::Highlighter;
+ use KinoSearch::Util::ToolSet qw( confess a_isa_b );
+ use KinoSearch::base qw( KinoSearch::Obj Exporter );
+
+ our %instance_vars = __PACKAGE__->init_instance_vars(
+ # members
+ token_re => \our %token_re,
+ );
+
+ use HTML::Entities qw( encode_entities );
+ use KinoSearch::Highlight::HeatMap;
+
+ sub new {
+ my ( $either, %args ) = @_;
+ my $query = delete $args{query};
+ my $searchable = $args{searchable};
+ confess 'searchable is mandatory'
+ unless a_isa_b( $searchable, "KinoSearch::Search::Searchable" );
+ # Turn a query string into an object.
+ if ( !a_isa_b( $query, 'KinoSearch::Search::Query' ) ) {
+ $query = $searchable->prepare_simple_search($query);
+ }
+ my $self = $either->_new( %args, query => $query );
+ $token_re{$$self} = qr/\b\w+(?:'\w+)?\b/;
+ return $self;
+ }
+
+ sub do_encode { return encode_entities( $_[1] ) }
+
+ sub find_sentence_boundaries {
+ my $self = shift;
+ return $self->_fsb(@_)->to_arrayref;
+ }
+}
+
+{
+ package KinoSearch::InvIndex;
+ use KinoSearch::Util::ToolSet qw( confess a_isa_b );
+ use KinoSearch::base qw( KinoSearch::Obj );
+
+ use KinoSearch::Index::Snapshot;
+
+ sub new { confess("InvIndex's constructors are clobber, open, and read") }
+
+ sub _process_args {
+ my ( $either, %args ) = @_;
+
+ # Confirm Schema.
+ confess("Missing required parameter 'schema'")
+ unless a_isa_b( $args{schema}, "KinoSearch::Schema" );
+
+ # Confirm or create a Folder object.
+ if ( !defined $args{folder} ) {
+ confess("Missing required parameter 'folder'");
+ }
+ elsif ( !a_isa_b( $args{folder}, 'KinoSearch::Store::Folder' ) ) {
+ $args{folder}
+ = KinoSearch::Store::FSFolder->new( path => $args{folder} );
+ }
+
+ return ( $either, %args );
+ }
+
+ sub open { return _open( _process_args(@_) ) }
+ sub read { return _read( _process_args(@_) ) }
+ sub clobber { return _clobber( _process_args(@_) ) }
+
+}
+
+{
+ package KinoSearch::InvIndexer;
+ use KinoSearch::Util::ToolSet qw( confess );
+ use KinoSearch::base qw( KinoSearch::Obj );
+
+ sub add_doc {
+ confess('usage: $invindexer->add_doc($doc)') unless @_ == 2;
+ my ( $self, $doc ) = @_;
+ $self->get_seg_writer->add_doc($doc);
+ }
+}
+
+{
package KinoSearch::Obj;
use KinoSearch::Util::ToolSet qw( confess reftype to_perl );

@@ -441,6 +656,75 @@
}

{
+ package KinoSearch::Schema;
+ use KinoSearch::Util::ToolSet qw( confess blessed );
+ use KinoSearch::base qw( KinoSearch::Obj );
+
+ sub analyzer { shift->abstract_death }
+ sub similarity { KinoSearch::Search::Similarity->new }
+ sub index_interval {128}
+ sub skip_interval {16}
+
+ our %instance_vars = __PACKAGE__->init_instance_vars(
+ # private constructor params
+ similarity => undef,
+ analyzer => undef,
+ index_interval => undef,
+ skip_interval => undef,
+ );
+
+ sub new {
+ my $either = shift;
+ my $class = ref($either) || $either;
+ my $self = $class->_new(@_);
+
+ # Register all the fields in %fields.
+ my $fields = _retrieve_fields_hashref( $class . '::fields' );
+ confess("Can't find \%$class\::fields hash") unless defined $fields;
+ while ( my ( $field_name, $fspec_class ) = each %$fields ) {
+ $self->add_field( field => $field_name, spec => $fspec_class );
+ }
+
+ return $self;
+ }
+
+ sub clobber {
+ my ( $either, $path ) = @_;
+ my $self = blessed $either ? $either : $either->new;
+ return KinoSearch::InvIndex->clobber(
+ schema => $self,
+ folder => $path,
+ );
+ }
+
+ sub open {
+ my ( $either, $path ) = @_;
+ my $self = blessed $either ? $either : $either->new;
+ return KinoSearch::InvIndex->open(
+ schema => $self,
+ folder => $path,
+ );
+ }
+
+ sub read {
+ my ( $either, $path ) = @_;
+ my $self = blessed $either ? $either : $either->new;
+ return KinoSearch::InvIndex->read(
+ schema => $self,
+ folder => $path,
+ );
+ }
+
+ sub all_fields { shift->_all_fields->to_perl }
+
+}
+
+{
+ package KinoSearch::Schema::FieldSpec;
+ use KinoSearch::base qw( KinoSearch::FieldSpec::text );
+}
+
+{
package KinoSearch::Search::Compiler;
use KinoSearch::Util::ToolSet qw( a_isa_b confess );
use KinoSearch::base qw( KinoSearch::Obj );
@@ -526,6 +810,30 @@
}

{
+ package KinoSearch::Searcher;
+ use KinoSearch::Util::ToolSet qw( a_isa_b confess );
+ use KinoSearch::base qw( KinoSearch::Search::Searchable );
+
+ sub new {
+ my ( $either, %args ) = @_;
+
+ # Require either invindex or reader.
+ if ( a_isa_b( $args{reader}, 'KinoSearch::Index::IndexReader' ) ) {
+ $args{invindex} = $args{reader}->get_invindex;
+ }
+ elsif ( a_isa_b( $args{invindex}, 'KinoSearch::InvIndex' ) ) {
+ $args{reader} = KinoSearch::Index::IndexReader->open(
+ invindex => $args{invindex} );
+ }
+ else {
+ confess("Either 'invindex' or 'reader' is required");
+ }
+
+ return $either->_new(%args);
+ }
+}
+
+{
package KinoSearch::Store::Folder;
use KinoSearch::base qw( KinoSearch::Obj );
use File::Spec::Functions qw( rel2abs );


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