Mailing List Archive

r3719 - in trunk: c_src/KinoSearch perl perl/lib perl/lib/KinoSearch perl/xs/KinoSearch
Author: creamyg
Date: 2008-08-04 18:18:34 -0700 (Mon, 04 Aug 2008)
New Revision: 3719

Added:
trunk/perl/xs/KinoSearch/Schema.c
Modified:
trunk/c_src/KinoSearch/Schema.bp
trunk/c_src/KinoSearch/Schema.c
trunk/perl/MANIFEST
trunk/perl/lib/KinoSearch.pm
trunk/perl/lib/KinoSearch/Schema.pm
Log:
Implement initialization of fields in Schema using a new method,
Schema_Init_Fields(), which has to be implemented by the binding.


Modified: trunk/c_src/KinoSearch/Schema.bp
===================================================================
--- trunk/c_src/KinoSearch/Schema.bp 2008-08-05 00:38:29 UTC (rev 3718)
+++ trunk/c_src/KinoSearch/Schema.bp 2008-08-05 01:18:34 UTC (rev 3719)
@@ -38,6 +38,11 @@
void
Add_Field(Schema *self, const CharBuf *field, const CharBuf *spec);

+ /** Add initial set of field name / field spec pairs to the Schema.
+ */
+ void
+ Init_Fields(Schema *self);
+
/** Return the FieldSpec for the specified field. If the field can't be
* found, return NULL.
*/

Modified: trunk/c_src/KinoSearch/Schema.c
===================================================================
--- trunk/c_src/KinoSearch/Schema.c 2008-08-05 00:38:29 UTC (rev 3718)
+++ trunk/c_src/KinoSearch/Schema.c 2008-08-05 01:18:34 UTC (rev 3719)
@@ -37,9 +37,10 @@
if (!self->sim || !OBJ_IS_A(self->sim, SIMILARITY))
CONFESS("Invalid Similarity");

- /* Init FieldSpec singleton storage. */
+ /* Init FieldSpec singleton storage, then add fields. */
if (fspec_singletons == NULL) fspec_singletons = Hash_new(0);
(void)REFCOUNT_INC(fspec_singletons);
+ Schema_Init_Fields(self);

ABSTRACT_CLASS_CHECK(self, SCHEMA);
return self;

Modified: trunk/perl/MANIFEST
===================================================================
--- trunk/perl/MANIFEST 2008-08-05 00:38:29 UTC (rev 3718)
+++ trunk/perl/MANIFEST 2008-08-05 01:18:34 UTC (rev 3719)
@@ -382,6 +382,7 @@
xs/KinoSearch/Index/SegWriter.c
xs/KinoSearch/Obj.c
xs/KinoSearch/Obj/FastObj.c
+xs/KinoSearch/Schema.c
xs/KinoSearch/Util/Carp.c
xs/KinoSearch/Util/Native.c
xs/XSBind.c

Modified: trunk/perl/lib/KinoSearch/Schema.pm
===================================================================
--- trunk/perl/lib/KinoSearch/Schema.pm 2008-08-05 00:38:29 UTC (rev 3718)
+++ trunk/perl/lib/KinoSearch/Schema.pm 2008-08-05 01:18:34 UTC (rev 3719)
@@ -4,22 +4,6 @@

__END__

-__XS__
-
-MODULE = KinoSearch PACKAGE = KinoSearch::Schema
-
-SV*
-_retrieve_fields_hashref(name)
- const char *name;
-CODE:
-{
- HV* fields_hash = get_hv(name, 0);
- RETVAL = fields_hash == NULL
- ? newSV(0)
- : newRV_inc((SV*)fields_hash);
-}
-OUTPUT: RETVAL
-
__AUTO_XS__

{ "KinoSearch::Schema" => {
@@ -32,12 +16,13 @@
fetch_analyzer
fetch_sim
fetch_posting
+ init_fields
num_fields
field_num
_all_fields|all_fields
add_field )
],
- make_constructors => [qw( _new )],
+ make_constructors => [qw( new )],
}
}


Modified: trunk/perl/lib/KinoSearch.pm
===================================================================
--- trunk/perl/lib/KinoSearch.pm 2008-08-05 00:38:29 UTC (rev 3718)
+++ trunk/perl/lib/KinoSearch.pm 2008-08-05 01:18:34 UTC (rev 3719)
@@ -363,23 +363,8 @@

{
package KinoSearch::Schema;
- use KinoSearch::Util::ToolSet qw( confess blessed );
+ use KinoSearch::Util::ToolSet qw( blessed );

- 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;

Added: trunk/perl/xs/KinoSearch/Schema.c
===================================================================
--- trunk/perl/xs/KinoSearch/Schema.c (rev 0)
+++ trunk/perl/xs/KinoSearch/Schema.c 2008-08-05 01:18:34 UTC (rev 3719)
@@ -0,0 +1,53 @@
+#include "xs/XSBind.h"
+#include "KinoSearch/Schema.h"
+#include "KinoSearch/Util/Stringhelper.h"
+
+void
+kino_Schema_init_fields(kino_Schema *self)
+{
+ kino_CharBuf *schema_class = Kino_Schema_Get_Class_Name(self);
+ kino_CharBuf *hash_name = kino_CB_newf("%o::fields", schema_class);
+ HV* fields_hash = get_hv((char*)Kino_CB_Get_Ptr8(hash_name), 0);
+ REFCOUNT_DEC(hash_name);
+
+ if (!fields_hash) {
+ CONFESS("Can't find %%%o::fields hash", schema_class);
+ }
+ else {
+ chy_u32_t num_keys = hv_iterinit(fields_hash);
+ kino_ZombieCharBuf field_name = KINO_ZCB_BLANK;
+ kino_ZombieCharBuf fspec_class = KINO_ZCB_BLANK;
+
+ while (num_keys--) {
+ HE *entry = hv_iternext(fields_hash);
+ SV *value_sv = HeVAL(entry);
+ STRLEN value_len;
+ char *value = SvPVutf8(value_sv, value_len);
+ STRLEN key_len;
+ /* Copied from Perl 5.10.0 HePV macro, because the HePV macro in
+ * earlier versions of Perl triggers a compiler warning. */
+ char *key = HeKLEN(entry) == HEf_SVKEY
+ ? SvPV(HeKEY_sv(entry), key_len)
+ : ((key_len = HeKLEN(entry)), HeKEY(entry));
+
+ if (!kino_StrHelp_utf8_valid(key, key_len)) {
+ /* Force field name to UTF-8. */
+ SV *key_sv = HeSVKEY_force(entry);
+ key = SvPVutf8(key_sv, key_len);
+ }
+
+ Kino_ZCB_Assign_Str(&field_name, key, key_len);
+ Kino_ZCB_Assign_Str(&fspec_class, value, value_len);
+ Kino_Schema_Add_Field(self, (kino_CharBuf*)&field_name,
+ (kino_CharBuf*)&fspec_class);
+ }
+ }
+}
+
+/* Copyright 2005-2008 Marvin Humphrey
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * under the same terms as Perl itself.
+ */
+
+


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