SOLR-1520: added tests

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1213824 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2011-12-13 18:22:39 +00:00
parent 0f8fe10c7d
commit 7efb166240
3 changed files with 283 additions and 224 deletions

View File

@ -84,6 +84,7 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore
private SolrParams initArgs = null; private SolrParams initArgs = null;
private Analyzer analyzer = null; private Analyzer analyzer = null;
private String idField = null; private String idField = null;
private FieldType idSchemaFT;
boolean forceElevation = false; boolean forceElevation = false;
// For each IndexReader, keep a query->elevation map // For each IndexReader, keep a query->elevation map
@ -115,6 +116,7 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore
this.priority = new HashMap<BytesRef, Integer>(); this.priority = new HashMap<BytesRef, Integer>();
int max = elevate.size()+5; int max = elevate.size()+5;
for( String id : elevate ) { for( String id : elevate ) {
id = idSchemaFT.readableToIndexed(id);
ids.add(id); ids.add(id);
TermQuery tq = new TermQuery( new Term( idField, id ) ); TermQuery tq = new TermQuery( new Term( idField, id ) );
include.add( tq, BooleanClause.Occur.SHOULD ); include.add( tq, BooleanClause.Occur.SHOULD );
@ -127,7 +129,7 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore
else { else {
this.exclude = new BooleanClause[exclude.size()]; this.exclude = new BooleanClause[exclude.size()];
for( int i=0; i<exclude.size(); i++ ) { for( int i=0; i<exclude.size(); i++ ) {
TermQuery tq = new TermQuery( new Term( idField, exclude.get(i) ) ); TermQuery tq = new TermQuery( new Term( idField, idSchemaFT.readableToIndexed(exclude.get(i)) ) );
this.exclude[i] = new BooleanClause( tq, BooleanClause.Occur.MUST_NOT ); this.exclude[i] = new BooleanClause( tq, BooleanClause.Occur.MUST_NOT );
} }
} }
@ -155,10 +157,11 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore
} }
SchemaField sf = core.getSchema().getUniqueKeyField(); SchemaField sf = core.getSchema().getUniqueKeyField();
if( sf == null || !(sf.getType() instanceof StrField)) { if( sf == null || sf.getType().isTokenized() == true) {
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
"QueryElevationComponent requires the schema to have a uniqueKeyField implemented using StrField" ); "QueryElevationComponent requires the schema to have a uniqueKeyField implemented using a non-tokenized field" );
} }
idSchemaFT = sf.getType();
idField = sf.getName(); idField = sf.getName();
//register the EditorialMarkerFactory //register the EditorialMarkerFactory
EditorialMarkerFactory factory = new EditorialMarkerFactory(); EditorialMarkerFactory factory = new EditorialMarkerFactory();

View File

@ -32,5 +32,11 @@
<doc id="2" /> <doc id="2" />
<doc id="3" /> <doc id="3" />
</query> </query>
<query text="AAAA">
<doc id="7.0" />
</query>
</elevate> </elevate>

View File

