use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.
the class SignatureUpdateProcessorFactoryTest method testNonStringFieldsValues.
@Test
public void testNonStringFieldsValues() throws Exception {
this.chain = "dedupe-allfields";
SolrCore core = h.getCore();
UpdateRequestProcessorChain chained = core.getUpdateProcessingChain(chain);
SignatureUpdateProcessorFactory factory = ((SignatureUpdateProcessorFactory) chained.getProcessors().get(0));
factory.setEnabled(true);
Map<String, String[]> params = new HashMap<>();
MultiMapSolrParams mmparams = new MultiMapSolrParams(params);
params.put(UpdateParams.UPDATE_CHAIN, new String[] { chain });
UpdateRequest ureq = new UpdateRequest();
{
SolrInputDocument doc = new SolrInputDocument();
doc.addField("v_t", "same");
doc.addField("weight", 1.0f);
doc.addField("ints_is", 34);
doc.addField("ints_is", 42);
ureq.add(doc);
}
{
SolrInputDocument doc = new SolrInputDocument();
doc.addField("v_t", "same");
doc.addField("weight", 2.0f);
doc.addField("ints_is", 42);
doc.addField("ints_is", 66);
ureq.add(doc);
}
{
// A and B should have same sig as eachother
// even though the particulars of how the the ints_is list are built
SolrInputDocument docA = new SolrInputDocument();
SolrInputDocument docB = new SolrInputDocument();
UnusualList<Integer> ints = new UnusualList<>(3);
for (int val : new int[] { 42, 66, 34 }) {
docA.addField("ints_is", new Integer(val));
ints.add(val);
}
docB.addField("ints_is", ints);
for (SolrInputDocument doc : new SolrInputDocument[] { docA, docB }) {
doc.addField("v_t", "same");
doc.addField("weight", 3.0f);
ureq.add(doc);
}
}
{
// now add another doc with the same values as A & B above,
// but diff ints_is collection (diff order)
SolrInputDocument doc = new SolrInputDocument();
doc.addField("v_t", "same");
doc.addField("weight", 3.0f);
for (int val : new int[] { 66, 42, 34 }) {
doc.addField("ints_is", new Integer(val));
}
ureq.add(doc);
}
ArrayList<ContentStream> streams = new ArrayList<>(2);
streams.add(new BinaryRequestWriter().getContentStream(ureq));
LocalSolrQueryRequest req = new LocalSolrQueryRequest(h.getCore(), mmparams);
try {
req.setContentStreams(streams);
UpdateRequestHandler h = new UpdateRequestHandler();
h.init(new NamedList());
h.handleRequestBody(req, new SolrQueryResponse());
} finally {
req.close();
}
addDoc(commit());
checkNumDocs(4);
}
use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.
the class SolrSchemalessExampleTest method createNewSolrClient.
@Override
public SolrClient createNewSolrClient() {
try {
// setup the server...
String url = jetty.getBaseUrl().toString() + "/collection1";
HttpSolrClient client = getHttpSolrClient(url);
client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
client.setUseMultiPartPost(random().nextBoolean());
if (random().nextBoolean()) {
client.setParser(new BinaryResponseParser());
client.setRequestWriter(new BinaryRequestWriter());
}
return client;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.
the class TestSolrJErrorHandling method testWithBinary.
@Test
public void testWithBinary() throws Exception {
HttpSolrClient client = (HttpSolrClient) getSolrClient();
client.setRequestWriter(new BinaryRequestWriter());
// delete everything!
client.deleteByQuery("*:*");
doIt(client);
}
use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.
the class BinaryUpdateRequestHandlerTest method testRequestParams.
@Test
public void testRequestParams() throws Exception {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "1");
UpdateRequest ureq = new UpdateRequest();
ureq.add(doc);
ureq.setParam(UpdateParams.COMMIT_WITHIN, "100");
ureq.setParam(UpdateParams.OVERWRITE, Boolean.toString(false));
BinaryRequestWriter brw = new BinaryRequestWriter();
BufferingRequestProcessor p = new BufferingRequestProcessor(null);
SolrQueryResponse rsp = new SolrQueryResponse();
UpdateRequestHandler handler = new UpdateRequestHandler();
handler.init(new NamedList());
SolrQueryRequest req = req();
ContentStreamLoader csl = handler.newLoader(req, p);
csl.load(req, rsp, brw.getContentStream(ureq), p);
AddUpdateCommand add = p.addCommands.get(0);
System.out.println(add.solrDoc);
assertEquals(false, add.overwrite);
assertEquals(100, add.commitWithin);
req.close();
}
use of org.apache.solr.client.solrj.impl.BinaryRequestWriter in project lucene-solr by apache.
the class StreamingSolrClients method getSolrClient.
public synchronized SolrClient getSolrClient(final SolrCmdDistributor.Req req) {
String url = getFullUrl(req.node.getUrl());
ConcurrentUpdateSolrClient client = solrClients.get(url);
if (client == null) {
// NOTE: increasing to more than 1 threadCount for the client could cause updates to be reordered
// on a greater scale since the current behavior is to only increase the number of connections/Runners when
// the queue is more than half full.
client = new ErrorReportingConcurrentUpdateSolrClient(url, httpClient, 100, runnerCount, updateExecutor, true, req);
// minimize connections created
client.setPollQueueTime(Integer.MAX_VALUE);
client.setParser(new BinaryResponseParser());
client.setRequestWriter(new BinaryRequestWriter());
Set<String> queryParams = new HashSet<>(2);
queryParams.add(DistributedUpdateProcessor.DISTRIB_FROM);
queryParams.add(DistributingUpdateProcessorFactory.DISTRIB_UPDATE_PARAM);
client.setQueryParams(queryParams);
solrClients.put(url, client);
}
return client;
}
Aggregations