Skip to content

Apache Lucene open-source search software

Adding a utility function to convert SolrDocument -> SolrInputDocument

Ryan McKinley69f9e931e9d2
diff --git a/client/java/solrj/src/org/apache/solr/client/solrj/util/ClientUtils.java b/client/java/solrj/src/org/apache/solr/client/solrj/util/ClientUtils.java
index 587c7f3a22d..3259661fa06 100644
--- a/client/java/solrj/src/org/apache/solr/client/solrj/util/ClientUtils.java
+++ b/client/java/solrj/src/org/apache/solr/client/solrj/util/ClientUtils.java
@@ -34,6 +34,7 @@ import java.util.regex.Pattern;
import org.apache.commons.httpclient.util.DateParseException;
import org.apache.commons.httpclient.util.DateUtil;
+import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.SolrInputField;
import org.apache.solr.common.params.SolrParams;
@@ -68,6 +69,20 @@ public class ClientUtils
return streams;
}
+ /**
+ * @param SolrDocument to convert
+ * @return a SolrInputDocument with the same fields and values as the
+ * SolrDocument. All boosts are 1.0f
+ */
+ public static SolrInputDocument toSolrInputDocument( SolrDocument d )
+ {
+ SolrInputDocument doc = new SolrInputDocument();
+ for( String name : d.getFieldNames() ) {
+ doc.addField( name, d.getFieldValue(name), 1.0f );
+ }
+ return doc;
+ }
+
//------------------------------------------------------------------------
//------------------------------------------------------------------------