@ -36,6 +36,7 @@ import org.apache.solr.core.SolrCore;
import org.apache.solr.handler.component.QueryElevationComponent.ElevationObj; import org.apache.solr.handler.component.QueryElevationComponent.ElevationObj;
import org.apache.solr.request.LocalSolrQueryRequest; import org.apache.solr.request.LocalSolrQueryRequest;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -44,237 +45,281 @@ import org.junit.Test;
public class QueryElevationComponentTest extends SolrTestCaseJ4 { public class QueryElevationComponentTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception { @Before
@Override
public void setUp() throws Exception{
super.setUp();
}
private void init(String schema) throws Exception {
//write out elevate-data.xml to the Data dir first by copying it from conf, which we know exists, this way we can test both conf and data configurations //write out elevate-data.xml to the Data dir first by copying it from conf, which we know exists, this way we can test both conf and data configurations
createTempDir(); createTempDir();
File parent = new File(TEST_HOME(), "conf"); File parent = new File(TEST_HOME(), "conf");
File elevateFile = new File(parent, "elevate.xml"); File elevateFile = new File(parent, "elevate.xml");
File elevateDataFile = new File(dataDir, "elevate-data.xml"); File elevateDataFile = new File(dataDir, "elevate-data.xml");
FileUtils.copyFile(elevateFile, elevateDataFile); FileUtils.copyFile(elevateFile, elevateDataFile);
initCore("solrconfig-elevate.xml", "schema12.xml");
}
@Before initCore("solrconfig-elevate.xml",schema);
@Override
public void setUp() throws Exception{
super.setUp();
clearIndex(); clearIndex();
assertU(commit()); assertU(commit());
assertU(optimize());
// make sure this component is initialized correctly for each test
QueryElevationComponent comp = (QueryElevationComponent)h.getCore().getSearchComponent("elevate");
NamedList<String> args = new NamedList<String>();
args.add( QueryElevationComponent.CONFIG_FILE, "elevate.xml" );
args.add( QueryElevationComponent.FIELD_TYPE, "string" );
comp.init( args );
comp.inform( h.getCore() );
comp.forceElevation = false;
} }
private void delete() throws Exception {
deleteCore();
}
@Test
public void testFieldType() throws Exception {
try {
init("schema11.xml");
clearIndex();
assertU(commit());
assertU(adoc("id", "1", "text", "XXXX XXXX", "str_s", "a" ));
assertU(adoc("id", "2", "text", "YYYY", "str_s", "b" ));
assertU(adoc("id", "3", "text", "ZZZZ", "str_s", "c" ));
assertU(adoc("id", "4", "text", "XXXX XXXX", "str_s", "x" ));
assertU(adoc("id", "5", "text", "YYYY YYYY", "str_s", "y" ));
assertU(adoc("id", "6", "text", "XXXX XXXX", "str_s", "z" ));
assertU(adoc("id", "7", "text", "AAAA", "str_s", "a" ));
assertU(adoc("id", "8", "text", "AAAA", "str_s", "a" ));
assertU(adoc("id", "9", "text", "AAAA AAAA", "str_s", "a" ));
assertU(commit());
assertQ("", req(CommonParams.Q, "AAAA", CommonParams.QT, "/elevate",
CommonParams.FL, "id, score, [elevated]")
,"//*[@numFound='3']"
,"//result/doc[1]/float[@name='id'][.='7.0']"
,"//result/doc[2]/float[@name='id'][.='8.0']"
,"//result/doc[3]/float[@name='id'][.='9.0']",
"//result/doc[1]/bool[@name='[elevated]'][.='true']",
"//result/doc[2]/bool[@name='[elevated]'][.='false']",
"//result/doc[3]/bool[@name='[elevated]'][.='false']"
);
} finally{
delete();
}
}
@Test @Test
public void testInterface() throws Exception public void testInterface() throws Exception
{ {
SolrCore core = h.getCore(); try {
init("schema12.xml");
NamedList<String> args = new NamedList<String>(); SolrCore core = h.getCore();
args.add( QueryElevationComponent.FIELD_TYPE, "string" );
args.add( QueryElevationComponent.CONFIG_FILE, "elevate.xml" );
QueryElevationComponent comp = new QueryElevationComponent();
comp.init( args );
comp.inform( core );
SolrQueryRequest req = req(); NamedList<String> args = new NamedList<String>();
IndexReader reader = req.getSearcher().getIndexReader(); args.add( QueryElevationComponent.FIELD_TYPE, "string" );
Map<String, ElevationObj> map = comp.getElevationMap( reader, core ); args.add( QueryElevationComponent.CONFIG_FILE, "elevate.xml" );
req.close();
// Make sure the boosts loaded properly QueryElevationComponent comp = new QueryElevationComponent();
assertEquals( 3, map.size() ); comp.init( args );
assertEquals( 1, map.get( "XXXX" ).priority.size() ); comp.inform( core );
assertEquals( 2, map.get( "YYYY" ).priority.size() );
assertEquals( 3, map.get( "ZZZZ" ).priority.size() );
assertEquals( null, map.get( "xxxx" ) );
assertEquals( null, map.get( "yyyy" ) );
assertEquals( null, map.get( "zzzz" ) );
// Now test the same thing with a lowercase filter: 'lowerfilt'
args = new NamedList<String>();
args.add( QueryElevationComponent.FIELD_TYPE, "lowerfilt" );
args.add( QueryElevationComponent.CONFIG_FILE, "elevate.xml" );
comp = new QueryElevationComponent();
comp.init( args );
comp.inform( core );
map = comp.getElevationMap( reader, core );
assertEquals( 3, map.size() );
assertEquals( null, map.get( "XXXX" ) );
assertEquals( null, map.get( "YYYY" ) );
assertEquals( null, map.get( "ZZZZ" ) );
assertEquals( 1, map.get( "xxxx" ).priority.size() );
assertEquals( 2, map.get( "yyyy" ).priority.size() );
assertEquals( 3, map.get( "zzzz" ).priority.size() );
assertEquals( "xxxx", comp.getAnalyzedQuery( "XXXX" ) );
assertEquals( "xxxxyyyy", comp.getAnalyzedQuery( "XXXX YYYY" ) );
assertQ("Make sure QEC handles null queries", req("qt","/elevate", "q.alt","*:*", "defType","dismax"), SolrQueryRequest req = req();
"//*[@numFound='0']"); IndexReader reader = req.getSearcher().getIndexReader();
Map<String, ElevationObj> map = comp.getElevationMap( reader, core );
req.close();
// Make sure the boosts loaded properly
assertEquals( 4, map.size() );
assertEquals( 1, map.get( "XXXX" ).priority.size() );
assertEquals( 2, map.get( "YYYY" ).priority.size() );
assertEquals( 3, map.get( "ZZZZ" ).priority.size() );
assertEquals( null, map.get( "xxxx" ) );
assertEquals( null, map.get( "yyyy" ) );
assertEquals( null, map.get( "zzzz" ) );
// Now test the same thing with a lowercase filter: 'lowerfilt'
args = new NamedList<String>();
args.add( QueryElevationComponent.FIELD_TYPE, "lowerfilt" );
args.add( QueryElevationComponent.CONFIG_FILE, "elevate.xml" );
comp = new QueryElevationComponent();
comp.init( args );
comp.inform( core );
map = comp.getElevationMap( reader, core );
assertEquals( 4, map.size() );
assertEquals( null, map.get( "XXXX" ) );
assertEquals( null, map.get( "YYYY" ) );
assertEquals( null, map.get( "ZZZZ" ) );
assertEquals( 1, map.get( "xxxx" ).priority.size() );
assertEquals( 2, map.get( "yyyy" ).priority.size() );
assertEquals( 3, map.get( "zzzz" ).priority.size() );
assertEquals( "xxxx", comp.getAnalyzedQuery( "XXXX" ) );
assertEquals( "xxxxyyyy", comp.getAnalyzedQuery( "XXXX YYYY" ) );
assertQ("Make sure QEC handles null queries", req("qt","/elevate", "q.alt","*:*", "defType","dismax"),
"//*[@numFound='0']");
} finally {
delete();
}
} }
@Test @Test
public void testMarker() throws Exception { public void testMarker() throws Exception {
assertU(adoc("id", "1", "title", "XXXX XXXX", "str_s1", "a" )); try {
assertU(adoc("id", "2", "title", "YYYY", "str_s1", "b" )); init("schema12.xml");
assertU(adoc("id", "3", "title", "ZZZZ", "str_s1", "c" )); assertU(adoc("id", "1", "title", "XXXX XXXX", "str_s1", "a" ));
assertU(adoc("id", "2", "title", "YYYY", "str_s1", "b" ));
assertU(adoc("id", "3", "title", "ZZZZ", "str_s1", "c" ));
assertU(adoc("id", "4", "title", "XXXX XXXX", "str_s1", "x" )); assertU(adoc("id", "4", "title", "XXXX XXXX", "str_s1", "x" ));
assertU(adoc("id", "5", "title", "YYYY YYYY", "str_s1", "y" )); assertU(adoc("id", "5", "title", "YYYY YYYY", "str_s1", "y" ));
assertU(adoc("id", "6", "title", "XXXX XXXX", "str_s1", "z" )); assertU(adoc("id", "6", "title", "XXXX XXXX", "str_s1", "z" ));
assertU(adoc("id", "7", "title", "AAAA", "str_s1", "a" )); assertU(adoc("id", "7", "title", "AAAA", "str_s1", "a" ));
assertU(commit()); assertU(commit());
assertQ("", req(CommonParams.Q, "XXXX", CommonParams.QT, "/elevate", assertQ("", req(CommonParams.Q, "XXXX", CommonParams.QT, "/elevate",
CommonParams.FL, "id, score, [elevated]") CommonParams.FL, "id, score, [elevated]")
,"//*[@numFound='3']" ,"//*[@numFound='3']"
,"//result/doc[1]/str[@name='id'][.='1']" ,"//result/doc[1]/str[@name='id'][.='1']"
,"//result/doc[2]/str[@name='id'][.='4']" ,"//result/doc[2]/str[@name='id'][.='4']"
,"//result/doc[3]/str[@name='id'][.='6']", ,"//result/doc[3]/str[@name='id'][.='6']",
"//result/doc[1]/bool[@name='[elevated]'][.='true']", "//result/doc[1]/bool[@name='[elevated]'][.='true']",
"//result/doc[2]/bool[@name='[elevated]'][.='false']", "//result/doc[2]/bool[@name='[elevated]'][.='false']",
"//result/doc[3]/bool[@name='[elevated]'][.='false']" "//result/doc[3]/bool[@name='[elevated]'][.='false']"
); );
assertQ("", req(CommonParams.Q, "AAAA", CommonParams.QT, "/elevate", assertQ("", req(CommonParams.Q, "AAAA", CommonParams.QT, "/elevate",
CommonParams.FL, "id, score, [elevated]") CommonParams.FL, "id, score, [elevated]")
,"//*[@numFound='1']" ,"//*[@numFound='1']"
,"//result/doc[1]/str[@name='id'][.='7']", ,"//result/doc[1]/str[@name='id'][.='7']",
"//result/doc[1]/bool[@name='[elevated]'][.='false']" "//result/doc[1]/bool[@name='[elevated]'][.='false']"
); );
assertQ("", req(CommonParams.Q, "AAAA", CommonParams.QT, "/elevate", assertQ("", req(CommonParams.Q, "AAAA", CommonParams.QT, "/elevate",
CommonParams.FL, "id, score, [elev]") CommonParams.FL, "id, score, [elev]")
,"//*[@numFound='1']" ,"//*[@numFound='1']"
,"//result/doc[1]/str[@name='id'][.='7']", ,"//result/doc[1]/str[@name='id'][.='7']",
"not(//result/doc[1]/bool[@name='[elevated]'][.='false'])", "not(//result/doc[1]/bool[@name='[elevated]'][.='false'])",
"not(//result/doc[1]/bool[@name='[elev]'][.='false'])" // even though we asked for elev, there is no Transformer registered w/ that, so we shouldn't get a result "not(//result/doc[1]/bool[@name='[elev]'][.='false'])" // even though we asked for elev, there is no Transformer registered w/ that, so we shouldn't get a result
); );
} finally {
delete();
}
} }
@Test @Test
public void testSorting() throws IOException public void testSorting() throws Exception
{ {
assertU(adoc("id", "a", "title", "ipod", "str_s1", "a" )); try {
assertU(adoc("id", "b", "title", "ipod ipod", "str_s1", "b" )); init("schema12.xml");
assertU(adoc("id", "c", "title", "ipod ipod ipod", "str_s1", "c" )); assertU(adoc("id", "a", "title", "ipod", "str_s1", "a" ));
assertU(adoc("id", "b", "title", "ipod ipod", "str_s1", "b" ));
assertU(adoc("id", "c", "title", "ipod ipod ipod", "str_s1", "c" ));
assertU(adoc("id", "x", "title", "boosted", "str_s1", "x" )); assertU(adoc("id", "x", "title", "boosted", "str_s1", "x" ));
assertU(adoc("id", "y", "title", "boosted boosted", "str_s1", "y" )); assertU(adoc("id", "y", "title", "boosted boosted", "str_s1", "y" ));
assertU(adoc("id", "z", "title", "boosted boosted boosted", "str_s1", "z" )); assertU(adoc("id", "z", "title", "boosted boosted boosted", "str_s1", "z" ));
assertU(commit()); assertU(commit());
String query = "title:ipod";
Map<String,String> args = new HashMap<String, String>();
args.put( CommonParams.Q, query );
args.put( CommonParams.QT, "/elevate" );
args.put( CommonParams.FL, "id,score" );
args.put( "indent", "true" );
//args.put( CommonParams.FL, "id,title,score" );
SolrQueryRequest req = new LocalSolrQueryRequest( h.getCore(), new MapSolrParams( args) );
IndexReader reader = req.getSearcher().getIndexReader();
QueryElevationComponent booster = (QueryElevationComponent)req.getCore().getSearchComponent( "elevate" );
assertQ("Make sure standard sort works as expected", req String query = "title:ipod";
,"//*[@numFound='3']"
,"//result/doc[1]/str[@name='id'][.='a']" Map<String,String> args = new HashMap<String, String>();
,"//result/doc[2]/str[@name='id'][.='b']" args.put( CommonParams.Q, query );
,"//result/doc[3]/str[@name='id'][.='c']" args.put( CommonParams.QT, "/elevate" );
); args.put( CommonParams.FL, "id,score" );
args.put( "indent", "true" );
// Explicitly set what gets boosted //args.put( CommonParams.FL, "id,title,score" );
booster.elevationCache.clear(); SolrQueryRequest req = new LocalSolrQueryRequest( h.getCore(), new MapSolrParams( args) );
booster.setTopQueryResults( reader, query, new String[] { "x", "y", "z" }, null ); IndexReader reader = req.getSearcher().getIndexReader();
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']"
,"//result/doc[2]/str[@name='id'][.='b']"
,"//result/doc[3]/str[@name='id'][.='c']"
);
// Explicitly set what gets boosted
booster.elevationCache.clear();
booster.setTopQueryResults( reader, query, new String[] { "x", "y", "z" }, null );
assertQ("All six should make it", req assertQ("All six should make it", req
,"//*[@numFound='6']" ,"//*[@numFound='6']"
,"//result/doc[1]/str[@name='id'][.='x']" ,"//result/doc[1]/str[@name='id'][.='x']"
,"//result/doc[2]/str[@name='id'][.='y']" ,"//result/doc[2]/str[@name='id'][.='y']"
,"//result/doc[3]/str[@name='id'][.='z']" ,"//result/doc[3]/str[@name='id'][.='z']"
,"//result/doc[4]/str[@name='id'][.='a']" ,"//result/doc[4]/str[@name='id'][.='a']"
,"//result/doc[5]/str[@name='id'][.='b']" ,"//result/doc[5]/str[@name='id'][.='b']"
,"//result/doc[6]/str[@name='id'][.='c']" ,"//result/doc[6]/str[@name='id'][.='c']"
); );
booster.elevationCache.clear();
// now switch the order:
booster.setTopQueryResults( reader, query, new String[] { "a", "x" }, null );
assertQ("All four should make it", req
,"//*[@numFound='4']"
,"//result/doc[1]/str[@name='id'][.='a']"
,"//result/doc[2]/str[@name='id'][.='x']"
,"//result/doc[3]/str[@name='id'][.='b']"
,"//result/doc[4]/str[@name='id'][.='c']"
);
// Test reverse sort
args.put( CommonParams.SORT, "score asc" );
assertQ("All four should make it", req
,"//*[@numFound='4']"
,"//result/doc[4]/str[@name='id'][.='a']"
,"//result/doc[3]/str[@name='id'][.='x']"
,"//result/doc[2]/str[@name='id'][.='b']"
,"//result/doc[1]/str[@name='id'][.='c']"
);
// Try normal sort by 'id'
// default 'forceBoost' should be false
assertEquals( false, booster.forceElevation );
args.put( CommonParams.SORT, "str_s1 asc" );
assertQ( null, req
,"//*[@numFound='4']"
,"//result/doc[1]/str[@name='id'][.='a']"
,"//result/doc[2]/str[@name='id'][.='b']"
,"//result/doc[3]/str[@name='id'][.='c']"
,"//result/doc[4]/str[@name='id'][.='x']"
);
booster.forceElevation = true;
assertQ( null, req
,"//*[@numFound='4']"
,"//result/doc[1]/str[@name='id'][.='a']"
,"//result/doc[2]/str[@name='id'][.='x']"
,"//result/doc[3]/str[@name='id'][.='b']"
,"//result/doc[4]/str[@name='id'][.='c']"
);
//Test exclusive (not to be confused with exclusion) booster.elevationCache.clear();
args.put(QueryElevationParams.EXCLUSIVE, "true");
booster.setTopQueryResults( reader, query, new String[] { "x", "a" }, new String[] {} );
assertQ( null, req
,"//*[@numFound='2']"
,"//result/doc[1]/str[@name='id'][.='x']"
,"//result/doc[2]/str[@name='id'][.='a']"
);
// Test exclusion // now switch the order:
booster.elevationCache.clear(); booster.setTopQueryResults( reader, query, new String[] { "a", "x" }, null );
args.remove( CommonParams.SORT ); assertQ("All four should make it", req
args.remove( QueryElevationParams.EXCLUSIVE); ,"//*[@numFound='4']"
booster.setTopQueryResults( reader, query, new String[] { "x" }, new String[] { "a" } ); ,"//result/doc[1]/str[@name='id'][.='a']"
assertQ( null, req ,"//result/doc[2]/str[@name='id'][.='x']"
,"//*[@numFound='3']" ,"//result/doc[3]/str[@name='id'][.='b']"
,"//result/doc[1]/str[@name='id'][.='x']" ,"//result/doc[4]/str[@name='id'][.='c']"
,"//result/doc[2]/str[@name='id'][.='b']" );
,"//result/doc[3]/str[@name='id'][.='c']"
); // Test reverse sort
args.put( CommonParams.SORT, "score asc" );
assertQ("All four should make it", req
,"//*[@numFound='4']"
,"//result/doc[4]/str[@name='id'][.='a']"
,"//result/doc[3]/str[@name='id'][.='x']"
,"//result/doc[2]/str[@name='id'][.='b']"
,"//result/doc[1]/str[@name='id'][.='c']"
);
// Try normal sort by 'id'
// default 'forceBoost' should be false
assertEquals( false, booster.forceElevation );
args.put( CommonParams.SORT, "str_s1 asc" );
assertQ( null, req
,"//*[@numFound='4']"
,"//result/doc[1]/str[@name='id'][.='a']"
,"//result/doc[2]/str[@name='id'][.='b']"
,"//result/doc[3]/str[@name='id'][.='c']"
,"//result/doc[4]/str[@name='id'][.='x']"
);
booster.forceElevation = true;
assertQ( null, req
,"//*[@numFound='4']"
,"//result/doc[1]/str[@name='id'][.='a']"
,"//result/doc[2]/str[@name='id'][.='x']"
,"//result/doc[3]/str[@name='id'][.='b']"
,"//result/doc[4]/str[@name='id'][.='c']"
);
//Test exclusive (not to be confused with exclusion)
args.put(QueryElevationParams.EXCLUSIVE, "true");
booster.setTopQueryResults( reader, query, new String[] { "x", "a" }, new String[] {} );
assertQ( null, req
,"//*[@numFound='2']"
,"//result/doc[1]/str[@name='id'][.='x']"
,"//result/doc[2]/str[@name='id'][.='a']"
);
// Test exclusion
booster.elevationCache.clear();
args.remove( CommonParams.SORT );
args.remove( QueryElevationParams.EXCLUSIVE);
booster.setTopQueryResults( reader, query, new String[] { "x" }, new String[] { "a" } );
assertQ( null, req
,"//*[@numFound='3']"
,"//result/doc[1]/str[@name='id'][.='x']"
,"//result/doc[2]/str[@name='id'][.='b']"
,"//result/doc[3]/str[@name='id'][.='c']"
);
req.close(); req.close();
} finally {
delete();
}
} }
// write a test file to boost some docs // write a test file to boost some docs
@ -298,33 +343,38 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
@Test @Test
public void testElevationReloading() throws Exception public void testElevationReloading() throws Exception
{ {
String testfile = "data-elevation.xml"; try {
File f = new File( h.getCore().getDataDir(), testfile ); init("schema12.xml");
writeFile( f, "aaa", "A" ); String testfile = "data-elevation.xml";
File f = new File( h.getCore().getDataDir(), testfile );
QueryElevationComponent comp = (QueryElevationComponent)h.getCore().getSearchComponent("elevate"); writeFile( f, "aaa", "A" );
NamedList<String> args = new NamedList<String>();
args.add( QueryElevationComponent.CONFIG_FILE, testfile );
comp.init( args );
comp.inform( h.getCore() );
SolrQueryRequest req = req(); QueryElevationComponent comp = (QueryElevationComponent)h.getCore().getSearchComponent("elevate");
IndexReader reader = req.getSearcher().getIndexReader(); NamedList<String> args = new NamedList<String>();
Map<String, ElevationObj> map = comp.getElevationMap(reader, h.getCore()); args.add( QueryElevationComponent.CONFIG_FILE, testfile );
assertTrue( map.get( "aaa" ).priority.containsKey( new BytesRef("A") ) ); comp.init( args );
assertNull( map.get( "bbb" ) ); comp.inform( h.getCore() );
req.close();
// now change the file
writeFile( f, "bbb", "B" );
assertU(adoc("id", "10000")); // will get same reader if no index change
assertU(commit());
req = req(); SolrQueryRequest req = req();
reader = req.getSearcher().getIndexReader(); IndexReader reader = req.getSearcher().getIndexReader();
map = comp.getElevationMap(reader, h.getCore()); Map<String, ElevationObj> map = comp.getElevationMap(reader, h.getCore());
assertNull( map.get( "aaa" ) ); assertTrue( map.get( "aaa" ).priority.containsKey( new BytesRef("A") ) );
assertTrue( map.get( "bbb" ).priority.containsKey( new BytesRef("B") ) ); assertNull( map.get( "bbb" ) );
req.close(); req.close();
// now change the file
writeFile( f, "bbb", "B" );
assertU(adoc("id", "10000")); // will get same reader if no index change
assertU(commit());
req = req();
reader = req.getSearcher().getIndexReader();
map = comp.getElevationMap(reader, h.getCore());
assertNull( map.get( "aaa" ) );
assertTrue( map.get( "bbb" ).priority.containsKey( new BytesRef("B") ) );
req.close();
} finally {
delete();
}
} }
} }