Lucy
view release on metacpan or search on metacpan
buildlib/Lucy/Build/Binding/Index.pm view on Meta::CPAN
my $searcher = Lucy::Search::IndexSearcher->new( index => $reader );
END_SYNOPSIS
my $constructor = <<'END_CONSTRUCTOR';
my $manager = Lucy::Index::IndexManager->new(
host => $hostname, # default: ""
);
END_CONSTRUCTOR
$pod_spec->set_synopsis($synopsis);
$pod_spec->add_constructor( alias => 'new', sample => $constructor, );
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Index::IndexManager",
);
$binding->set_pod_spec($pod_spec);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
sub bind_indexreader {
my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
my $synopsis = <<'END_SYNOPSIS';
my $reader = Lucy::Index::IndexReader->open(
index => '/path/to/index',
);
my $seg_readers = $reader->seg_readers;
for my $seg_reader (@$seg_readers) {
my $seg_name = $seg_reader->get_segment->get_name;
my $num_docs = $seg_reader->doc_max;
print "Segment $seg_name ($num_docs documents):\n";
my $doc_reader = $seg_reader->obtain("Lucy::Index::DocReader");
for my $doc_id ( 1 .. $num_docs ) {
my $doc = $doc_reader->fetch_doc($doc_id);
print " $doc_id: $doc->{title}\n";
}
}
END_SYNOPSIS
my $constructor = <<'END_CONSTRUCTOR';
my $reader = Lucy::Index::IndexReader->open(
index => '/path/to/index', # required
snapshot => $snapshot,
manager => $index_manager,
);
END_CONSTRUCTOR
$pod_spec->set_synopsis($synopsis);
$pod_spec->add_constructor(
alias => 'open',
sample => $constructor,
);
$pod_spec->add_method(
method => 'Offsets',
alias => 'offsets',
);
my $xs_code = <<'END_XS_CODE';
MODULE = Lucy PACKAGE = Lucy::Index::IndexReader
void
set_race_condition_debug1(val_sv)
SV *val_sv;
PPCODE:
CFISH_DECREF(lucy_PolyReader_race_condition_debug1);
lucy_PolyReader_race_condition_debug1 = (cfish_String*)
XSBind_perl_to_cfish_nullable(aTHX_ val_sv, CFISH_STRING);
int32_t
debug1_num_passes()
CODE:
RETVAL = lucy_PolyReader_debug1_num_passes;
OUTPUT: RETVAL
END_XS_CODE
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Index::IndexReader",
);
$binding->bind_constructor(
alias => 'open',
initializer => 'do_open',
);
$binding->exclude_constructor;
$binding->bind_method( alias => '_offsets', method => 'Offsets' );
$binding->append_xs($xs_code);
$binding->set_pod_spec($pod_spec);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
sub bind_indexer {
my @hand_rolled = qw( Add_Doc );
my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
my $synopsis = <<'END_SYNOPSIS';
my $indexer = Lucy::Index::Indexer->new(
schema => $schema,
index => '/path/to/index',
create => 1,
);
while ( my ( $title, $content ) = each %source_docs ) {
$indexer->add_doc({
title => $title,
content => $content,
});
}
$indexer->commit;
END_SYNOPSIS
my $constructor = <<'END_NEW';
=head2 new
my $indexer = Lucy::Index::Indexer->new(
schema => $schema, # required at index creation
index => '/path/to/index', # required
create => 1, # default: 0
truncate => 1, # default: 0
manager => $manager # default: created internally
);
=over
=item *
buildlib/Lucy/Build/Binding/Index.pm view on Meta::CPAN
my $add_doc_pod = <<'END_ADD_DOC_POD';
=head2 add_doc
$indexer->add_doc($doc);
$indexer->add_doc( { field_name => $field_value } );
$indexer->add_doc(
doc => { field_name => $field_value },
boost => 2.5, # default: 1.0
);
Add a document to the index. Accepts either a single argument or labeled
params.
=over
=item *
B<doc> - Either a Lucy::Document::Doc object, or a hashref (which will
be attached to a Lucy::Document::Doc object internally).
=item *
B<boost> - A floating point weight which affects how this document scores.
=back
END_ADD_DOC_POD
$pod_spec->set_synopsis($synopsis);
# Override necessary because of different handling for flags.
$pod_spec->add_constructor( alias => 'new', pod => $constructor );
# Override is necessary because there's no standard way to explain
# hash/hashref across multiple host languages.
$pod_spec->add_method(
method => 'Add_Doc',
alias => 'add_doc',
pod => $add_doc_pod,
);
my $xs_code = <<'END_XS_CODE';
MODULE = Lucy PACKAGE = Lucy::Index::Indexer
int32_t
CREATE(...)
CODE:
CFISH_UNUSED_VAR(items);
RETVAL = lucy_Indexer_CREATE;
OUTPUT: RETVAL
int32_t
TRUNCATE(...)
CODE:
CFISH_UNUSED_VAR(items);
RETVAL = lucy_Indexer_TRUNCATE;
OUTPUT: RETVAL
void
add_doc(self, ...)
lucy_Indexer *self;
PPCODE:
{
lucy_Doc *doc = NULL;
SV *doc_sv = NULL;
float boost = 1.0;
if (items == 2) {
doc_sv = ST(1);
}
else {
static const XSBind_ParamSpec param_specs[2] = {
XSBIND_PARAM("doc", true),
XSBIND_PARAM("boost", false)
};
int32_t locations[2];
XSBind_locate_args(aTHX_ &ST(0), 1, items, param_specs, locations, 2);
doc_sv = ST(locations[0]);
if (locations[1] < items) { boost = (float)SvNV(ST(locations[1])); }
}
// Either get a Doc or use the stock doc.
if (sv_isobject(doc_sv)
&& sv_derived_from(doc_sv, "Lucy::Document::Doc")
) {
IV tmp = SvIV(SvRV(doc_sv));
doc = INT2PTR(lucy_Doc*, tmp);
}
else if (XSBind_sv_defined(aTHX_ doc_sv) && SvROK(doc_sv)) {
HV *maybe_fields = (HV*)SvRV(doc_sv);
if (SvTYPE((SV*)maybe_fields) == SVt_PVHV) {
doc = LUCY_Indexer_Get_Stock_Doc(self);
LUCY_Doc_Set_Fields(doc, maybe_fields);
}
}
if (!doc) {
THROW(CFISH_ERR, "Need either a hashref or a %o",
CFISH_Class_Get_Name(LUCY_DOC));
}
LUCY_Indexer_Add_Doc(self, doc, boost);
}
END_XS_CODE
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Index::Indexer",
);
$binding->bind_constructor( alias => '_new' );
$binding->exclude_method($_) for @hand_rolled;
$binding->append_xs($xs_code);
$binding->set_pod_spec($pod_spec);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
sub bind_lexicon {
my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
my $synopsis = <<'END_SYNOPSIS';
my $lex_reader = $seg_reader->obtain('Lucy::Index::LexiconReader');
buildlib/Lucy/Build/Binding/Index.pm view on Meta::CPAN
class_name => "Lucy::Index::Posting::ScorePosting",
);
$binding->append_xs($xs_code);
$binding->exclude_method($_) for @hand_rolled;
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
sub bind_postinglist {
my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
my $synopsis = <<'END_SYNOPSIS';
my $posting_list_reader
= $seg_reader->obtain("Lucy::Index::PostingListReader");
my $posting_list = $posting_list_reader->posting_list(
field => 'content',
term => 'foo',
);
while ( my $doc_id = $posting_list->next ) {
say "Matching doc id: $doc_id";
}
END_SYNOPSIS
$pod_spec->set_synopsis($synopsis);
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Index::PostingList",
);
$binding->set_pod_spec($pod_spec);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
sub bind_postinglistreader {
my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
my $synopsis = <<'END_SYNOPSIS';
my $posting_list_reader
= $seg_reader->obtain("Lucy::Index::PostingListReader");
my $posting_list = $posting_list_reader->posting_list(
field => 'title',
term => 'foo',
);
END_SYNOPSIS
$pod_spec->set_synopsis($synopsis);
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Index::PostingListReader",
);
$binding->set_pod_spec($pod_spec);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
sub bind_postinglistwriter {
my $xs_code = <<'END_XS';
MODULE = Lucy PACKAGE = Lucy::Index::PostingListWriter
void
set_default_mem_thresh(mem_thresh)
uint32_t mem_thresh;
PPCODE:
lucy_PListWriter_set_default_mem_thresh(mem_thresh);
END_XS
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Index::PostingListWriter",
);
$binding->append_xs($xs_code);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
sub bind_segreader {
my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
my $synopsis = <<'END_SYNOPSIS';
my $polyreader = Lucy::Index::IndexReader->open(
index => '/path/to/index',
);
my $seg_readers = $polyreader->seg_readers;
for my $seg_reader (@$seg_readers) {
my $seg_name = $seg_reader->get_seg_name;
my $num_docs = $seg_reader->doc_max;
print "Segment $seg_name ($num_docs documents):\n";
my $doc_reader = $seg_reader->obtain("Lucy::Index::DocReader");
for my $doc_id ( 1 .. $num_docs ) {
my $doc = $doc_reader->fetch_doc($doc_id);
print " $doc_id: $doc->{title}\n";
}
}
END_SYNOPSIS
$pod_spec->set_synopsis($synopsis);
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Index::SegReader",
);
$binding->set_pod_spec($pod_spec);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
sub bind_segwriter {
my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Index::SegWriter",
);
$binding->set_pod_spec($pod_spec);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
sub bind_segment {
my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
my $synopsis = <<'END_SYNOPSIS';
# Index-time.
package MyDataWriter;
use base qw( Lucy::Index::DataWriter );
buildlib/Lucy/Build/Binding/Index.pm view on Meta::CPAN
END_CONSTRUCTOR
$pod_spec->set_synopsis($synopsis);
$pod_spec->add_constructor( alias => 'new', sample => $constructor, );
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Index::Snapshot",
);
$binding->set_pod_spec($pod_spec);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
sub bind_sortcache {
my @hand_rolled = qw( Value );
my $xs_code = <<'END_XS_CODE';
MODULE = Lucy PACKAGE = Lucy::Index::SortCache
SV*
value(self, ...)
lucy_SortCache *self;
CODE:
{
static const XSBind_ParamSpec param_specs[1] = {
XSBIND_PARAM("ord", false)
};
int32_t locations[1];
int32_t ord = 0;
XSBind_locate_args(aTHX_ &ST(0), 1, items, param_specs, locations, 1);
ord = locations[0] < items ? (int32_t)SvIV(ST(locations[0])) : 0;
{
cfish_Obj *value = LUCY_SortCache_Value(self, ord);
RETVAL = XSBind_cfish_to_perl(aTHX_ value);
CFISH_DECREF(value);
}
}
OUTPUT: RETVAL
END_XS_CODE
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Index::SortCache",
);
$binding->exclude_method($_) for @hand_rolled;
$binding->append_xs($xs_code);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
sub bind_sortwriter {
my $xs_code = <<'END_XS';
MODULE = Lucy PACKAGE = Lucy::Index::SortWriter
void
set_default_mem_thresh(mem_thresh)
size_t mem_thresh;
PPCODE:
lucy_SortWriter_set_default_mem_thresh(mem_thresh);
END_XS
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Index::SortWriter",
);
$binding->append_xs($xs_code);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
1;
( run in 0.737 second using v1.01-cache-2.11-cpan-5511b514fd6 )