lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gsing...@apache.org
Subject svn commit: r1387259 - in /lucene/dev/trunk/solr/core/src: java/org/apache/solr/handler/component/ResponseLogComponent.java test/org/apache/solr/handler/component/ResponseLogComponentTest.java
Date Tue, 18 Sep 2012 17:04:31 GMT
Author: gsingers
Date: Tue Sep 18 17:04:31 2012
New Revision: 1387259

URL: http://svn.apache.org/viewvc?rev=1387259&view=rev
Log:
SOLR-3825: use unique key

Modified:
    lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/ResponseLogComponent.java
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/ResponseLogComponentTest.java

Modified: lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/ResponseLogComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/ResponseLogComponent.java?rev=1387259&r1=1387258&r2=1387259&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/ResponseLogComponent.java
(original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/handler/component/ResponseLogComponent.java
Tue Sep 18 17:04:31 2012
@@ -17,11 +17,16 @@ package org.apache.solr.handler.componen
  */
 
 import java.io.IOException;
+import java.util.Collections;
+import java.util.Set;
 
+import org.apache.lucene.index.StoredFieldVisitor;
 import org.apache.solr.common.params.SolrParams;
 import org.apache.solr.response.ResultContext;
+import org.apache.solr.schema.IndexSchema;
 import org.apache.solr.search.DocIterator;
 import org.apache.solr.search.DocList;
+import org.apache.solr.search.SolrIndexSearcher;
 
 /**
  * Adds to the log file the document IDs that are sent in the query response.
@@ -62,32 +67,45 @@ public class ResponseLogComponent extend
     SolrParams params = rb.req.getParams();
     if (!params.getBool(COMPONENT_NAME, false)) return;
     
+    IndexSchema schema = rb.req.getSchema();
+    if (schema.getUniqueKeyField() == null) return;
+
     ResultContext rc = (ResultContext) rb.rsp.getValues().get("response");
+    SolrIndexSearcher searcher = rb.req.getSearcher();    
+    
     if (rc.docs.hasScores()) {
-      processScores(rb, rc.docs);
+      processScores(rb, rc.docs, schema, searcher);
     } else {
-      processIds(rb, rc.docs);
+      processIds(rb, rc.docs, schema, searcher);
     }
   }
 
-  protected void processIds(ResponseBuilder rb, DocList dl) {
+  protected void processIds(ResponseBuilder rb, DocList dl, IndexSchema schema,
+      SolrIndexSearcher searcher) throws IOException {
+    
     StringBuilder sb = new StringBuilder();
+
+    Set<String> fields = Collections.singleton(schema.getUniqueKeyField().getName());
     for(DocIterator iter = dl.iterator(); iter.hasNext();) {
-        sb.append(iter.nextDoc())
-          .append(',');
+
+      sb.append(schema.printableUniqueKey(searcher.doc(iter.nextDoc(), fields)))
+        .append(',');
     }
     if (sb.length() > 0) {
       rb.rsp.addToLog("responseLog", sb.substring(0, sb.length() - 1));
     }  
   }
   
-  protected void processScores(ResponseBuilder rb, DocList dl) {
+  protected void processScores(ResponseBuilder rb, DocList dl, IndexSchema schema,
+      SolrIndexSearcher searcher) throws IOException {
+    
     StringBuilder sb = new StringBuilder();
+    Set<String> fields = Collections.singleton(schema.getUniqueKeyField().getName());
     for(DocIterator iter = dl.iterator(); iter.hasNext();) {
-        sb.append(iter.nextDoc())
-          .append(':')
-          .append(iter.score())
-          .append(',');
+      sb.append(schema.printableUniqueKey(searcher.doc(iter.nextDoc(), fields)))
+        .append(':')
+        .append(iter.score())
+        .append(',');
     }
     if (sb.length() > 0) {
       rb.rsp.addToLog("responseLog", sb.substring(0, sb.length() - 1));
@@ -104,4 +122,4 @@ public class ResponseLogComponent extend
     return "$URL$";
   }
   
-}
\ No newline at end of file
+}

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/ResponseLogComponentTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/ResponseLogComponentTest.java?rev=1387259&r1=1387258&r2=1387259&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/ResponseLogComponentTest.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/handler/component/ResponseLogComponentTest.java
Tue Sep 18 17:04:31 2012
@@ -30,7 +30,7 @@ public class ResponseLogComponentTest ex
   public static void beforeTest() throws Exception {
     initCore("solrconfig-response-log-component.xml","schema12.xml");
     assertNull(h.validateUpdate(adoc("id", "1", "subject", "aa")));
-    assertNull(h.validateUpdate(adoc("id", "2", "subject", "aa")));
+    assertNull(h.validateUpdate(adoc("id", "two", "subject", "aa")));
     assertNull(h.validateUpdate(adoc("id", "3", "subject", "aa")));
     assertU(commit());
   }
@@ -46,11 +46,9 @@ public class ResponseLogComponentTest ex
       NamedList<Object> entries = qr.getToLog();
       String responseLog = (String) entries.get("responseLog");
       assertNotNull(responseLog);
-      assertTrue(responseLog.matches("\\d+,\\d+"));
+      assertTrue(responseLog.matches("\\w+,\\w+"));
     } finally {
-      if (req != null) {
-        req.close();
-      }
+      req.close();
     }
   }
 
@@ -65,11 +63,9 @@ public class ResponseLogComponentTest ex
       NamedList<Object> entries = qr.getToLog();
       String responseLog = (String) entries.get("responseLog");
       assertNotNull(responseLog);
-      assertTrue(responseLog.matches("\\d+:\\d+\\.\\d+,\\d+:\\d+\\.\\d+"));
+      assertTrue(responseLog.matches("\\w+:\\d+\\.\\d+,\\w+:\\d+\\.\\d+"));
     } finally {
-      if (req != null) {
-        req.close();
-      }
+      req.close();
     }
   }
   
@@ -85,9 +81,7 @@ public class ResponseLogComponentTest ex
       String responseLog = (String) entries.get("responseLog");
       assertNull(responseLog);
     } finally {
-      if (req != null) {
-        req.close();
-      }
+      req.close();
     }    
   }
 }



Mime
View raw message