Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-217 - no error if fields are unindexed and unstored, instead let them be quietly ignored

Chris M. Hostetter23e5fb0e472a
diff --git a/CHANGES.txt b/CHANGES.txt
index d92ad600957..0183f6686f3 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -167,7 +167,13 @@ New Features
descriptive error message. By default, the uniqueKey field is
a required field. This can be disabled by setting required=false
in schema.xml. (Greg Ludington via ryan)
-
+
+28. SOLR-217: Fields configured in the schema to be neither indexed or
+ stored will now be quietly ignored by Solr when Documents are added.
+ The example schema has a comment explaining how this can be used to
+ ignore any "unknown" fields.
+ (Will Johnson via hossman)
+
Changes in runtime behavior
1. Highlighting using DisMax will only pick up terms from the main
user query, not boost or filter queries (klaas).
diff --git a/example/solr/conf/schema.xml b/example/solr/conf/schema.xml
index 4195bd896c4..c31ccf21455 100755
--- a/example/solr/conf/schema.xml
+++ b/example/solr/conf/schema.xml
@@ -215,6 +215,11 @@
</analyzer>
</fieldType>
+ <!-- since fields of this type are by default not stored or indexed, any data added to
+ them will be ignored outright
+ -->
+ <fieldtype name="ignored" stored="false" indexed="false" class="solr.StrField" />
+
</types>
@@ -289,6 +294,13 @@
<dynamicField name="*_f" type="sfloat" indexed="true" stored="true"/>
<dynamicField name="*_d" type="sdouble" indexed="true" stored="true"/>
<dynamicField name="*_dt" type="date" indexed="true" stored="true"/>
+
+ <!-- uncomment the following to ignore any fields that don't already match an existing
+ field name or dynamic field, rather than reporting them as an error.
+ alternately, change the type="ignored" to some other type e.g. "text" if you want
+ unknown fields indexed and/or stored by default -->
+ <!--dynamicField name="*" type="ignored" /-->
+
</fields>
<!-- Field to use to determine and enforce document uniqueness.
diff --git a/src/java/org/apache/solr/schema/FieldType.java b/src/java/org/apache/solr/schema/FieldType.java
index 9608103d90a..aa25e62cb71 100644
--- a/src/java/org/apache/solr/schema/FieldType.java
+++ b/src/java/org/apache/solr/schema/FieldType.java
@@ -173,6 +173,11 @@ public abstract class FieldType extends FieldProperties {
throw new SolrException(500, "Error while creating field '" + field + "' from value '" + externalVal + "'", e, false);
}
if (val==null) return null;
+ if (!field.indexed() && !field.stored()) {
+ log.finest("Ignoring unindexed/unstored field: " + field);
+ return null;
+ }
+
Field f = new Field(field.getName(),
val,
diff --git a/src/test/org/apache/solr/BasicFunctionalityTest.java b/src/test/org/apache/solr/BasicFunctionalityTest.java
index 5811951d209..7fe44f20b56 100644
--- a/src/test/org/apache/solr/BasicFunctionalityTest.java
+++ b/src/test/org/apache/solr/BasicFunctionalityTest.java
@@ -55,6 +55,21 @@ public class BasicFunctionalityTest extends AbstractSolrTestCase {
super.tearDown();
}
+
+ public void testIgnoredFields() throws Exception {
+ lrf.args.put("version","2.0");
+ assertU("adding doc with ignored field",
+ adoc("id", "42", "foo_ignored", "blah blah"));
+ assertU("commit",
+ commit());
+
+ // :TODO: the behavior of querying on an unindexed field should be better specified in the future.
+ assertQ("query with ignored field",
+ req("bar_ignored:yo id:42")
+ ,"//*[@numFound='1']"
+ ,"//int[@name='id'][.='42']"
+ );
+ }
public void testSomeStuff() throws Exception {
lrf.args.put("version","2.0");
diff --git a/src/test/test-files/solr/conf/schema.xml b/src/test/test-files/solr/conf/schema.xml
index f71cd46f972..5231118b577 100644
--- a/src/test/test-files/solr/conf/schema.xml
+++ b/src/test/test-files/solr/conf/schema.xml
@@ -406,7 +406,8 @@
<dynamicField name="*aa" type="string" indexed="true" stored="true"/>
<dynamicField name="*aaa" type="integer" indexed="false" stored="true"/>
-
+ <!-- ignored becuase not stored or indexed -->
+ <dynamicField name="*_ignored" type="text" indexed="false" stored="false"/>
</fields>