SOLR-2010: fix resource leak in spellcheck collator

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1023329 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-10-16 17:06:31 +00:00
parent 987f32849b
commit e579ca5c62
1 changed files with 9 additions and 8 deletions

View File

@ -29,6 +29,7 @@ import org.apache.solr.handler.component.QueryComponent;
import org.apache.solr.handler.component.ResponseBuilder; import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.handler.component.SearchComponent; import org.apache.solr.handler.component.SearchComponent;
import org.apache.solr.handler.component.SearchHandler; import org.apache.solr.handler.component.SearchHandler;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequestBase; import org.apache.solr.request.SolrQueryRequestBase;
import org.apache.solr.response.SolrQueryResponse; import org.apache.solr.response.SolrQueryResponse;
import org.mortbay.log.Log; import org.mortbay.log.Log;
@ -58,7 +59,7 @@ public class SpellCheckCollator {
verifyCandidateWithQuery = false; verifyCandidateWithQuery = false;
} }
if (queryComponent == null && verifyCandidateWithQuery) { 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; maxTries = 1;
verifyCandidateWithQuery = false; verifyCandidateWithQuery = false;
} }
@ -82,14 +83,12 @@ public class SpellCheckCollator {
checkResponse.components = Arrays.asList(new SearchComponent[] { queryComponent }); checkResponse.components = Arrays.asList(new SearchComponent[] { queryComponent });
ModifiableSolrParams params = new ModifiableSolrParams(ultimateResponse.req.getParams()); ModifiableSolrParams params = new ModifiableSolrParams(ultimateResponse.req.getParams());
params.remove(CommonParams.Q); params.set(CommonParams.Q, collationQueryStr);
params.add(CommonParams.Q, collationQueryStr);
params.remove(CommonParams.START); params.remove(CommonParams.START);
params.remove(CommonParams.ROWS); params.set(CommonParams.FL, "id");
params.add(CommonParams.FL, "id"); params.set(CommonParams.ROWS, "0");
params.add(CommonParams.ROWS, "0"); // creating a request here... make sure to close it!
//Would rather have found a concrete class to use... checkResponse.req = new LocalSolrQueryRequest(ultimateResponse.req.getCore(), params);
checkResponse.req = new SolrQueryRequestBase(ultimateResponse.req.getCore(), params) { };
checkResponse.rsp = new SolrQueryResponse(); checkResponse.rsp = new SolrQueryResponse();
try { try {
@ -98,6 +97,8 @@ public class SpellCheckCollator {
hits = (Integer) checkResponse.rsp.getToLog().get("hits"); hits = (Integer) checkResponse.rsp.getToLog().get("hits");
} catch (Exception e) { } catch (Exception e) {
Log.warn("Exception trying to re-query to check if a spell check possibility would return any hits.", 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) { if (hits > 0 || !verifyCandidateWithQuery) {