mirror of https://github.com/apache/lucene.git
fixing multiple document adding error.
setting: addCmd.indexedId = null; before each add git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@553574 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
455194dff0
commit
3fd423d27a
|
@ -21,10 +21,12 @@ package org.apache.solr.client.solrj;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.apache.solr.client.solrj.request.UpdateRequest;
|
||||||
import org.apache.solr.client.solrj.response.QueryResponse;
|
import org.apache.solr.client.solrj.response.QueryResponse;
|
||||||
import org.apache.solr.client.solrj.response.UpdateResponse;
|
import org.apache.solr.client.solrj.response.UpdateResponse;
|
||||||
import org.apache.solr.client.solrj.util.ClientUtils;
|
import org.apache.solr.client.solrj.util.ClientUtils;
|
||||||
|
@ -153,6 +155,61 @@ abstract public class SolrExampleTestBase extends AbstractSolrTestCase
|
||||||
Assert.assertFalse(query.getFilterQueries() == query2.getFilterQueries());
|
Assert.assertFalse(query.getFilterQueries() == query2.getFilterQueries());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* query the example
|
||||||
|
*/
|
||||||
|
public void testAddRetrieve() throws Exception
|
||||||
|
{
|
||||||
|
String path = "/update";
|
||||||
|
|
||||||
|
SolrServer server = getSolrServer();
|
||||||
|
|
||||||
|
// Empty the database...
|
||||||
|
server.deleteByQuery( "*:*" );// delete everything!
|
||||||
|
|
||||||
|
// Now add something...
|
||||||
|
SolrInputDocument doc1 = new SolrInputDocument();
|
||||||
|
doc1.addField( "id", "id1", 1.0f );
|
||||||
|
doc1.addField( "name", "doc1", 1.0f );
|
||||||
|
doc1.addField( "price", 10 );
|
||||||
|
|
||||||
|
SolrInputDocument doc2 = new SolrInputDocument();
|
||||||
|
doc2.addField( "id", "id2", 1.0f );
|
||||||
|
doc2.addField( "name", "doc2", 1.0f );
|
||||||
|
doc2.addField( "price", 20 );
|
||||||
|
|
||||||
|
Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
|
||||||
|
docs.add( doc1 );
|
||||||
|
docs.add( doc2 );
|
||||||
|
|
||||||
|
// Add the documents
|
||||||
|
UpdateRequest up = new UpdateRequest();
|
||||||
|
up.setPath( path );
|
||||||
|
up.add( docs );
|
||||||
|
server.request( up );
|
||||||
|
server.commit();
|
||||||
|
|
||||||
|
SolrQuery query = new SolrQuery();
|
||||||
|
query.setQuery( "*:*" );
|
||||||
|
query.addSortField( "price", SolrQuery.ORDER.asc );
|
||||||
|
QueryResponse rsp = server.query( query );
|
||||||
|
|
||||||
|
Assert.assertEquals( path, 2, rsp.getResults().getNumFound() );
|
||||||
|
System.out.println( rsp.getResults() );
|
||||||
|
|
||||||
|
// Now do it again
|
||||||
|
up = new UpdateRequest();
|
||||||
|
up.setPath( path );
|
||||||
|
up.add( docs );
|
||||||
|
server.request( up );
|
||||||
|
server.commit();
|
||||||
|
|
||||||
|
rsp = server.query( query );
|
||||||
|
Assert.assertEquals( path, 2, rsp.getResults().getNumFound() );
|
||||||
|
System.out.println( rsp.getResults() );
|
||||||
|
}
|
||||||
|
|
||||||
protected void assertNumFound( String query, int num ) throws SolrServerException, IOException
|
protected void assertNumFound( String query, int num ) throws SolrServerException, IOException
|
||||||
{
|
{
|
||||||
QueryResponse rsp = getSolrServer().query( new SolrQuery( query ) );
|
QueryResponse rsp = getSolrServer().query( new SolrQuery( query ) );
|
||||||
|
|
|
@ -197,6 +197,7 @@ public class XmlUpdateRequestHandler extends RequestHandlerBase
|
||||||
}
|
}
|
||||||
else if ("doc".equals(currTag)) {
|
else if ("doc".equals(currTag)) {
|
||||||
log.finest("adding doc...");
|
log.finest("adding doc...");
|
||||||
|
addCmd.indexedId = null;
|
||||||
SolrInputDocument doc = readDoc( parser );
|
SolrInputDocument doc = readDoc( parser );
|
||||||
processor.processAdd( addCmd, doc );
|
processor.processAdd( addCmd, doc );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue