Author: yonik
Date: Tue Jun 17 06:37:55 2008
New Revision: 668661

URL: http://svn.apache.org/viewvc?rev=668661&view=rev
Log:
SOLR-486: make javabin the default for SolrJ

Modified:
    lucene/solr/trunk/CHANGES.txt
    
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java
    lucene/solr/trunk/src/java/org/apache/solr/common/util/NamedListCodec.java
    lucene/solr/trunk/src/java/org/apache/solr/request/BinaryResponseWriter.java
    lucene/solr/trunk/src/test/org/apache/solr/TestDistributedSearch.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=668661&r1=668660&r2=668661&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Tue Jun 17 06:37:55 2008
@@ -258,8 +258,9 @@
     and QueryResponseTest (Shalin Shekhar Mangar via gsingers)
 
 44. SOLR-486: Binary response format, faster and smaller
-    than XML and  JSON response formats (use wt=javabin).
-    BinaryResponseParser for utilizing the binary format via SolrJ.
+    than XML and JSON response formats (use wt=javabin).
+    BinaryResponseParser for utilizing the binary format via SolrJ
+    and is now the default.
     (Noble Paul, yonik)
 
 45. SOLR-521: StopFilterFactory support for "enablePositionIncrements"

Modified: 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java?rev=668661&r1=668660&r2=668661&view=diff
==============================================================================
--- 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java
 (original)
+++ 
lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java
 Tue Jun 17 06:37:55 2008
@@ -85,7 +85,7 @@
    * will use this SolrServer.
    */
   public CommonsHttpSolrServer(String solrServerUrl, HttpClient httpClient) 
throws MalformedURLException {
-    this(new URL(solrServerUrl), httpClient, new XMLResponseParser());
+    this(new URL(solrServerUrl), httpClient, new BinaryResponseParser());
   }
 
   public CommonsHttpSolrServer(String solrServerUrl, HttpClient httpClient, 
ResponseParser parser) throws MalformedURLException {
@@ -100,7 +100,7 @@
    */
   public CommonsHttpSolrServer(URL baseURL) 
   {
-    this(baseURL, null, new XMLResponseParser());
+    this(baseURL, null, new BinaryResponseParser());
   }
 
   public CommonsHttpSolrServer(URL baseURL, HttpClient client){

Modified: 
lucene/solr/trunk/src/java/org/apache/solr/common/util/NamedListCodec.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/common/util/NamedListCodec.java?rev=668661&r1=668660&r2=668661&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/common/util/NamedListCodec.java 
(original)
+++ lucene/solr/trunk/src/java/org/apache/solr/common/util/NamedListCodec.java 
Tue Jun 17 06:37:55 2008
@@ -57,7 +57,7 @@
           ARR =       (byte)(4 << 5), //
           ORDERED_MAP=(byte)(5 << 5), // SimpleOrderedMap (a NamedList 
subclass, and more common)
           NAMED_LST = (byte)(6 << 5), // NamedList
-          RESERVED2 = (byte)(7 << 5);
+          EXTERN_STRING = (byte)(7 << 5);
 
 
   private byte VERSION = 1;
@@ -149,6 +149,7 @@
       case ARR >>> 5         : return readArray(dis);
       case ORDERED_MAP >>> 5 : return readOrderedMap(dis);
       case NAMED_LST >>> 5   : return readNamedList(dis);
+      case EXTERN_STRING >>> 5   : return readExternString(dis);
     }
 
     switch(tagByte){
@@ -190,7 +191,19 @@
       return true;
     }
     if (val instanceof SolrDocument) {
-      writeSolrDocument((SolrDocument) val);
+      //this needs special treatment to know which fields are to be written
+      if(resolver == null){
+        writeSolrDocument((SolrDocument) val);
+      }else {
+        Object retVal = resolver.resolve(val, this);
+        if(retVal != null) {
+          if (retVal instanceof SolrDocument) {
+            writeSolrDocument((SolrDocument) retVal);
+          } else {
+            writeVal(retVal);
+          }
+        }
+      }
       return true;
     }
     if (val instanceof Iterator) {
@@ -234,13 +247,26 @@
   }
 
   public void writeSolrDocument(SolrDocument doc) throws IOException {
+    writeSolrDocument(doc, null);
+  }
+  public void writeSolrDocument(SolrDocument doc, Set<String> fields) throws 
IOException {
+    int count = 0;
+    if (fields == null) {
+      count = doc.getFieldNames().size();
+    } else {
+      for (Map.Entry<String, Object> entry : doc) {
+        if (fields.contains(entry.getKey())) count++;
+      }
+    }
     writeTag(SOLRDOC);
-    writeTag(ORDERED_MAP, doc.getFieldNames().size());
+    writeTag(ORDERED_MAP, count);
     for (Map.Entry<String, Object> entry : doc) {
-      String name = entry.getKey();
-      writeStr(name);
-      Object val = entry.getValue();
-      writeVal(val);
+      if (fields == null || fields.contains(entry.getKey())) {
+        String name = entry.getKey();
+        writeExternString(name);
+        Object val = entry.getValue();
+        writeVal(val);
+      }
     }
   }
 
