exclude rejected results from result count

(by using the resultcontainer.size instead of input docList.size)
skip waiting for write-search-result-to-local-index
  (by removing the Thread.join - which will bring a small performance increase)
pull/60/head
reger 9 years ago
parent a476d06aec
commit 41c36ffd75

@ -1147,25 +1147,25 @@ public final class Protocol {
return 0; return 0;
} }
List<URIMetadataNode> container = new ArrayList<URIMetadataNode>(); List<URIMetadataNode> resultContainer = new ArrayList<URIMetadataNode>();
Network.log.info("SEARCH (solr), returned " + docList[0].size() + " out of " + docList[0].getNumFound() + " documents and " + facets.size() + " facets " + facets.keySet().toString() + " from " + (target == null ? "shard" : ("peer " + target.hash + ":" + target.getName()))); Network.log.info("SEARCH (solr), returned " + docList[0].size() + " out of " + docList[0].getNumFound() + " documents and " + facets.size() + " facets " + facets.keySet().toString() + " from " + (target == null ? "shard" : ("peer " + target.hash + ":" + target.getName())));
int term = count; int term = count;
Collection<SolrInputDocument> docs; Collection<SolrInputDocument> docs;
if (event.addResultsToLocalIndex) { // only needed to store remote results if (event.addResultsToLocalIndex) { // only needed to store remote results
docs = new ArrayList<SolrInputDocument>(docList[0].size()); docs = new ArrayList<SolrInputDocument>(docList[0].size());
} else docs = null; } else docs = null;
for (final SolrDocument doc: docList[0]) { for (final SolrDocument tmpdoc: docList[0]) {
//System.out.println("***DEBUG*** " + ((String) doc.getFieldValue("sku"))); //System.out.println("***DEBUG*** " + ((String) doc.getFieldValue("sku")));
if ( term-- <= 0 ) { if ( term-- <= 0 ) {
break; // do not process more that requested (in case that evil peers fill us up with rubbish) break; // do not process more that requested (in case that evil peers fill us up with rubbish)
} }
// get one single search result // get one single search result
if ( doc == null ) { if ( tmpdoc == null ) {
continue; continue;
} }
URIMetadataNode urlEntry; URIMetadataNode urlEntry;
try { try {
urlEntry = new URIMetadataNode(doc); urlEntry = new URIMetadataNode(tmpdoc);
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
continue; continue;
} }
@ -1199,8 +1199,8 @@ public final class Protocol {
// put the remote documents to the local index. We must convert the solr document to a solr input document: // put the remote documents to the local index. We must convert the solr document to a solr input document:
if (event.addResultsToLocalIndex) { if (event.addResultsToLocalIndex) {
/* Check document size, only if a limit is set on remote documents size allowed to be stored to local index */ /* Check document size, only if a limit is set on remote documents size allowed to be stored to local index */
if(checkDocumentSize(doc, event.getRemoteDocStoredMaxSize() * 1024)) { if (checkDocumentSize(tmpdoc, event.getRemoteDocStoredMaxSize() * 1024)) {
final SolrInputDocument sid = event.query.getSegment().fulltext().getDefaultConfiguration().toSolrInputDocument(doc); final SolrInputDocument sid = event.query.getSegment().fulltext().getDefaultConfiguration().toSolrInputDocument(tmpdoc);
// the input document stays untouched because it contains top-level cloned objects // the input document stays untouched because it contains top-level cloned objects
docs.add(sid); docs.add(sid);
@ -1214,7 +1214,7 @@ public final class Protocol {
// after this conversion we can remove the largest and not used field text_t and synonyms_sxt from the document // after this conversion we can remove the largest and not used field text_t and synonyms_sxt from the document
// because that goes into a search cache and would take a lot of memory in the search cache // because that goes into a search cache and would take a lot of memory in the search cache
//doc.removeFields(CollectionSchema.text_t.getSolrFieldName()); //doc.removeFields(CollectionSchema.text_t.getSolrFieldName());
doc.removeFields(CollectionSchema.synonyms_sxt.getSolrFieldName()); tmpdoc.removeFields(CollectionSchema.synonyms_sxt.getSolrFieldName());
ResultURLs.stack( ResultURLs.stack(
ASCII.String(urlEntry.url().hash()), ASCII.String(urlEntry.url().hash()),
@ -1224,18 +1224,17 @@ public final class Protocol {
EventOrigin.QUERIES); EventOrigin.QUERIES);
} }
// add the url entry to the word indexes // add the url entry to the checked results
container.add(urlEntry); resultContainer.add(urlEntry);
} }
final int dls = docList[0].size();
final int numFound = (int) docList[0].getNumFound(); final int numFound = (int) docList[0].getNumFound();
docList[0].clear(); docList[0].clear();
docList[0] = null; docList[0] = null;
if (localsearch) { if (localsearch) {
event.addNodes(container, facets, snippets, true, "localpeer", numFound); event.addNodes(resultContainer, facets, snippets, true, "localpeer", numFound);
event.addFinalize(); event.addFinalize();
event.addExpectedRemoteReferences(-count); event.addExpectedRemoteReferences(-count);
Network.log.info("local search (solr): localpeer sent " + container.size() + "/" + numFound + " references"); Network.log.info("local search (solr): localpeer sent " + resultContainer.size() + "/" + numFound + " references");
} else { } else {
if (event.addResultsToLocalIndex) { if (event.addResultsToLocalIndex) {
/* /*
@ -1245,26 +1244,15 @@ public final class Protocol {
throw new InterruptedException("solrQuery interrupted"); throw new InterruptedException("solrQuery interrupted");
} }
WriteToLocalIndexThread writeToLocalIndexThread = new WriteToLocalIndexThread(event.query.getSegment(), WriteToLocalIndexThread writeToLocalIndexThread = new WriteToLocalIndexThread(event.query.getSegment(),
docs); docs); // will clear docs on return
writeToLocalIndexThread.start(); writeToLocalIndexThread.start();
try {
writeToLocalIndexThread.join();
} catch (InterruptedException e) {
/*
* Current thread interruption might happen while waiting
* for writeToLocalIndexThread.
*/
writeToLocalIndexThread.stopWriting();
throw new InterruptedException("solrQuery interrupted");
}
docs.clear();
} }
event.addNodes(container, facets, snippets, false, target.getName() + "/" + target.hash, numFound); event.addNodes(resultContainer, facets, snippets, false, target.getName() + "/" + target.hash, numFound);
event.addFinalize(); event.addFinalize();
event.addExpectedRemoteReferences(-count); event.addExpectedRemoteReferences(-count);
Network.log.info("remote search (solr): peer " + target.getName() + " sent " + (container.size() == 0 ? 0 : container.size()) + "/" + numFound + " references"); Network.log.info("remote search (solr): peer " + target.getName() + " sent " + (resultContainer.size()) + "/" + numFound + " references");
} }
return dls; return resultContainer.size();
} }
/** /**
@ -1285,6 +1273,7 @@ public final class Protocol {
/** /**
* Parameters must be not null. * Parameters must be not null.
* After writing the collection is cleared
* @param segment solr segment to write * @param segment solr segment to write
* @param docs solr documents collection to put to segment * @param docs solr documents collection to put to segment
*/ */
@ -1304,11 +1293,13 @@ public final class Protocol {
public void run() { public void run() {
for (SolrInputDocument doc : docs) { for (SolrInputDocument doc : docs) {
if (stop.get()) { if (stop.get()) {
docs.clear();
Network.log.info("Writing documents collection to Solr segment was stopped."); Network.log.info("Writing documents collection to Solr segment was stopped.");
return; return;
} }
segment.putDocument(doc); segment.putDocument(doc);
} }
docs.clear();
} }
} }

Loading…
Cancel
Save