Apache Lucene open-source search software
close up searchers in spellchecker tests
Robert Muira61e395774eb
diff --git a/solr/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java b/solr/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.javaindex 950a12fcd61..41b64532a8b 100644--- a/solr/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java+++ b/solr/src/test/org/apache/solr/spelling/DirectSolrSpellCheckerTest.java@@ -21,10 +21,11 @@ import java.util.Collection;import java.util.Map;import org.apache.lucene.analysis.Token;-import org.apache.lucene.index.IndexReader;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.util.NamedList;import org.apache.solr.core.SolrCore;+import org.apache.solr.search.SolrIndexSearcher;+import org.apache.solr.util.RefCounted;import org.junit.BeforeClass;import org.junit.Test;@@ -59,9 +60,9 @@ public class DirectSolrSpellCheckerTest extends SolrTestCaseJ4 {SolrCore core = h.getCore();checker.init(spellchecker, core);- IndexReader reader = core.getSearcher().get().getReader();+ RefCounted<SolrIndexSearcher> searcher = core.getSearcher();Collection<Token> tokens = queryConverter.convert("fob");- SpellingOptions spellOpts = new SpellingOptions(tokens, reader);+ SpellingOptions spellOpts = new SpellingOptions(tokens, searcher.get().getReader());SpellingResult result = checker.getSuggestions(spellOpts);assertTrue("result is null and it shouldn't be", result != null);Map<String, Integer> suggestions = result.get(tokens.iterator().next());@@ -74,5 +75,6 @@ public class DirectSolrSpellCheckerTest extends SolrTestCaseJ4 {assertTrue("result is null and it shouldn't be", result != null);suggestions = result.get(tokens.iterator().next());assertTrue("suggestions is not null and it should be", suggestions == null);+ searcher.decref();}}diff --git a/solr/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java b/solr/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.javaindex 4b30691b0ef..c1580a16c53 100644--- a/solr/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java+++ b/solr/src/test/org/apache/solr/spelling/FileBasedSpellCheckerTest.java@@ -20,7 +20,8 @@ package org.apache.solr.spelling;import org.apache.solr.SolrTestCaseJ4;import org.apache.solr.common.util.NamedList;import org.apache.solr.core.SolrCore;-import org.apache.lucene.index.IndexReader;+import org.apache.solr.search.SolrIndexSearcher;+import org.apache.solr.util.RefCounted;import org.apache.lucene.analysis.Token;import org.junit.AfterClass;import org.junit.BeforeClass;@@ -78,9 +79,9 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {assertTrue(dictName + " is not equal to " + "external", dictName.equals("external") == true);checker.build(core, null);- IndexReader reader = core.getSearcher().get().getReader();+ RefCounted<SolrIndexSearcher> searcher = core.getSearcher();Collection<Token> tokens = queryConverter.convert("fob");- SpellingOptions spellOpts = new SpellingOptions(tokens, reader);+ SpellingOptions spellOpts = new SpellingOptions(tokens, searcher.get().getReader());SpellingResult result = checker.getSuggestions(spellOpts);assertTrue("result is null and it shouldn't be", result != null);Map<String, Integer> suggestions = result.get(tokens.iterator().next());@@ -93,7 +94,7 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {assertTrue("result is null and it shouldn't be", result != null);suggestions = result.get(tokens.iterator().next());assertTrue("suggestions is not null and it should be", suggestions == null);-+ searcher.decref();}@@ -117,10 +118,10 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {assertTrue(dictName + " is not equal to " + "external", dictName.equals("external") == true);checker.build(core, null);- IndexReader reader = core.getSearcher().get().getReader();+ RefCounted<SolrIndexSearcher> searcher = core.getSearcher();Collection<Token> tokens = queryConverter.convert("Solar");- SpellingOptions spellOpts = new SpellingOptions(tokens, reader);+ SpellingOptions spellOpts = new SpellingOptions(tokens, searcher.get().getReader());SpellingResult result = checker.getSuggestions(spellOpts);assertTrue("result is null and it shouldn't be", result != null);//should be lowercased, b/c we are using a lowercasing analyzer@@ -136,6 +137,7 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {assertTrue("result is null and it shouldn't be", result != null);suggestions = result.get(tokens.iterator().next());assertTrue("suggestions is not null and it should be", suggestions == null);+ searcher.decref();}/**@@ -161,9 +163,9 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {assertTrue(dictName + " is not equal to " + "external", dictName.equals("external") == true);checker.build(core, null);- IndexReader reader = core.getSearcher().get().getReader();+ RefCounted<SolrIndexSearcher> searcher = core.getSearcher();Collection<Token> tokens = queryConverter.convert("solar");- SpellingOptions spellOpts = new SpellingOptions(tokens, reader);+ SpellingOptions spellOpts = new SpellingOptions(tokens, searcher.get().getReader());SpellingResult result = checker.getSuggestions(spellOpts);assertTrue("result is null and it shouldn't be", result != null);//should be lowercased, b/c we are using a lowercasing analyzer@@ -179,5 +181,6 @@ public class FileBasedSpellCheckerTest extends SolrTestCaseJ4 {assertTrue("result is null and it shouldn't be", result != null);suggestions = result.get(spellOpts.tokens.iterator().next());assertTrue("suggestions is not null and it should be", suggestions == null);+ searcher.decref();}}diff --git a/solr/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java b/solr/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.javaindex 743305d2502..6a7c8ac3aa8 100644--- a/solr/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java+++ b/solr/src/test/org/apache/solr/spelling/SpellCheckCollatorTest.java@@ -33,6 +33,7 @@ import org.apache.solr.core.SolrCore;import org.apache.solr.handler.component.SearchComponent;import org.apache.solr.handler.component.SpellCheckComponent;import org.apache.solr.request.LocalSolrQueryRequest;+import org.apache.solr.request.SolrQueryRequest;import org.apache.solr.request.SolrRequestHandler;import org.apache.solr.response.SolrQueryResponse;import org.junit.BeforeClass;@@ -73,7 +74,9 @@ public class SpellCheckCollatorTest extends SolrTestCaseJ4 {SolrRequestHandler handler = core.getRequestHandler("spellCheckCompRH");SolrQueryResponse rsp = new SolrQueryResponse();rsp.add("responseHeader", new SimpleOrderedMap());- handler.handleRequest(new LocalSolrQueryRequest(core, params), rsp);+ SolrQueryRequest req = new LocalSolrQueryRequest(core, params);+ handler.handleRequest(req, rsp);+ req.close();NamedList values = rsp.getValues();NamedList spellCheck = (NamedList) values.get("spellcheck");NamedList suggestions = (NamedList) spellCheck.get("suggestions");