add_doc

$lucy->add_doc({
    location => $url,
    title    => $title,
    content  => $content,
});

Add a document to the index. The document must be supplied as a hashref, with field names as keys and content as values.

END_ADD_DOC_POD $pod_spec->set_synopsis($synopsis);

$pod_spec->add_constructor( sample => $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::Simple

void add_doc(self, doc_sv) lucy_Simple *self; SV *doc_sv; PPCODE: { lucy_Doc *doc = NULL;

// 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) {
        lucy_Indexer *indexer = LUCY_Simple_Get_Indexer(self);
        doc = LUCY_Indexer_Get_Stock_Doc(indexer);
        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_Simple_Add_Doc(self, doc);
}
END_XS_CODE

my $binding = Clownfish::CFC::Binding::Perl::Class->new(
    parcel     => "Lucy",
    class_name => "Lucy::Simple",
);
$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_test { my $xs_code = <<'END_XS_CODE'; MODULE = Lucy::Test PACKAGE = Lucy::Test

#include "Clownfish/TestHarness/TestFormatter.h" #include "Clownfish/TestHarness/TestSuite.h"

bool run_tests(package) char *package; CODE: cfish_String *class_name = cfish_Str_newf("%s", package); cfish_TestFormatter *formatter = (cfish_TestFormatter*)cfish_TestFormatterTAP_new(); cfish_TestSuite *suite = testlucy_Test_create_test_suite(); bool result = CFISH_TestSuite_Run_Batch(suite, class_name, formatter); CFISH_DECREF(class_name); CFISH_DECREF(formatter); CFISH_DECREF(suite);

RETVAL = result;
OUTPUT: RETVAL
END_XS_CODE

my $binding = Clownfish::CFC::Binding::Perl::Class->new(
    parcel     => "TestLucy",
    class_name => "Lucy::Test",
);
$binding->append_xs($xs_code);

Clownfish::CFC::Binding::Perl::Class->register($binding);
}

1;