You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/08/30 19:28:35 UTC
[02/19] lucy git commit: Remove Document POD whitelist
Remove Document POD whitelist
Additional Document methods added to the Perl API:
- Store
- Get_Size
- Extract
- Field_Names
These methods are needed for the C bindings but they aren't really
useful from Perl. They can be blacklisted later.
Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/75330009
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/75330009
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/75330009
Branch: refs/heads/master
Commit: 753300094f6a70c998318712d61608477fad0156
Parents: c198e10
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Thu Aug 20 21:49:13 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Sun Aug 23 15:02:02 2015 +0200
----------------------------------------------------------------------
core/Lucy/Document/Doc.cfh | 18 +++++-----
core/Lucy/Document/HitDoc.cfh | 4 +--
perl/buildlib/Lucy/Build/Binding/Document.pm | 42 +++++++++++++++++++----
perl/t/200-doc.t | 5 ++-
4 files changed, 51 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucy/blob/75330009/core/Lucy/Document/Doc.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Document/Doc.cfh b/core/Lucy/Document/Doc.cfh
index c5cc855..4db55d6 100644
--- a/core/Lucy/Document/Doc.cfh
+++ b/core/Lucy/Document/Doc.cfh
@@ -49,8 +49,11 @@ public class Lucy::Document::Doc inherits Clownfish::Obj {
Get_Doc_ID(Doc *self);
/** Store a field value in the Doc.
+ *
+ * @param field The field name
+ * @param value The value
*/
- void
+ public void
Store(Doc *self, String *field, Obj *value);
/** Set the doc's field's attribute.
@@ -68,17 +71,14 @@ public class Lucy::Document::Doc inherits Clownfish::Obj {
public uint32_t
Get_Size(Doc *self);
- /** Retrieve the field's value, or NULL if the field is not present. If
- * the field is a text type, assign it to `target`. Otherwise,
- * return the interior object. Callers must check to verify the kind of
- * object returned.
+ /** Retrieve the field's value, or NULL if the field is not present.
*/
- nullable incremented Obj*
+ public nullable incremented Obj*
Extract(Doc *self, String *field);
/** Return a list of names of all fields present.
*/
- incremented Vector*
+ public incremented Vector*
Field_Names(Doc *self);
/* Unimplemented methods.
@@ -92,10 +92,10 @@ public class Lucy::Document::Doc inherits Clownfish::Obj {
incremented Doc*
Deserialize(decremented Doc *self, InStream *instream);
- public incremented Hash*
+ incremented Hash*
Dump(Doc *self);
- public incremented Doc*
+ incremented Doc*
Load(Doc *self, Obj *dump);
public void
http://git-wip-us.apache.org/repos/asf/lucy/blob/75330009/core/Lucy/Document/HitDoc.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Document/HitDoc.cfh b/core/Lucy/Document/HitDoc.cfh
index 52ce232..3fc17ec 100644
--- a/core/Lucy/Document/HitDoc.cfh
+++ b/core/Lucy/Document/HitDoc.cfh
@@ -53,10 +53,10 @@ public class Lucy::Document::HitDoc inherits Lucy::Document::Doc {
public bool
Equals(HitDoc *self, Obj *other);
- public incremented Hash*
+ incremented Hash*
Dump(HitDoc *self);
- public incremented HitDoc*
+ incremented HitDoc*
Load(HitDoc *self, Obj *dump);
void
http://git-wip-us.apache.org/repos/asf/lucy/blob/75330009/perl/buildlib/Lucy/Build/Binding/Document.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build/Binding/Document.pm b/perl/buildlib/Lucy/Build/Binding/Document.pm
index 2316034..abf5842 100644
--- a/perl/buildlib/Lucy/Build/Binding/Document.pm
+++ b/perl/buildlib/Lucy/Build/Binding/Document.pm
@@ -26,8 +26,7 @@ sub bind_all {
}
sub bind_doc {
- my @exposed = qw( Set_Doc_ID Get_Doc_ID Get_Fields );
- my @hand_rolled = qw( Set_Fields Get_Fields );
+ my @hand_rolled = qw( Store Set_Fields Get_Fields );
my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
my $synopsis = <<'END_SYNOPSIS';
@@ -46,9 +45,30 @@ END_SYNOPSIS
fields => { foo => 'foo foo', bar => 'bar bar' },
);
END_CONSTRUCTOR
+ my $store_pod = <<'END_POD';
+=head2 store(field, value)
+
+Store a field value in the Doc.
+
+=over
+
+=item *
+
+B<field> - The field name.
+
+=item *
+
+B<value> - The value.
+
+=back
+END_POD
$pod_spec->set_synopsis($synopsis);
$pod_spec->add_constructor( alias => 'new', sample => $constructor );
- $pod_spec->add_method( method => $_, alias => lc($_) ) for @exposed;
+ $pod_spec->add_method(
+ method => 'Store',
+ alias => 'store',
+ pod => $store_pod,
+ );
my $xs_code = <<'END_XS_CODE';
MODULE = Lucy PACKAGE = Lucy::Document::Doc
@@ -88,6 +108,19 @@ CODE:
}
OUTPUT: RETVAL
+void
+store(self, field, value_sv)
+ lucy_Doc *self;
+ cfish_String *field;
+ SV *value_sv;
+PPCODE:
+{
+ cfish_Obj *value
+ = (cfish_Obj*)XSBind_perl_to_cfish(aTHX_ value_sv, CFISH_OBJ);
+ LUCY_Doc_Store(self, field, value);
+ CFISH_DECREF(value);
+}
+
SV*
get_fields(self, ...)
lucy_Doc *self;
@@ -117,8 +150,6 @@ END_XS_CODE
}
sub bind_hitdoc {
- my @exposed = qw( Set_Score Get_Score );
-
my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new;
my $synopsis = <<'END_SYNOPSIS';
while ( my $hit_doc = $hits->next ) {
@@ -128,7 +159,6 @@ sub bind_hitdoc {
}
END_SYNOPSIS
$pod_spec->set_synopsis($synopsis);
- $pod_spec->add_method( method => $_, alias => lc($_) ) for @exposed;
my $xs_code = <<'END_XS_CODE';
MODULE = Lucy PACKAGE = Lucy::Document::HitDoc
http://git-wip-us.apache.org/repos/asf/lucy/blob/75330009/perl/t/200-doc.t
----------------------------------------------------------------------
diff --git a/perl/t/200-doc.t b/perl/t/200-doc.t
index 63a9564..8867260 100644
--- a/perl/t/200-doc.t
+++ b/perl/t/200-doc.t
@@ -16,7 +16,7 @@
use strict;
use warnings;
-use Test::More tests => 11;
+use Test::More tests => 12;
use Storable qw( nfreeze thaw );
use Lucy::Test;
@@ -30,6 +30,9 @@ is_deeply( $doc->get_fields, { foo => 'oink' }, "set_fields" );
$doc->{foo} = "blah";
is_deeply( $doc->get_fields, { foo => 'blah' }, "overloading" );
+$doc->store(title => "A title");
+is_deeply( $doc->extract('title'), "A title", "store/extract" );
+
my %hash = ( foo => 'foo' );
$doc = Lucy::Document::Doc->new(
fields => \%hash,