mirror of https://github.com/apache/lucene.git
tests: fix resource leaks + simplify
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1022735 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
62ef53cdd0
commit
9355b6d473
|
@ -101,29 +101,15 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
|
||||
assertEquals( "xxxx", comp.getAnalyzedQuery( "XXXX" ) );
|
||||
assertEquals( "xxxxyyyy", comp.getAnalyzedQuery( "XXXX YYYY" ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyQuery() throws Exception {
|
||||
SolrCore core = h.getCore();
|
||||
|
||||
//String query = "title:ipod";
|
||||
|
||||
Map<String,String> args = new HashMap<String, String>();
|
||||
args.put( "q.alt", "*:*" );
|
||||
args.put( "defType", "dismax");
|
||||
args.put( CommonParams.QT, "/elevate" );
|
||||
//args.put( CommonParams.FL, "id,title,score" );
|
||||
SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
|
||||
assertQ("Make sure QEC handles null queries", req, "//*[@numFound='0']");
|
||||
assertQ("Make sure QEC handles null queries", req("qt","/elevate", "q.alt","*:*", "defType","dismax"),
|
||||
"//*[@numFound='0']");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSorting() throws IOException
|
||||
{
|
||||
SolrCore core = h.getCore();
|
||||
|
||||
assertU(adoc("id", "a", "title", "ipod", "str_s", "a" ));
|
||||
assertU(adoc("id", "b", "title", "ipod ipod", "str_s", "b" ));
|
||||
assertU(adoc("id", "c", "title", "ipod ipod ipod", "str_s", "c" ));
|
||||
|
@ -141,8 +127,10 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
args.put( CommonParams.FL, "id,score" );
|
||||
args.put( "indent", "true" );
|
||||
//args.put( CommonParams.FL, "id,title,score" );
|
||||
SolrQueryRequest req = new LocalSolrQueryRequest( core, new MapSolrParams( args) );
|
||||
|
||||
SolrQueryRequest req = new LocalSolrQueryRequest( h.getCore(), new MapSolrParams( args) );
|
||||
IndexReader reader = req.getSearcher().getReader();
|
||||
QueryElevationComponent booster = (QueryElevationComponent)req.getCore().getSearchComponent( "elevate" );
|
||||
|
||||
assertQ("Make sure standard sort works as expected", req
|
||||
,"//*[@numFound='3']"
|
||||
,"//result/doc[1]/str[@name='id'][.='a']"
|
||||
|
@ -151,11 +139,10 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
);
|
||||
|
||||
// Explicitly set what gets boosted
|
||||
IndexReader reader = core.getSearcher().get().getReader();
|
||||
QueryElevationComponent booster = (QueryElevationComponent)core.getSearchComponent( "elevate" );
|
||||
booster.elevationCache.clear();
|
||||
booster.setTopQueryResults( reader, query, new String[] { "x", "y", "z" }, null );
|
||||
|
||||
|
||||
assertQ("All six should make it", req
|
||||
,"//*[@numFound='6']"
|
||||
,"//result/doc[1]/str[@name='id'][.='x']"
|
||||
|
@ -230,6 +217,8 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
,"//result/doc[3]/str[@name='id'][.='c']"
|
||||
);
|
||||
|
||||
|
||||
req.close();
|
||||
}
|
||||
|
||||
// write a test file to boost some docs
|
||||
|
@ -253,31 +242,33 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
@Test
|
||||
public void testElevationReloading() throws Exception
|
||||
{
|
||||
SolrCore core = h.getCore();
|
||||
|
||||
String testfile = "data-elevation.xml";
|
||||
File f = new File( core.getDataDir(), testfile );
|
||||
File f = new File( h.getCore().getDataDir(), testfile );
|
||||
writeFile( f, "aaa", "A" );
|
||||
|
||||
QueryElevationComponent comp = (QueryElevationComponent)core.getSearchComponent("elevate");
|
||||
QueryElevationComponent comp = (QueryElevationComponent)h.getCore().getSearchComponent("elevate");
|
||||
NamedList<String> args = new NamedList<String>();
|
||||
args.add( QueryElevationComponent.CONFIG_FILE, testfile );
|
||||
comp.init( args );
|
||||
comp.inform( core );
|
||||
|
||||
IndexReader reader = core.getSearcher().get().getReader();
|
||||
Map<String, ElevationObj> map = comp.getElevationMap(reader, core);
|
||||
comp.inform( h.getCore() );
|
||||
|
||||
SolrQueryRequest req = req();
|
||||
IndexReader reader = req.getSearcher().getReader();
|
||||
Map<String, ElevationObj> map = comp.getElevationMap(reader, h.getCore());
|
||||
assertTrue( map.get( "aaa" ).priority.containsKey( new BytesRef("A") ) );
|
||||
assertNull( map.get( "bbb" ) );
|
||||
req.close();
|
||||
|
||||
// now change the file
|
||||
writeFile( f, "bbb", "B" );
|
||||
assertU(adoc("id", "10000")); // will get same reader if no index change
|
||||
assertU(commit());
|
||||
|
||||
reader = core.getSearcher().get().getReader();
|
||||
map = comp.getElevationMap(reader, core);
|
||||
|
||||
req = req();
|
||||
reader = req.getSearcher().getReader();
|
||||
map = comp.getElevationMap(reader, h.getCore());
|
||||
assertNull( map.get( "aaa" ) );
|
||||
assertTrue( map.get( "bbb" ).priority.containsKey( new BytesRef("B") ) );
|
||||
req.close();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue