mirror of https://github.com/apache/lucene.git
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:
parent
0f8fe10c7d
commit
7efb166240
|
@ -84,6 +84,7 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore
|
|||
private SolrParams initArgs = null;
|
||||
private Analyzer analyzer = null;
|
||||
private String idField = null;
|
||||
private FieldType idSchemaFT;
|
||||
|
||||
boolean forceElevation = false;
|
||||
// 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>();
|
||||
int max = elevate.size()+5;
|
||||
for( String id : elevate ) {
|
||||
id = idSchemaFT.readableToIndexed(id);
|
||||
ids.add(id);
|
||||
TermQuery tq = new TermQuery( new Term( idField, id ) );
|
||||
include.add( tq, BooleanClause.Occur.SHOULD );
|
||||
|
@ -127,7 +129,7 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore
|
|||
else {
|
||||
this.exclude = new BooleanClause[exclude.size()];
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
@ -155,10 +157,11 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore
|
|||
}
|
||||
|
||||
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,
|
||||
"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();
|
||||
//register the EditorialMarkerFactory
|
||||
EditorialMarkerFactory factory = new EditorialMarkerFactory();
|
||||
|
|
|
@ -33,4 +33,10 @@
|
|||
<doc id="3" />
|
||||
</query>
|
||||
|
||||
<query text="AAAA">
|
||||
<doc id="7.0" />
|
||||
</query>
|
||||
|
||||
|
||||
|
||||
</elevate>
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.apache.solr.core.SolrCore;
|
|||
import org.apache.solr.handler.component.QueryElevationComponent.ElevationObj;
|
||||
import org.apache.solr.request.LocalSolrQueryRequest;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
@ -44,37 +45,68 @@ import org.junit.Test;
|
|||
|
||||
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
|
||||
createTempDir();
|
||||
File parent = new File(TEST_HOME(), "conf");
|
||||
File elevateFile = new File(parent, "elevate.xml");
|
||||
File elevateDataFile = new File(dataDir, "elevate-data.xml");
|
||||
FileUtils.copyFile(elevateFile, elevateDataFile);
|
||||
initCore("solrconfig-elevate.xml", "schema12.xml");
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception{
|
||||
super.setUp();
|
||||
initCore("solrconfig-elevate.xml",schema);
|
||||
clearIndex();
|
||||
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
|
||||
public void testInterface() throws Exception
|
||||
{
|
||||
try {
|
||||
init("schema12.xml");
|
||||
SolrCore core = h.getCore();
|
||||
|
||||
NamedList<String> args = new NamedList<String>();
|
||||
|
@ -91,7 +123,7 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
req.close();
|
||||
|
||||
// Make sure the boosts loaded properly
|
||||
assertEquals( 3, map.size() );
|
||||
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() );
|
||||
|
@ -108,7 +140,7 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
comp.init( args );
|
||||
comp.inform( core );
|
||||
map = comp.getElevationMap( reader, core );
|
||||
assertEquals( 3, map.size() );
|
||||
assertEquals( 4, map.size() );
|
||||
assertEquals( null, map.get( "XXXX" ) );
|
||||
assertEquals( null, map.get( "YYYY" ) );
|
||||
assertEquals( null, map.get( "ZZZZ" ) );
|
||||
|
@ -121,11 +153,16 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
|
||||
assertQ("Make sure QEC handles null queries", req("qt","/elevate", "q.alt","*:*", "defType","dismax"),
|
||||
"//*[@numFound='0']");
|
||||
} finally {
|
||||
delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarker() throws Exception {
|
||||
try {
|
||||
init("schema12.xml");
|
||||
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" ));
|
||||
|
@ -161,11 +198,16 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
"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
|
||||
);
|
||||
} finally {
|
||||
delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSorting() throws IOException
|
||||
public void testSorting() throws Exception
|
||||
{
|
||||
try {
|
||||
init("schema12.xml");
|
||||
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" ));
|
||||
|
@ -275,6 +317,9 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
|
||||
|
||||
req.close();
|
||||
} finally {
|
||||
delete();
|
||||
}
|
||||
}
|
||||
|
||||
// write a test file to boost some docs
|
||||
|
@ -298,6 +343,8 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
@Test
|
||||
public void testElevationReloading() throws Exception
|
||||
{
|
||||
try {
|
||||
init("schema12.xml");
|
||||
String testfile = "data-elevation.xml";
|
||||
File f = new File( h.getCore().getDataDir(), testfile );
|
||||
writeFile( f, "aaa", "A" );
|
||||
|
@ -326,5 +373,8 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
|
|||
assertNull( map.get( "aaa" ) );
|
||||
assertTrue( map.get( "bbb" ).priority.containsKey( new BytesRef("B") ) );
|
||||
req.close();
|
||||
} finally {
|
||||
delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue