mirror of https://github.com/apache/lucene.git
SOLR-2830: apply transformers in RealTimeGetComponent
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1183177 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ddbbab534c
commit
212543268b
|
@ -29,6 +29,7 @@ import org.apache.solr.common.params.SolrParams;
|
|||
import org.apache.solr.common.util.StrUtils;
|
||||
import org.apache.solr.request.SolrQueryRequest;
|
||||
import org.apache.solr.response.SolrQueryResponse;
|
||||
import org.apache.solr.response.transform.DocTransformer;
|
||||
import org.apache.solr.schema.FieldType;
|
||||
import org.apache.solr.schema.IndexSchema;
|
||||
import org.apache.solr.schema.SchemaField;
|
||||
|
@ -100,6 +101,7 @@ public class RealTimeGetComponent extends SearchComponent
|
|||
|
||||
RefCounted<SolrIndexSearcher> searcherHolder = null;
|
||||
|
||||
DocTransformer transformer = rsp.getReturnFields().getTransformer();
|
||||
try {
|
||||
SolrIndexSearcher searcher = null;
|
||||
|
||||
|
@ -115,7 +117,11 @@ public class RealTimeGetComponent extends SearchComponent
|
|||
int oper = (Integer)entry.get(0);
|
||||
switch (oper) {
|
||||
case UpdateLog.ADD:
|
||||
docList.add(toSolrDoc((SolrInputDocument)entry.get(entry.size()-1), req.getSchema()));
|
||||
SolrDocument doc = toSolrDoc((SolrInputDocument)entry.get(entry.size()-1), req.getSchema());
|
||||
if(transformer!=null) {
|
||||
transformer.transform(doc, -1); // unknown docID
|
||||
}
|
||||
docList.add(doc);
|
||||
break;
|
||||
case UpdateLog.DELETE:
|
||||
break;
|
||||
|
@ -135,7 +141,11 @@ public class RealTimeGetComponent extends SearchComponent
|
|||
int docid = searcher.getFirstMatch(new Term(idField.getName(), idBytes));
|
||||
if (docid < 0) continue;
|
||||
Document luceneDocument = searcher.doc(docid);
|
||||
docList.add(toSolrDoc(luceneDocument, req.getSchema()));
|
||||
SolrDocument doc = toSolrDoc(luceneDocument, req.getSchema());
|
||||
if( transformer != null ) {
|
||||
transformer.transform(doc, docid);
|
||||
}
|
||||
docList.add(doc);
|
||||
}
|
||||
|
||||
} finally {
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
|
|||
import org.apache.solr.client.solrj.impl.XMLResponseParser;
|
||||
import org.apache.solr.client.solrj.request.DirectXmlRequest;
|
||||
import org.apache.solr.client.solrj.request.LukeRequest;
|
||||
import org.apache.solr.client.solrj.request.QueryRequest;
|
||||
import org.apache.solr.client.solrj.request.SolrPing;
|
||||
import org.apache.solr.client.solrj.response.FieldStatsInfo;
|
||||
import org.apache.solr.client.solrj.request.UpdateRequest;
|
||||
|
@ -990,4 +991,43 @@ abstract public class SolrExampleTests extends SolrJettyTestBase
|
|||
QueryResponse rsp = server.query( query );
|
||||
assertEquals(1, rsp.getResults().getNumFound());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testRealtimeGet() throws Exception
|
||||
{
|
||||
SolrServer server = getSolrServer();
|
||||
|
||||
// Empty the database...
|
||||
server.deleteByQuery( "*:*" );// delete everything!
|
||||
|
||||
// Now add something...
|
||||
SolrInputDocument doc = new SolrInputDocument();
|
||||
doc.addField( "id", "DOCID", 1.0f );
|
||||
doc.addField( "name", "hello", 1.0f );
|
||||
server.add( doc );
|
||||
server.commit(); // Since the transaction log is disabled in the example, we need to commit
|
||||
|
||||
SolrQuery q = new SolrQuery();
|
||||
q.setQueryType("/get");
|
||||
q.set("id", "DOCID");
|
||||
q.set("fl", "id,name,aaa:[value v=aaa]");
|
||||
|
||||
// First Try with the BinaryResponseParser
|
||||
QueryRequest req = new QueryRequest( q );
|
||||
req.setResponseParser(new BinaryResponseParser());
|
||||
QueryResponse rsp = req.process(server);
|
||||
SolrDocument out = (SolrDocument)rsp.getResponse().get("doc");
|
||||
assertEquals("DOCID", out.get("id"));
|
||||
assertEquals("hello", out.get("name"));
|
||||
assertEquals("aaa", out.get("aaa"));
|
||||
|
||||
// Then with the XMLResponseParser
|
||||
req.setResponseParser(new XMLResponseParser());
|
||||
rsp = req.process(server);
|
||||
out = (SolrDocument)rsp.getResponse().get("doc");
|
||||
assertEquals("DOCID", out.get("id"));
|
||||
assertEquals("hello", out.get("name"));
|
||||
assertEquals("aaa", out.get("aaa"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue