Skip to content

Apache Lucene open-source search software

* Changed setKeepDuplicateFieldValues to setRemoveDuplicateFieldValues * made sure the tests deal with duplicate values on one field, but not the other

Ryan McKinley045248e2c123
diff --git a/src/java/org/apache/solr/common/SolrInputDocument.java b/src/java/org/apache/solr/common/SolrInputDocument.java
index 25a541f55e1..500d74a11da 100644
--- a/src/java/org/apache/solr/common/SolrInputDocument.java
+++ b/src/java/org/apache/solr/common/SolrInputDocument.java
@@ -29,7 +29,7 @@ import java.util.Map;
* match those specified in schema.xml
*
* By default, this will keep every field value added to the document. To only
- * keep distinct values, use setKeepDuplicateFieldValues( "fieldname", false);
+ * keep distinct values, use setRemoveDuplicateFieldValues( "fieldname", true );
*
* @author ryan
* @version $Id$
@@ -38,7 +38,7 @@ import java.util.Map;
public class SolrInputDocument extends SolrDocument
{
private Map<String,Float> _boost = null;
- private Map<String,Boolean> _keepDuplicates = null;
+ private Map<String,Boolean> _removeDuplicates = null;
/**
* Return a base collection to manage the fields for a given value. If
@@ -49,7 +49,7 @@ public class SolrInputDocument extends SolrDocument
@Override
protected Collection<Object> getEmptyCollection( String name )
{
- if( _keepDuplicates == null || Boolean.TRUE == _keepDuplicates.get( name )) {
+ if( _removeDuplicates == null || Boolean.FALSE == _removeDuplicates.get( name )) {
return new ArrayList<Object>();
}
return new LinkedHashSet<Object>(); // keep the order? -- perhaps HashSet?
@@ -65,8 +65,8 @@ public class SolrInputDocument extends SolrDocument
if( _boost != null ) {
_boost.clear();
}
- if(_keepDuplicates != null ) {
- _keepDuplicates.clear();
+ if(_removeDuplicates != null ) {
+ _removeDuplicates.clear();
}
}
@@ -125,22 +125,22 @@ public class SolrInputDocument extends SolrDocument
*
* NOTE: this must be called before adding any values to the given field.
*/
- public void setKeepDuplicateFieldValues( String name, boolean v )
+ public void setRemoveDuplicateFieldValues( String name, boolean v )
{
if( this.getFieldValues( 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( _keepDuplicates == null ) {
- if( v == true ) {
- // we only care about 'false' we don't need to make a map unless
+ 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;
}
- _keepDuplicates = new HashMap<String, Boolean>();
+ _removeDuplicates = new HashMap<String, Boolean>();
}
- _keepDuplicates.put( name, v );
+ _removeDuplicates.put( name, v );
}
}
diff --git a/src/test/org/apache/solr/common/SolrDocumentTest.java b/src/test/org/apache/solr/common/SolrDocumentTest.java
index 4105eaa6da7..1509bfb5365 100644
--- a/src/test/org/apache/solr/common/SolrDocumentTest.java
+++ b/src/test/org/apache/solr/common/SolrDocumentTest.java
@@ -132,11 +132,15 @@ public class SolrDocumentTest extends TestCase
c0.add( "ccc" );
SolrInputDocument doc = new SolrInputDocument();
- doc.setKeepDuplicateFieldValues( null, false );
- doc.addField( "v", c0 );
- assertEquals( 3, doc.getFieldValues("v").size() );
-
- assertEquals( "[aaa, bbb, ccc]", doc.getFieldValues( "v" ).toString() );
+ doc.setRemoveDuplicateFieldValues( "f1", true );
+ doc.setRemoveDuplicateFieldValues( "f2", false );
+ doc.addField( "f1", c0 );
+ doc.addField( "f2", c0 );
+ assertEquals( 3, doc.getFieldValues("f1").size() );
+ assertEquals( 5, doc.getFieldValues("f2").size() );
+
+ assertEquals( "[aaa, bbb, ccc]", doc.getFieldValues( "f1" ).toString() );
+ assertEquals( "[aaa, bbb, aaa, aaa, ccc]", doc.getFieldValues( "f2" ).toString() );
}
public void testDuplicate()
@@ -155,13 +159,13 @@ public class SolrDocumentTest extends TestCase
assertEquals( (3*5), doc.getFieldValues("f").size() );
try {
- doc.setKeepDuplicateFieldValues( "f", false );
+ doc.setRemoveDuplicateFieldValues( "f", true );
fail( "can't change distinct for an existing field" );
}
catch( Exception ex ) {}
doc.removeFields( "f" );
- doc.setKeepDuplicateFieldValues( "f", false );
+ doc.setRemoveDuplicateFieldValues( "f", true );
for( int i=0; i<5; i++ ) {
doc.addField( "f", fval0 );
doc.addField( "f", fval1 );