You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2010/06/11 01:57:37 UTC
svn commit: r953507 - in /lucene/lucy/trunk: core/Lucy/Plan/BlobType.bp
core/Lucy/Plan/BlobType.c core/Lucy/Test/Plan/TestBlobType.bp
core/Lucy/Test/Plan/TestBlobType.c perl/lib/Lucy/Test.pm
perl/t/core/231-blob_type.t
Author: marvin
Date: Thu Jun 10 23:57:37 2010
New Revision: 953507
URL: http://svn.apache.org/viewvc?rev=953507&view=rev
Log:
Add Lucy::Plan::BlobType. (LUCY-107)
Added:
lucene/lucy/trunk/core/Lucy/Plan/BlobType.bp (with props)
lucene/lucy/trunk/core/Lucy/Plan/BlobType.c (with props)
lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.bp (with props)
lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.c (with props)
lucene/lucy/trunk/perl/t/core/231-blob_type.t (with props)
Modified:
lucene/lucy/trunk/perl/lib/Lucy/Test.pm
Added: lucene/lucy/trunk/core/Lucy/Plan/BlobType.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Plan/BlobType.bp?rev=953507&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Plan/BlobType.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Plan/BlobType.bp Thu Jun 10 23:57:37 2010
@@ -0,0 +1,63 @@
+parcel Lucy;
+
+/** Default behaviors for binary fields.
+ *
+ * BlobType is an implementation of FieldType tuned for use with fields
+ * containing binary data, which cannot be indexed or searched -- only stored.
+ */
+class Lucy::Plan::BlobType extends Lucy::Plan::FieldType
+ : dumpable {
+
+
+ /**
+ * @param similarity A Similarity.
+ * @param stored boolean indicating whether the field should be stored.
+ * @param sortable boolean indicating whether the field should be
+ * sortable.
+ */
+ public inert BlobType*
+ init(BlobType *self, Similarity *similarity = NULL);
+
+ public inert BlobType*
+ init2(BlobType *self, Similarity *similarity = NULL,
+ bool_t stored = true, bool_t sortable = false);
+
+ public inert incremented BlobType*
+ new(Similarity *similarity);
+
+ /** Returns true.
+ */
+ public bool_t
+ Binary(BlobType *self);
+
+ uint8_t
+ Scalar_Type_ID(BlobType *self);
+
+ incremented Hash*
+ Dump_For_Schema(BlobType *self);
+
+ public incremented Hash*
+ Dump(BlobType *self);
+
+ public incremented BlobType*
+ Load(BlobType *self, Obj *dump);
+
+ public bool_t
+ Equals(BlobType *self, Obj *other);
+}
+
+/* Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
Propchange: lucene/lucy/trunk/core/Lucy/Plan/BlobType.bp
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/lucy/trunk/core/Lucy/Plan/BlobType.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Plan/BlobType.c?rev=953507&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Plan/BlobType.c (added)
+++ lucene/lucy/trunk/core/Lucy/Plan/BlobType.c Thu Jun 10 23:57:37 2010
@@ -0,0 +1,148 @@
+#define C_LUCY_BLOBTYPE
+#include "Lucy/Util/ToolSet.h"
+
+#include "Lucy/Plan/BlobType.h"
+#include "Lucy/Index/Similarity.h"
+
+BlobType*
+BlobType_new(Similarity *similarity)
+{
+ BlobType *self = (BlobType*)VTable_Make_Obj(BLOBTYPE);
+ return BlobType_init(self, similarity);
+}
+
+BlobType*
+BlobType_init(BlobType *self, Similarity *similarity)
+{
+ BlobType_init2(self, similarity, true, false);
+ return self;
+}
+
+BlobType*
+BlobType_init2(BlobType *self, Similarity *similarity, bool_t stored,
+ bool_t sortable)
+{
+ FType_init2((FieldType*)self, similarity, 1.0, false, stored, sortable);
+ return self;
+}
+
+bool_t
+BlobType_binary(BlobType *self)
+{
+ UNUSED_VAR(self);
+ return true;
+}
+
+uint8_t
+BlobType_scalar_type_id(BlobType *self)
+{
+ UNUSED_VAR(self);
+ return Obj_BLOB;
+}
+
+bool_t
+BlobType_equals(BlobType *self, Obj *other)
+{
+ BlobType *evil_twin = (BlobType*)other;
+ if (evil_twin == self) return true;
+ if (!Obj_Is_A(other, BLOBTYPE)) return false;
+ return FType_equals((FieldType*)self, other);
+}
+
+Hash*
+BlobType_dump_for_schema(BlobType *self)
+{
+ Hash *dump = Hash_new(0);
+ Hash_Store_Str(dump, "type", 4, (Obj*)CB_newf("blob"));
+
+ // Store attributes that override the defaults -- even if they're
+ // meaningless.
+ if (self->boost != 1.0) {
+ Hash_Store_Str(dump, "boost", 5, (Obj*)CB_newf("%f64", self->boost));
+ }
+ if (self->indexed) {
+ Hash_Store_Str(dump, "indexed", 7, (Obj*)CB_newf("1"));
+ }
+ if (!self->stored) {
+ Hash_Store_Str(dump, "stored", 6, (Obj*)CB_newf("0"));
+ }
+ if (self->sortable) {
+ Hash_Store_Str(dump, "sortable", 8, (Obj*)CB_newf("1"));
+ }
+
+ return dump;
+}
+
+Hash*
+BlobType_dump(BlobType *self)
+{
+ Hash *dump = BlobType_Dump_For_Schema(self);
+ Hash_Store_Str(dump, "_class", 6,
+ (Obj*)CB_Clone(BlobType_Get_Class_Name(self)));
+ if (self->sim) {
+ Hash_Store_Str(dump, "similarity", 10, (Obj*)Sim_Dump(self->sim));
+ }
+ DECREF(Hash_Delete_Str(dump, "type", 4));
+ return dump;
+}
+
+BlobType*
+BlobType_load(BlobType *self, Obj *dump)
+{
+ UNUSED_VAR(self);
+ Hash *source = (Hash*)CERTIFY(dump, HASH);
+ CharBuf *class_name = (CharBuf*)Hash_Fetch_Str(source, "_class", 6);
+ VTable *vtable
+ = (class_name != NULL && Obj_Is_A((Obj*)class_name, CHARBUF))
+ ? VTable_singleton(class_name, NULL)
+ : BLOBTYPE;
+ BlobType *loaded = (BlobType*)VTable_Make_Obj(vtable);
+
+ // Extract boost.
+ Obj *boost_dump = Hash_Fetch_Str(source, "boost", 5);
+ float boost = boost_dump ? (float)Obj_To_F64(boost_dump) : 1.0f;
+
+ // Find boolean properties.
+ Obj *indexed_dump = Hash_Fetch_Str(source, "indexed", 7);
+ Obj *stored_dump = Hash_Fetch_Str(source, "stored", 6);
+ Obj *sort_dump = Hash_Fetch_Str(source, "sortable", 8);
+ bool_t indexed = indexed_dump ? (bool_t)Obj_To_I64(indexed_dump) : false;
+ bool_t stored = stored_dump ? (bool_t)Obj_To_I64(stored_dump) : true;
+ bool_t sortable = sort_dump ? (bool_t)Obj_To_I64(sort_dump) : false;
+
+ // Extract a Similarity.
+ Similarity *sim = NULL;
+ Obj *sim_dump = Hash_Fetch_Str(source, "similarity", 10);
+ if (sim_dump) {
+ if (Obj_Is_A(sim_dump, SIMILARITY)) {
+ // Schema munged the dump and installed a shared sim.
+ sim = (Similarity*)INCREF(sim_dump);
+ }
+ else {
+ sim = (Similarity*)CERTIFY(
+ Obj_Load(sim_dump, sim_dump), SIMILARITY);
+ }
+ }
+
+ BlobType_init2(loaded, sim, stored, sortable);
+ loaded->boost = boost;
+ loaded->indexed = indexed;
+
+ return loaded;
+}
+
+/* Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
Propchange: lucene/lucy/trunk/core/Lucy/Plan/BlobType.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.bp?rev=953507&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.bp Thu Jun 10 23:57:37 2010
@@ -0,0 +1,22 @@
+parcel Lucy;
+
+inert class Lucy::Test::Plan::TestBlobType {
+ inert void
+ run_tests();
+}
+
+/* Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
Propchange: lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.bp
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.c?rev=953507&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.c (added)
+++ lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.c Thu Jun 10 23:57:37 2010
@@ -0,0 +1,75 @@
+#define C_LUCY_TESTBLOBTYPE
+#include "Lucy/Util/ToolSet.h"
+
+#include "Lucy/Test.h"
+#include "Lucy/Test/Plan/TestBlobType.h"
+#include "Lucy/Test/Index/Similarity/DummySimilarity.h"
+#include "Lucy/Plan/BlobType.h"
+
+static void
+test_simple_accessors(TestBatch *batch)
+{
+ BlobType *type = BlobType_new(NULL);
+ ASSERT_TRUE(batch, BlobType_Scalar_Type_ID(type) == Obj_BLOB,
+ "Scalar_Type_ID()");
+ ASSERT_TRUE(batch, BlobType_Binary(type), "Binary() returns true");
+ DECREF(type);
+}
+
+static void
+test_Dump_Load_and_Equals(TestBatch *batch)
+{
+ Similarity *sim = (Similarity*)DummySim_new(1);
+ BlobType *type = BlobType_new(sim);
+
+ // Set to non-defaults to stress Dump/Load.
+ BlobType_Set_Sortable(type, true);
+
+ {
+ Obj *dump = (Obj*)BlobType_Dump(type);
+ Obj *clone = Obj_Load(dump, dump);
+ ASSERT_TRUE(batch, BlobType_Equals(type, (Obj*)clone),
+ "Dump => Load round trip");
+ DECREF(dump);
+ DECREF(clone);
+ }
+
+ {
+ Obj *dump = (Obj*)BlobType_Dump_For_Schema(type);
+ // (This step is normally performed by Schema_Load() internally.)
+ Hash_Store_Str((Hash*)dump, "similarity", 10, INCREF(sim));
+ BlobType *clone = BlobType_load(NULL, dump);
+ ASSERT_TRUE(batch, BlobType_Equals(type, (Obj*)clone),
+ "Dump_For_Schema => Load round trip");
+ DECREF(dump);
+ DECREF(clone);
+ }
+
+ DECREF(type);
+}
+
+void
+TestBlobType_run_tests()
+{
+ TestBatch *batch = TestBatch_new(4);
+ TestBatch_Plan(batch);
+ test_simple_accessors(batch);
+ test_Dump_Load_and_Equals(batch);
+ DECREF(batch);
+}
+
+/* Copyright 2010 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
Propchange: lucene/lucy/trunk/core/Lucy/Test/Plan/TestBlobType.c
------------------------------------------------------------------------------
svn:eol-style = native
Modified: lucene/lucy/trunk/perl/lib/Lucy/Test.pm
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/lib/Lucy/Test.pm?rev=953507&r1=953506&r2=953507&view=diff
==============================================================================
--- lucene/lucy/trunk/perl/lib/Lucy/Test.pm (original)
+++ lucene/lucy/trunk/perl/lib/Lucy/Test.pm Thu Jun 10 23:57:37 2010
@@ -50,6 +50,9 @@ PPCODE:
lucy_TestVArray_run_tests();
}
// Lucy::Plan
+ else if (strEQ(package, "TestBlobType")) {
+ lucy_TestBlobType_run_tests();
+ }
else if (strEQ(package, "TestFieldType")) {
lucy_TestFType_run_tests();
}
Added: lucene/lucy/trunk/perl/t/core/231-blob_type.t
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/t/core/231-blob_type.t?rev=953507&view=auto
==============================================================================
--- lucene/lucy/trunk/perl/t/core/231-blob_type.t (added)
+++ lucene/lucy/trunk/perl/t/core/231-blob_type.t Thu Jun 10 23:57:37 2010
@@ -0,0 +1,6 @@
+use strict;
+use warnings;
+
+use Lucy::Test;
+Lucy::Test::run_tests("TestBlobType");
+
Propchange: lucene/lucy/trunk/perl/t/core/231-blob_type.t
------------------------------------------------------------------------------
svn:eol-style = native