Skip to content

Apache Lucene open-source search software

SOLR-2010: fix resource leak in spellcheck collator

Yonik Seeleye579ca5c6225
diff --git a/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java b/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java
index 21bc4eb5f67..f15b5dc8e35 100644
--- a/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java
+++ b/solr/src/java/org/apache/solr/spelling/SpellCheckCollator.java
@@ -29,6 +29,7 @@ import org.apache.solr.handler.component.QueryComponent;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.handler.component.SearchHandler;
+import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequestBase;
import org.apache.solr.response.SolrQueryResponse;
import org.mortbay.log.Log;
@@ -58,7 +59,7 @@ public class SpellCheckCollator {
verifyCandidateWithQuery = false;
}
if (queryComponent == null && verifyCandidateWithQuery) {
- LOG.warn("Could not find an instance of QueryComponent. Disabling collation verification against the index.");
+ LOG.info("Could not find an instance of QueryComponent. Disabling collation verification against the index.");
maxTries = 1;
verifyCandidateWithQuery = false;
}
@@ -82,14 +83,12 @@ public class SpellCheckCollator {
checkResponse.components = Arrays.asList(new SearchComponent[] { queryComponent });
ModifiableSolrParams params = new ModifiableSolrParams(ultimateResponse.req.getParams());
- params.remove(CommonParams.Q);
- params.add(CommonParams.Q, collationQueryStr);
+ params.set(CommonParams.Q, collationQueryStr);
params.remove(CommonParams.START);
- params.remove(CommonParams.ROWS);
- params.add(CommonParams.FL, "id");
- params.add(CommonParams.ROWS, "0");
- //Would rather have found a concrete class to use...
- checkResponse.req = new SolrQueryRequestBase(ultimateResponse.req.getCore(), params) { };
+ params.set(CommonParams.FL, "id");
+ params.set(CommonParams.ROWS, "0");
+ // creating a request here... make sure to close it!
+ checkResponse.req = new LocalSolrQueryRequest(ultimateResponse.req.getCore(), params);
checkResponse.rsp = new SolrQueryResponse();
try {
@@ -98,6 +97,8 @@ public class SpellCheckCollator {
hits = (Integer) checkResponse.rsp.getToLog().get("hits");
} catch (Exception e) {
Log.warn("Exception trying to re-query to check if a spell check possibility would return any hits.", e);
+ } finally {
+ checkResponse.req.close();
}
}
if (hits > 0 || !verifyCandidateWithQuery) {