lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject svn commit: r1183177 - in /lucene/dev/trunk/solr: core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
Date Fri, 14 Oct 2011 00:33:54 GMT
Author: ryan
Date: Fri Oct 14 00:33:54 2011
New Revision: 1183177

URL: http://svn.apache.org/viewvc?rev=1183177&view=rev
Log:
SOLR-2830: apply transformers in RealTimeGetComponent

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
    lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java?rev=1183177&r1=1183176&r2=1183177&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
(original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/RealTimeGetComponent.java
Fri Oct 14 00:33:54 2011
@@ -29,6 +29,7 @@ import org.apache.solr.common.params.Sol
 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 extend
 
     RefCounted<SolrIndexSearcher> searcherHolder = null;
 
+    DocTransformer transformer = rsp.getReturnFields().getTransformer();
    try {
      SolrIndexSearcher searcher = null;
 
@@ -115,7 +117,11 @@ public class RealTimeGetComponent extend
            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 extend
        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 {

Modified: lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java?rev=1183177&r1=1183176&r2=1183177&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
(original)
+++ lucene/dev/trunk/solr/solrj/src/test/org/apache/solr/client/solrj/SolrExampleTests.java
Fri Oct 14 00:33:54 2011
@@ -33,6 +33,7 @@ import org.apache.solr.client.solrj.impl
 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 e
     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"));
+  }
 }



Mime
View raw message