From 5a103adc6019ba6d9f8d9a834d850e33a0326db9 Mon Sep 17 00:00:00 2001 From: Noble Paul Date: Wed, 25 Nov 2009 10:34:36 +0000 Subject: [PATCH] SOLR-1600 A single value in amultivalued field means the value will not be a collection for javabin git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@884021 13f79535-47bb-0310-9956-ffa450edef68 --- .../solr/request/BinaryResponseWriter.java | 17 +- .../request/TestBinaryResponseWriter.java | 2 +- .../apache/solr/schema/IndexSchemaTest.java | 7 + .../solr/conf/schema-binaryfield.xml | 2 +- .../solr/conf/schema-replication1.xml | 2 +- .../solr/conf/schema-replication2.xml | 2 +- src/test/test-files/solr/conf/schema1_2.xml | 549 ++++++++++++++++++ 7 files changed, 571 insertions(+), 10 deletions(-) create mode 100644 src/test/test-files/solr/conf/schema1_2.xml diff --git a/src/java/org/apache/solr/request/BinaryResponseWriter.java b/src/java/org/apache/solr/request/BinaryResponseWriter.java index bd85bc64fd7..f4ec7cceec3 100755 --- a/src/java/org/apache/solr/request/BinaryResponseWriter.java +++ b/src/java/org/apache/solr/request/BinaryResponseWriter.java @@ -30,10 +30,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.*; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; public class BinaryResponseWriter implements BinaryQueryResponseWriter { @@ -137,7 +134,9 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter { for (Fieldable f : (List) doc.getFields()) { String fieldName = f.name(); if (returnFields != null && !returnFields.contains(fieldName)) continue; - FieldType ft = schema.getFieldTypeNoEx(fieldName); + SchemaField sf = schema.getFieldOrNull(fieldName); + FieldType ft = null; + if(sf != null) ft =sf.getType(); Object val; if (ft == null) { // handle fields not in the schema if (f.isBinary()) val = f.binaryValue(); @@ -157,7 +156,13 @@ public class BinaryResponseWriter implements BinaryQueryResponseWriter { continue; } } - solrDoc.addField(fieldName, val); + if(sf != null && sf.multiValued() && !solrDoc.containsKey(fieldName)){ + ArrayList l = new ArrayList(); + l.add(val); + solrDoc.addField(fieldName, l); + } else { + solrDoc.addField(fieldName, val); + } } return solrDoc; } diff --git a/src/test/org/apache/solr/request/TestBinaryResponseWriter.java b/src/test/org/apache/solr/request/TestBinaryResponseWriter.java index 7b0542cffdf..204e7f9e16f 100644 --- a/src/test/org/apache/solr/request/TestBinaryResponseWriter.java +++ b/src/test/org/apache/solr/request/TestBinaryResponseWriter.java @@ -36,7 +36,7 @@ import java.util.UUID; public class TestBinaryResponseWriter extends AbstractSolrTestCase { public String getSchemaFile() { - return "schema.xml"; + return "schema1_2.xml"; } public String getSolrConfigFile() { diff --git a/src/test/org/apache/solr/schema/IndexSchemaTest.java b/src/test/org/apache/solr/schema/IndexSchemaTest.java index 8dd065fcba1..52daaa75f7c 100644 --- a/src/test/org/apache/solr/schema/IndexSchemaTest.java +++ b/src/test/org/apache/solr/schema/IndexSchemaTest.java @@ -137,4 +137,11 @@ public class IndexSchemaTest extends AbstractSolrTestCase { assertTrue( schema.isDynamicField( "aaa_i" ) ); assertFalse( schema.isDynamicField( "no_such_field" ) ); } + + public void testProperties() throws Exception{ + SolrCore core = h.getCore(); + IndexSchema schema = core.getSchema(); + assertFalse(schema.getField("id").multiValued()); + + } } diff --git a/src/test/test-files/solr/conf/schema-binaryfield.xml b/src/test/test-files/solr/conf/schema-binaryfield.xml index a81bda71b57..bf0e3e91268 100644 --- a/src/test/test-files/solr/conf/schema-binaryfield.xml +++ b/src/test/test-files/solr/conf/schema-binaryfield.xml @@ -28,7 +28,7 @@ $Name: $ --> - + - + diff --git a/src/test/test-files/solr/conf/schema-replication2.xml b/src/test/test-files/solr/conf/schema-replication2.xml index 548fb60174a..65ad6f3ac1b 100644 --- a/src/test/test-files/solr/conf/schema-replication2.xml +++ b/src/test/test-files/solr/conf/schema-replication2.xml @@ -28,7 +28,7 @@ $Name$ --> - + diff --git a/src/test/test-files/solr/conf/schema1_2.xml b/src/test/test-files/solr/conf/schema1_2.xml new file mode 100644 index 00000000000..bea82904d7b --- /dev/null +++ b/src/test/test-files/solr/conf/schema1_2.xml @@ -0,0 +1,549 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text + id + + + + + + + + + + + + + + + + is there an echo? + + +