@@ -557,6 +583,36 @@
     }
   }
 
+  private int stringsCount  =  0;
+  private Map<String,Integer> stringsMap;
+  private List<String > stringsList;
+  public void writeExternString(String s) throws IOException {
+    if(s == null) {
+      writeTag(NULL) ;
+      return;
+    }
+    Integer idx = stringsMap == null ? null : stringsMap.get(s);
+    if(idx == null) idx =0;
+    writeTag(EXTERN_STRING,idx);
+    if(idx == 0){
+      writeStr(s);
+      if(stringsMap == null) stringsMap = new HashMap<String, Integer>();
+      stringsMap.put(s,++stringsCount);
+    }
+
+  }
+  public String  readExternString(FastInputStream fis) throws IOException {
+    int idx = readSize(fis);
+    if (idx != 0) {// idx != 0 is the index of the extern string
+      return stringsList.get(idx-1);
+    } else {// idx == 0 means it has a string value
+      String s = (String) readVal(fis);
+      if(stringsList == null ) stringsList = new ArrayList<String>();
+      stringsList.add(s);
+      return s;
+    }
+  }
+
 
   public static interface ObjectResolver{
     public Object resolve(Object o, NamedListCodec codec) throws IOException;

Modified: 
lucene/solr/trunk/src/java/org/apache/solr/request/BinaryResponseWriter.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/BinaryResponseWriter.java?rev=668661&r1=668660&r2=668661&view=diff
==============================================================================
--- 
lucene/solr/trunk/src/java/org/apache/solr/request/BinaryResponseWriter.java 
(original)
+++ 
lucene/solr/trunk/src/java/org/apache/solr/request/BinaryResponseWriter.java 
Tue Jun 17 06:37:55 2008
@@ -70,7 +70,7 @@
       this.schema = req.getSchema();
       this.searcher = req.getSearcher();
       this.includeScore = returnFields!=null && returnFields.contains("score");
-      
+
       if (returnFields != null) {
        if (returnFields.size() == 0 || (returnFields.size() == 1 && 
includeScore) || returnFields.contains("*")) {
           returnFields = null;  // null means return all stored fields
@@ -84,7 +84,11 @@
         writeDocList((DocList) o, codec);
         return null; // null means we completely handled it
       }
-
+      if (o instanceof SolrDocument) {
+        SolrDocument solrDocument = (SolrDocument) o;
+        codec.writeSolrDocument(solrDocument,returnFields);
+        return null;
+      }
       if (o instanceof Document) {
         return getDoc((Document) o);
       }

Modified: lucene/solr/trunk/src/test/org/apache/solr/TestDistributedSearch.java
URL: 
http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/org/apache/solr/TestDistributedSearch.java?rev=668661&r1=668660&r2=668661&view=diff
==============================================================================
--- lucene/solr/trunk/src/test/org/apache/solr/TestDistributedSearch.java 
(original)
+++ lucene/solr/trunk/src/test/org/apache/solr/TestDistributedSearch.java Tue 
Jun 17 06:37:55 2008
@@ -305,8 +305,8 @@
       cmp = compare(a.getMaxScore(), b.getMaxScore(), 0, handle);
       if (cmp != null) return ".maxScore" + cmp;
     } else {
-      if (a.getMaxScore() != null) {
-        if (b.getMaxScore() == null) {
+      if (b.getMaxScore() != null) {
+        if (a.getMaxScore() == null) {
           return ".maxScore missing";
         }
       }
@@ -453,18 +453,21 @@
 
     // these queries should be exactly ordered and scores should exactly match
     query("q","*:*", "sort",i1+" desc");
-    query("q","{!func}"+i1);
+    handle.put("maxScore", SKIPVAL);
+    query("q","{!func}"+i1);// does not expect maxScore. So if it comes 
,ignore it. NamedListCodec.writeSolrDocumentList()
+    //is agnostic of request params.
+    handle.remove("maxScore");
     query("q","{!func}"+i1, "fl","*,score");  // even scores should match 
exactly here
 
     handle.put("highlighting", UNORDERED);
     handle.put("response", UNORDERED);
 
+    handle.put("maxScore", SKIPVAL);
     query("q","quick");
     query("q","all","fl","id","start","0");
     query("q","all","fl","foofoofoo","start","0");  // no fields in returned 
docs
     query("q","all","fl","id","start","100");
 
-    handle.put("maxScore", SKIPVAL);
     handle.put("score", SKIPVAL);
     query("q","quick","fl","*,score");
     query("q","all","fl","*,score","start","1");


Reply via email to