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

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@536278 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris M. Hostetter 2007-05-08 18:03:32 +00:00
parent d6f65b926a
commit 23e5fb0e47
5 changed files with 41 additions and 2 deletions

View File

@ -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).

View File

@ -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.

View File

@ -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,

View File

@ -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");

View File

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