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/10 05:21:55 UTC
svn commit: r953207 - in /lucene/lucy/trunk: core/Lucy/Plan/
core/Lucy/Test/Plan/ perl/lib/Lucy/ perl/t/core/
Author: marvin
Date: Thu Jun 10 03:21:54 2010
New Revision: 953207
URL: http://svn.apache.org/viewvc?rev=953207&view=rev
Log:
Add Lucy::Plan::FieldType. (LUCY-105)
Added:
lucene/lucy/trunk/core/Lucy/Plan/
lucene/lucy/trunk/core/Lucy/Plan/FieldType.bp (with props)
lucene/lucy/trunk/core/Lucy/Plan/FieldType.c (with props)
lucene/lucy/trunk/core/Lucy/Test/Plan/
lucene/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.bp (with props)
lucene/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.c (with props)
lucene/lucy/trunk/perl/t/core/229-field_type.t (with props)
Modified:
lucene/lucy/trunk/perl/lib/Lucy/Test.pm
Added: lucene/lucy/trunk/core/Lucy/Plan/FieldType.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Plan/FieldType.bp?rev=953207&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Plan/FieldType.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Plan/FieldType.bp Thu Jun 10 03:21:54 2010
@@ -0,0 +1,169 @@
+parcel Lucy;
+
+/** Define a field's behavior.
+ *
+ * FieldType is an abstract class defining a set of traits and behaviors which
+ * may be associated with one or more field names.
+ *
+ * Properties which are common to all field types include <code>boost</code>,
+ * <code>indexed</code>, <code>stored</code>, <code>sortable</code>,
+ * <code>binary</code>, and <code>similarity</code>.
+ *
+ * The <code>boost</code> property is a floating point scoring multiplier
+ * which defaults to 1.0. Values greater than 1.0 cause the field to
+ * contribute more to a document's score; lower values, less.
+ *
+ * The <code>indexed</code> property indicates whether the field should be
+ * indexed (so that it can be searched).
+ *
+ * The <code>stored</code> property indicates whether to store the raw field
+ * value, so that it can be retrieved when a document turns up in a search.
+ *
+ * The <code>sortable</code> property indicates whether search results should
+ * be sortable based on the contents of the field.
+ *
+ * The <code>binary</code> property indicates whether the field contains
+ * binary or text data. Unlike most other properties, <code>binary</code> is
+ * not settable.
+ *
+ * The <code>similarity</code> property is a
+ * L<Similarity|Lucy::Index::Similarity> object which defines matching
+ * and scoring behavior for the field. It is required if the field is
+ * <code>indexed</code>.
+ */
+abstract class Lucy::Plan::FieldType cnick FType
+ extends Lucy::Object::Obj {
+
+ Similarity *sim;
+ float boost;
+ bool_t indexed;
+ bool_t stored;
+ bool_t sortable;
+
+ inert FieldType*
+ init(FieldType *self, Similarity *similarity = NULL);
+
+ inert FieldType*
+ init2(FieldType *self, Similarity *similarity = NULL, float boost = 1.0,
+ bool_t indexed = false, bool_t stored = false,
+ bool_t sortable = false);
+
+ public void
+ Destroy(FieldType *self);
+
+ /** Setter for <code>boost</code>.
+ */
+ public void
+ Set_Boost(FieldType *self, float boost);
+
+ /** Accessor for <code>boost</code>.
+ */
+ public float
+ Get_Boost(FieldType *self);
+
+ /** Setter for <code>indexed</code>.
+ */
+ public void
+ Set_Indexed(FieldType *self, bool_t indexed);
+
+ /** Accessor for <code>indexed</code>.
+ */
+ public bool_t
+ Indexed(FieldType *self);
+
+ /** Setter for <code>stored</code>.
+ */
+ public void
+ Set_Stored(FieldType *self, bool_t stored);
+
+ /** Accessor for <code>stored</code>.
+ */
+ public bool_t
+ Stored(FieldType *self);
+
+ /** Setter for <code>sortable</code>.
+ */
+ public void
+ Set_Sortable(FieldType *self, bool_t sortable);
+
+ /** Accessor for <code>sortable</code>.
+ */
+ public bool_t
+ Sortable(FieldType *self);
+
+ /** Indicate whether the field contains binary data.
+ */
+ public bool_t
+ Binary(FieldType *self);
+
+ /** Accessor for <code>similarity</code>.
+ */
+ public nullable Similarity*
+ Get_Similarity(FieldType *self);
+
+ /** Compare two values for the field. The default implementation
+ * dispatches to the Compare_To() method of argument <code>a</code>.
+ *
+ * @return a negative number if a is "less than" b, 0 if they are "equal",
+ * and a positive number if a is "greater than" b.
+ */
+ public int32_t
+ Compare_Values(FieldType *self, Obj *a, Obj *b);
+
+ /** NULL-safe comparison wrapper which sorts NULLs towards the back.
+ */
+ inert inline int32_t
+ null_back_compare_values(FieldType *self, Obj *a, Obj *b);
+
+ /** Return the Scalar_ID() of the FieldType's underlying data type.
+ */
+ abstract uint8_t
+ Scalar_Type_ID(FieldType *self);
+
+ /** Produce a special mimimal dump which does not include Similarity or
+ * Analyzer dumps. For exclusive internal use by Schema.
+ */
+ abstract incremented Hash*
+ Dump_For_Schema(FieldType *self);
+
+ /** Compares all common properties.
+ */
+ public bool_t
+ Equals(FieldType *self, Obj *other);
+}
+
+__C__
+
+static CHY_INLINE int32_t
+lucy_FType_null_back_compare_values(lucy_FieldType *self,
+ lucy_Obj *a, lucy_Obj *b)
+{
+ if (a == NULL) {
+ if (b == NULL) { return 0; }
+ else { return 1; }
+ }
+ else if (b == NULL) {
+ return -1;
+ }
+ else {
+ return Lucy_FType_Compare_Values(self, a, b);
+ }
+}
+
+__END_C__
+
+/* 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/FieldType.bp
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/lucy/trunk/core/Lucy/Plan/FieldType.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Plan/FieldType.c?rev=953207&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Plan/FieldType.c (added)
+++ lucene/lucy/trunk/core/Lucy/Plan/FieldType.c Thu Jun 10 03:21:54 2010
@@ -0,0 +1,111 @@
+#define C_LUCY_FIELDTYPE
+#include "Lucy/Util/ToolSet.h"
+
+#include "Lucy/Plan/FieldType.h"
+#include "Lucy/Index/Similarity.h"
+#include "Lucy/Index/Similarity/LuceneSimilarity.h"
+
+FieldType*
+FType_init(FieldType *self, Similarity *similarity)
+{
+ return FType_init2(self, similarity, 1.0f, false, false, false);
+}
+
+FieldType*
+FType_init2(FieldType *self, Similarity *similarity, float boost,
+ bool_t indexed, bool_t stored, bool_t sortable)
+{
+ self->sim = (Similarity*)INCREF(similarity);
+ self->sim = similarity ? (Similarity*)INCREF(similarity)
+ : indexed ? (Similarity*)LuceneSim_new()
+ : NULL;
+
+ if (indexed && !self->sim) {
+ THROW(ERR, "Indexed FieldType missing Similarity");
+ }
+ self->boost = boost;
+ self->indexed = indexed;
+ self->stored = stored;
+ self->sortable = sortable;
+ ABSTRACT_CLASS_CHECK(self, FIELDTYPE);
+ return self;
+}
+
+void
+FType_destroy(FieldType *self)
+{
+ DECREF(self->sim);
+ SUPER_DESTROY(self, FIELDTYPE);
+}
+
+void
+FType_set_boost(FieldType *self, float boost)
+ { self->boost = boost; }
+void
+FType_set_indexed(FieldType *self, bool_t indexed)
+ { self->indexed = !!indexed; }
+void
+FType_set_stored(FieldType *self, bool_t stored)
+ { self->stored = !!stored; }
+void
+FType_set_sortable(FieldType *self, bool_t sortable)
+ { self->sortable = !!sortable; }
+
+float
+FType_get_boost(FieldType *self) { return self->boost; }
+bool_t
+FType_indexed(FieldType *self) { return self->indexed; }
+bool_t
+FType_stored(FieldType *self) { return self->stored; }
+bool_t
+FType_sortable(FieldType *self) { return self->sortable; }
+Similarity*
+FType_get_similarity(FieldType *self) { return self->sim; }
+
+bool_t
+FType_binary(FieldType *self) {
+ UNUSED_VAR(self);
+ return false;
+}
+
+int32_t
+FType_compare_values(FieldType *self, Obj *a, Obj *b)
+{
+ UNUSED_VAR(self);
+ return Obj_Compare_To(a, b);
+}
+
+bool_t
+FType_equals(FieldType *self, Obj *other)
+{
+ FieldType *evil_twin = (FieldType*)other;
+ if (!other) return false;
+ if (evil_twin == self) return true;
+ if (!Obj_Is_A(other, FIELDTYPE)) return false;
+ if (self->boost != evil_twin->boost) return false;
+ if (!!self->indexed != !!evil_twin->indexed) return false;
+ if (!!self->stored != !!evil_twin->stored) return false;
+ if (!!self->sortable != !!evil_twin->sortable) return false;
+ if (!!self->sim != !!evil_twin->sim) return false;
+ if (!!FType_Binary(self) != !!FType_Binary(evil_twin)) return false;
+ if (self->sim) {
+ if (!Sim_Equals(self->sim, (Obj*)evil_twin->sim)) return false;
+ }
+ return true;
+}
+
+/* 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/FieldType.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.bp?rev=953207&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.bp (added)
+++ lucene/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.bp Thu Jun 10 03:21:54 2010
@@ -0,0 +1,34 @@
+parcel Lucy;
+
+inert class Lucy::Test::Plan::TestFieldType cnick TestFType {
+ inert void
+ run_tests();
+}
+
+class Lucy::Test::Plan::DummyFieldType
+ extends Lucy::Plan::FieldType {
+
+ bool_t binary;
+
+ inert incremented DummyFieldType*
+ new(Similarity *similarity = NULL);
+
+ public bool_t
+ Binary(DummyFieldType *self);
+}
+
+/* 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/TestFieldType.bp
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.c?rev=953207&view=auto
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.c (added)
+++ lucene/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.c Thu Jun 10 03:21:54 2010
@@ -0,0 +1,149 @@
+#define C_LUCY_DUMMYFIELDTYPE
+#include "Lucy/Util/ToolSet.h"
+
+#include "Lucy/Test.h"
+#include "Lucy/Test/Plan/TestFieldType.h"
+#include "Lucy/Test/TestUtils.h"
+#include "Lucy/Test/Index/Similarity/DummySimilarity.h"
+
+DummyFieldType*
+DummyFieldType_new(Similarity *similarity)
+{
+ DummyFieldType *self = (DummyFieldType*)VTable_Make_Obj(DUMMYFIELDTYPE);
+ self->binary = false;
+ return (DummyFieldType*)FType_init((FieldType*)self, similarity);
+}
+
+bool_t
+DummyFieldType_binary(DummyFieldType *self) { return self->binary; }
+
+static void
+test_primitive_accessors(TestBatch *batch)
+{
+ FieldType *type = (FieldType*)DummyFieldType_new(NULL);
+
+ ASSERT_FALSE(batch, FType_Indexed(type), "indexed false by default");
+ FType_Set_Indexed(type, true);
+ ASSERT_TRUE(batch, FType_Indexed(type), "Set_Indexed()");
+
+ ASSERT_FALSE(batch, FType_Stored(type), "stored false by default");
+ FType_Set_Stored(type, true);
+ ASSERT_TRUE(batch, FType_Stored(type), "Set_Stored()");
+
+ ASSERT_FALSE(batch, FType_Sortable(type), "sortable false by default");
+ FType_Set_Sortable(type, true);
+ ASSERT_TRUE(batch, FType_Sortable(type), "Set_Sortable()");
+
+ ASSERT_TRUE(batch, FType_Get_Boost(type) == 1.0f,
+ "Boost defaults to 1.0");
+ FType_Set_Boost(type, 2.0f);
+ ASSERT_TRUE(batch, FType_Get_Boost(type) == 2.0f, "Set_Boost()");
+
+ DECREF(type);
+}
+
+static void
+test_Compare_Values(TestBatch *batch)
+{
+ FieldType *type = (FieldType*)DummyFieldType_new(NULL);
+ ZombieCharBuf *a = ZCB_WRAP_STR("a", 1);
+ ZombieCharBuf *b = ZCB_WRAP_STR("b", 1);
+
+ ASSERT_TRUE(batch, FType_Compare_Values(type, (Obj*)a, (Obj*)b) < 0,
+ "a less than b");
+ ASSERT_TRUE(batch, FType_Compare_Values(type, (Obj*)b, (Obj*)a) > 0,
+ "b greater than a");
+ ASSERT_TRUE(batch, FType_Compare_Values(type, (Obj*)b, (Obj*)b) == 0,
+ "b equals b");
+
+ DECREF(type);
+}
+
+void
+test_Equals(TestBatch *batch)
+{
+ FieldType *type = (FieldType*)DummyFieldType_new(NULL);
+
+ ASSERT_FALSE(batch, FType_Equals(type, NULL),
+ "Equals() false for NULL other");
+ ASSERT_FALSE(batch, FType_Equals(type, (Obj*)&EMPTY),
+ "Equals() false for non-FieldType other");
+
+ FieldType *doppelganger = (FieldType*)DummyFieldType_new(NULL);
+ ASSERT_TRUE(batch, FType_Equals(type, (Obj*)doppelganger), "Equals()");
+ DECREF(doppelganger);
+
+ FieldType *indexed_differs = (FieldType*)DummyFieldType_new(NULL);
+ FType_Set_Indexed(indexed_differs, true);
+ ASSERT_FALSE(batch, FType_Equals(type, (Obj*)indexed_differs),
+ "Different value for 'indexed' spoils Equals()");
+ DECREF(indexed_differs);
+
+ FieldType *stored_differs = (FieldType*)DummyFieldType_new(NULL);
+ FType_Set_Stored(stored_differs, true);
+ ASSERT_FALSE(batch, FType_Equals(type, (Obj*)stored_differs),
+ "Different value for 'stored' spoils Equals()");
+ DECREF(stored_differs);
+
+ FieldType *sortable_differs = (FieldType*)DummyFieldType_new(NULL);
+ FType_Set_Sortable(sortable_differs, true);
+ ASSERT_FALSE(batch, FType_Equals(type, (Obj*)sortable_differs),
+ "Different value for 'sortable' spoils Equals()");
+ DECREF(sortable_differs);
+
+ FieldType *boost_differs = (FieldType*)DummyFieldType_new(NULL);
+ FType_Set_Boost(boost_differs, 2.0f);
+ ASSERT_FALSE(batch, FType_Equals(type, (Obj*)boost_differs),
+ "Different value for 'boost' spoils Equals()");
+ DECREF(boost_differs);
+
+ FieldType *binary_differs = (FieldType*)DummyFieldType_new(NULL);
+ ((DummyFieldType*)binary_differs)->binary = true;
+ ASSERT_FALSE(batch, FType_Equals(type, (Obj*)binary_differs),
+ "Different value for 'binary' spoils Equals()");
+ DECREF(binary_differs);
+
+ Similarity *sim = (Similarity*)DummySim_new(1);
+ Similarity *alt_sim = (Similarity*)DummySim_new(2);
+ FieldType *has_sim = (FieldType*)DummyFieldType_new(sim);
+ FieldType *has_alt_sim = (FieldType*)DummyFieldType_new(alt_sim);
+ ASSERT_FALSE(batch, FType_Equals(type, (Obj*)alt_sim),
+ "NULL vs non-NULL sim spoils Equals()");
+ ASSERT_FALSE(batch, FType_Equals(has_sim, (Obj*)type),
+ "non-NULL vs NULL sim spoils Equals()");
+ ASSERT_FALSE(batch, FType_Equals(has_sim, (Obj*)has_alt_sim),
+ "different sim spoils Equals()");
+ DECREF(has_alt_sim);
+ DECREF(has_sim);
+ DECREF(alt_sim);
+ DECREF(sim);
+
+ DECREF(type);
+}
+
+void
+TestFType_run_tests()
+{
+ TestBatch *batch = TestBatch_new(22);
+ TestBatch_Plan(batch);
+ test_primitive_accessors(batch);
+ test_Compare_Values(batch);
+ test_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/TestFieldType.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=953207&r1=953206&r2=953207&view=diff
==============================================================================
--- lucene/lucy/trunk/perl/lib/Lucy/Test.pm (original)
+++ lucene/lucy/trunk/perl/lib/Lucy/Test.pm Thu Jun 10 03:21:54 2010
@@ -49,6 +49,10 @@ PPCODE:
else if (strEQ(package, "TestVArray")) {
lucy_TestVArray_run_tests();
}
+ // Lucy::Plan
+ else if (strEQ(package, "TestFieldType")) {
+ lucy_TestFType_run_tests();
+ }
// Lucy::Store
else if (strEQ(package, "TestCompoundFileReader")) {
lucy_TestCFReader_run_tests();
Added: lucene/lucy/trunk/perl/t/core/229-field_type.t
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/perl/t/core/229-field_type.t?rev=953207&view=auto
==============================================================================
--- lucene/lucy/trunk/perl/t/core/229-field_type.t (added)
+++ lucene/lucy/trunk/perl/t/core/229-field_type.t Thu Jun 10 03:21:54 2010
@@ -0,0 +1,6 @@
+use strict;
+use warnings;
+
+use Lucy::Test;
+Lucy::Test::run_tests("TestFieldType");
+
Propchange: lucene/lucy/trunk/perl/t/core/229-field_type.t
------------------------------------------------------------------------------
svn:eol-style = native