Apache Lucene open-source search software
Removing some weirdness in the SolrInputDocument interface that is not really needed for SOLR-139.
Ryan McKinleyfdc4ed58b48a
diff --git a/src/java/org/apache/solr/common/SolrInputDocument.java b/src/java/org/apache/solr/common/SolrInputDocument.javaindex 9b4f180033c..9fd693e6725 100644--- a/src/java/org/apache/solr/common/SolrInputDocument.java+++ b/src/java/org/apache/solr/common/SolrInputDocument.java@@ -19,7 +19,6 @@ package org.apache.solr.common;import java.util.HashMap;import java.util.Iterator;-import java.util.LinkedHashSet;import java.util.Map;import java.util.Collection;@@ -27,9 +26,6 @@ import java.util.Collection;* Represent the field and boost information needed to construct and index* a Lucene Document. Like the SolrDocument, the field values should* match those specified in schema.xml- *- * By default, this will keep every field value added to the document. To only- * keep distinct values, use setRemoveDuplicateFieldValues( "fieldname", true );** @version $Id$* @since solr 1.3@@ -37,7 +33,6 @@ import java.util.Collection;public class SolrInputDocument implements Iterable<SolrInputField>{private final Map<String,SolrInputField> _fields;- private Map<String,Boolean> _removeDuplicates = null;private float _documentBoost = 1.0f;public SolrInputDocument()@@ -53,27 +48,12 @@ public class SolrInputDocument implements Iterable<SolrInputField>if( _fields != null ) {_fields.clear();}- if(_removeDuplicates != null ) {- _removeDuplicates.clear();- }}///////////////////////////////////////////////////////////////////// Add / Set fields///////////////////////////////////////////////////////////////////- private boolean isDistinct( String name )- {- if( _removeDuplicates != null ) {- Boolean v = _removeDuplicates.get( name );- if( v == null ) {- v = _removeDuplicates.get( null );- }- return (v == Boolean.TRUE);- }- return false;- }-/*** Add a field with implied null value for boost.*@@ -137,13 +117,7 @@ public class SolrInputDocument implements Iterable<SolrInputField>{SolrInputField field = new SolrInputField( name );_fields.put( name, field );- if( isDistinct( name ) ) {- field.value = new LinkedHashSet<Object>();- this.addField(name, value, boost);- }- else {- field.setValue( value, boost );- }+ field.setValue( value, boost );}/**@@ -170,34 +144,6 @@ public class SolrInputDocument implements Iterable<SolrInputField>public SolrInputField removeField(String name) {return _fields.remove( name );}-- /**- * Should the Document be able to contain duplicate values for the same field?- *- * By default, all field values are maintained. If you only want to distinct values- * set setKeepDuplicateFieldValues( "fieldname", false );- *- * To change the default behavior, use <code>null</code> as the fieldname.- *- * NOTE: this must be called before adding any values to the given field.- */- public void setRemoveDuplicateFieldValues( String name, boolean v )- {- if( _fields.get( name ) != null ) {- // If it was not distinct and changed to distinct, we could, but this seems like a better rule- throw new RuntimeException( "You can't change a fields distinctness after it is initialized." );- }-- if( _removeDuplicates == null ) {- if( v == false ) {- // we only care about 'true' we don't need to make a map unless- // something does not want multiple values- return;- }- _removeDuplicates = new HashMap<String, Boolean>();- }- _removeDuplicates.put( name, v );- }///////////////////////////////////////////////////////////////////// Get the field valuesdiff --git a/src/test/org/apache/solr/common/SolrDocumentTest.java b/src/test/org/apache/solr/common/SolrDocumentTest.javaindex 052c5ab5b95..e380c11139f 100644--- a/src/test/org/apache/solr/common/SolrDocumentTest.java+++ b/src/test/org/apache/solr/common/SolrDocumentTest.java@@ -113,28 +113,7 @@ public class SolrDocumentTest extends TestCasedoc.addField( "v", c0 );assertEquals( arr.length, doc.getFieldValues("v").size() );}-- public void testOrderedDistinctFields()- {- List<String> c0 = new ArrayList<String>();- c0.add( "aaa" );- c0.add( "bbb" );- c0.add( "aaa" );- c0.add( "aaa" );- c0.add( "ccc" );-- SolrInputDocument doc = new SolrInputDocument();- doc.setRemoveDuplicateFieldValues( "f1", true );- doc.setRemoveDuplicateFieldValues( "f2", false );- doc.addField( "f1", c0, 1.0f );- doc.addField( "f2", c0, 1.0f );- assertEquals( 3, doc.getField("f1").getValueCount() );- assertEquals( 5, doc.getField("f2").getValueCount() );-- assertEquals( "[aaa, bbb, ccc]", doc.getField( "f1" ).getValues().toString() );- assertEquals( "[aaa, bbb, aaa, aaa, ccc]", doc.getField( "f2" ).getValues().toString() );- }-+public void testDuplicate(){Float fval0 = new Float( 10.01f );@@ -149,21 +128,6 @@ public class SolrDocumentTest extends TestCasedoc.addField( "f", fval2, 1.0f );}assertEquals( (3*5), doc.getField("f").getValueCount() );-- try {- doc.setRemoveDuplicateFieldValues( "f", true );- fail( "can't change distinct for an existing field" );- }- catch( Exception ex ) {}-- doc.removeField( "f" );- doc.setRemoveDuplicateFieldValues( "f", true );- for( int i=0; i<5; i++ ) {- doc.addField( "f", fval0, 1.0f );- doc.addField( "f", fval1, 1.0f );- doc.addField( "f", fval2, 1.0f );- }- assertEquals( (3), doc.getField("f").getValueCount() );}}