SOLR-1520: support trie types, fix issues with failing tests

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1215352 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Grant Ingersoll 2011-12-16 23:51:12 +00:00
parent e9a2796c85
commit 39f7791817
5 changed files with 57 additions and 10 deletions

View File

@ -157,9 +157,9 @@ public class QueryElevationComponent extends SearchComponent implements SolrCore
} }
SchemaField sf = core.getSchema().getUniqueKeyField(); SchemaField sf = core.getSchema().getUniqueKeyField();
if( sf == null || sf.getType().isTokenized() == true) { if( sf == null) {
throw new SolrException( SolrException.ErrorCode.SERVER_ERROR, throw new SolrException( SolrException.ErrorCode.SERVER_ERROR,
"QueryElevationComponent requires the schema to have a uniqueKeyField implemented using a non-tokenized field" ); "QueryElevationComponent requires the schema to have a uniqueKeyField." );
} }
idSchemaFT = sf.getType(); idSchemaFT = sf.getType();
idField = sf.getName(); idField = sf.getName();

View File

@ -20,9 +20,12 @@ package org.apache.solr.response.transform;
import java.util.Set; import java.util.Set;
import org.apache.lucene.document.Field; import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericField;
import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.params.SolrParams; import org.apache.solr.common.params.SolrParams;
import org.apache.solr.request.SolrQueryRequest; import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.SchemaField;
/** /**
* *
@ -32,8 +35,9 @@ public class EditorialMarkerFactory extends TransformerFactory
{ {
@Override @Override
public DocTransformer create(String field, SolrParams params, SolrQueryRequest req) { public DocTransformer create(String field, SolrParams params, SolrQueryRequest req) {
String idfield = req.getSchema().getUniqueKeyField().getName(); SchemaField uniqueKeyField = req.getSchema().getUniqueKeyField();
return new MarkTransformer(field,idfield); String idfield = uniqueKeyField.getName();
return new MarkTransformer(field,idfield, uniqueKeyField.getType());
} }
} }
@ -41,11 +45,13 @@ class MarkTransformer extends TransformerWithContext
{ {
final String name; final String name;
final String idFieldName; final String idFieldName;
final FieldType ft;
public MarkTransformer( String name, String idFieldName) public MarkTransformer( String name, String idFieldName, FieldType ft)
{ {
this.name = name; this.name = name;
this.idFieldName = idFieldName; this.idFieldName = idFieldName;
this.ft = ft;
} }
@Override @Override
@ -60,11 +66,15 @@ class MarkTransformer extends TransformerWithContext
if(ids!=null) { if(ids!=null) {
String key; String key;
Object field = doc.get(idFieldName); Object field = doc.get(idFieldName);
if (field instanceof Field){ if (field instanceof NumericField){
key = ((Field)field).stringValue();
key = ft.readableToIndexed(key);
} else if (field instanceof Field){
key = ((Field)field).stringValue(); key = ((Field)field).stringValue();
} else { } else {
key = field.toString(); key = field.toString();
} }
doc.setField(name, ids.contains(key)); doc.setField(name, ids.contains(key));
} else { } else {
//if we have no ids, that means we weren't boosting, but the user still asked for the field to be added, so just mark everything as false //if we have no ids, that means we weren't boosting, but the user still asked for the field to be added, so just mark everything as false

View File

@ -34,7 +34,7 @@
</query> </query>
<query text="AAAA"> <query text="AAAA">
<doc id="7.0" /> <doc id="7" />
</query> </query>

View File

@ -425,7 +425,6 @@
</arr> </arr>
</requestHandler> </requestHandler>
<searchComponent name="tvComponent" class="org.apache.solr.handler.component.TermVectorComponent"/> <searchComponent name="tvComponent" class="org.apache.solr.handler.component.TermVectorComponent"/>
<requestHandler name="tvrh" class="org.apache.solr.handler.component.SearchHandler"> <requestHandler name="tvrh" class="org.apache.solr.handler.component.SearchHandler">

View File

@ -53,6 +53,10 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
} }
private void init(String schema) throws Exception { private void init(String schema) throws Exception {
init("solrconfig-elevate.xml", schema);
}
private void init(String config, 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");
@ -60,7 +64,7 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
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",schema); initCore(config,schema);
clearIndex(); clearIndex();
assertU(commit()); assertU(commit());
} }
@ -102,6 +106,40 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
} }
} }
@Test
public void testTrieFieldType() throws Exception {
try {
init("schema.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]/int[@name='id'][.='7']"
,"//result/doc[2]/int[@name='id'][.='8']"
,"//result/doc[3]/int[@name='id'][.='9']",
"//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
{ {
@ -188,7 +226,7 @@ public class QueryElevationComponentTest extends SolrTestCaseJ4 {
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]'][.='true']"
); );
assertQ("", req(CommonParams.Q, "AAAA", CommonParams.QT, "/elevate", assertQ("", req(CommonParams.Q, "AAAA", CommonParams.QT, "/elevate",