Author: ryan
Date: Sat Aug 4 22:26:53 2007
New Revision: 562832
URL: http://svn.apache.org/viewvc?view=rev&rev=562832
Log:
Removing some weirdness in the SolrInputDocument interface that is not really
needed for SOLR-139.
Modified:
lucene/solr/trunk/src/java/org/apache/solr/common/SolrInputDocument.java
lucene/solr/trunk/src/test/org/apache/solr/common/SolrDocumentTest.java
Modified:
lucene/solr/trunk/src/java/org/apache/solr/common/SolrInputDocument.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/common/SolrInputDocument.java?view=diff&rev=562832&r1=562831&r2=562832
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/common/SolrInputDocument.java
(original)
+++ lucene/solr/trunk/src/java/org/apache/solr/common/SolrInputDocument.java
Sat Aug 4 22:26:53 2007
@@ -19,7 +19,6 @@
import java.util.HashMap;
import java.util.Iterator;
-import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Collection;
@@ -27,9 +26,6 @@
* 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 @@
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 @@
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 @@
{
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 );
}
/**
@@ -169,34 +143,6 @@
*/
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 );
}
///////////////////////////////////////////////////////////////////
Modified:
lucene/solr/trunk/src/test/org/apache/solr/common/SolrDocumentTest.java
URL:
http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/common/SolrDocumentTest.java?view=diff&rev=562832&r1=562831&r2=562832
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/common/SolrDocumentTest.java
(original)
+++ lucene/solr/trunk/src/test/org/apache/solr/common/SolrDocumentTest.java Sat
Aug 4 22:26:53 2007
@@ -113,28 +113,7 @@
doc.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 @@
doc.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() );
}
}