lucene-solr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gsing...@apache.org
Subject svn commit: r638357 - in /lucene/solr/trunk: ./ client/java/solrj/src/org/apache/solr/client/solrj/response/ client/java/solrj/test/org/apache/solr/client/solrj/response/ src/test/test-files/
Date Tue, 18 Mar 2008 13:12:29 GMT
Author: gsingers
Date: Tue Mar 18 06:12:27 2008
New Revision: 638357

URL: http://svn.apache.org/viewvc?rev=638357&view=rev
Log:
SOLR-497: Added date faceting to QueryResponse

Added:
    lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/response/
    lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/response/QueryResponseTest.java
  (with props)
    lucene/solr/trunk/src/test/test-files/sampleDateFacetResponse.xml   (with props)
Modified:
    lucene/solr/trunk/CHANGES.txt
    lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/FacetField.java
    lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/QueryResponse.java

Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=638357&r1=638356&r2=638357&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Tue Mar 18 06:12:27 2008
@@ -214,6 +214,8 @@
 
 42. SOLR-494: Added cool admin Ajaxed schema explorer.
     (Greg Ludington via ehatcher)
+
+43. SOLR-497: Added date faceting to the QueryResponse in SolrJ and QueryResponseTest (Shalin
Shekhar Mangar via gsingers)
     
 Changes in runtime behavior
 

Modified: lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/FacetField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/FacetField.java?rev=638357&r1=638356&r2=638357&view=diff
==============================================================================
--- lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/FacetField.java
(original)
+++ lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/FacetField.java
Tue Mar 18 06:12:27 2008
@@ -19,6 +19,7 @@
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 import org.apache.solr.client.solrj.util.ClientUtils;
@@ -86,10 +87,36 @@
    
    private String      _name   = null;
    private List<Count> _values = null;
+   private String _gap = null;
+   private Date _end = null;
    
    public FacetField( final String n )
    {
      _name = n;
+   }
+   
+   public FacetField(String name, String gap, Date end) {
+     _name = name;
+     _gap = gap;
+     _end = end;
+   }
+   
+   /**
+    * Date Gap Facet parameter
+    * 
+    * @return the value specified for facet.date.gap
+    */
+   public String getGap()   {
+     return _gap;
+   }
+   
+   /**
+    * Date End Facet parameter
+    * 
+    * @return the value specified for facet.date.end
+    */
+   public Date getEnd() {
+     return _end;
    }
 
    /**

Modified: lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/QueryResponse.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/QueryResponse.java?rev=638357&r1=638356&r2=638357&view=diff
==============================================================================
--- lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/QueryResponse.java
(original)
+++ lucene/solr/trunk/client/java/solrj/src/org/apache/solr/client/solrj/response/QueryResponse.java
Tue Mar 18 06:12:27 2008
@@ -18,6 +18,7 @@
 package org.apache.solr.client.solrj.response;
 
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -45,6 +46,7 @@
   private Map<String,Integer> _facetQuery = null;
   private List<FacetField> _facetFields = null;
   private List<FacetField> _limitingFacets = null;
+  private List<FacetField> _facetDates = null;
   
   // Highlight Info
   private Map<String,Map<String,List<String>>> _highlighting = null;
@@ -143,6 +145,30 @@
         }
       }
     }
+    
+    //Parse date facets
+    NamedList<NamedList<Object>> df = (NamedList<NamedList<Object>>)
info.get("facet_dates");
+    if (df != null) {
+      // System.out.println(df);
+      _facetDates = new ArrayList<FacetField>( df.size() );
+      for (Map.Entry<String, NamedList<Object>> facet : df) {
+        // System.out.println("Key: " + facet.getKey() + " Value: " + facet.getValue());
+        NamedList<Object> values = facet.getValue();
+        String gap = (String) values.get("gap");
+        Date end = (Date) values.get("end");
+        FacetField f = new FacetField(facet.getKey(), gap, end);
+        
+        for (Map.Entry<String, Object> entry : values)   {
+          try {
+            f.add(entry.getKey(), Long.parseLong(entry.getValue().toString()));
+          } catch (NumberFormatException e) {
+            //Ignore for non-number responses which are already handled above
+          }
+        }
+        
+        _facetDates.add(f);
+      }
+    }
   }
 
   //------------------------------------------------------
@@ -186,6 +212,10 @@
     return _facetFields;
   }
   
+  public List<FacetField> getFacetDates()   {
+    return _facetDates;
+  }
+  
   /** get 
    * 
    * @param name the name of the 
@@ -196,6 +226,15 @@
     for (FacetField f : _facetFields) {
       if (f.getName().equals(name)) return f;
     }
+    return null;
+  }
+  
+  public FacetField getFacetDate(String name)   {
+    if (_facetDates == null)
+      return null;
+    for (FacetField f : _facetDates)
+      if (f.getName().equals(name))
+        return f;
     return null;
   }
   

Added: lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/response/QueryResponseTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/response/QueryResponseTest.java?rev=638357&view=auto
==============================================================================
--- lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/response/QueryResponseTest.java
(added)
+++ lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/response/QueryResponseTest.java
Tue Mar 18 06:12:27 2008
@@ -0,0 +1,57 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.client.solrj.response;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.FileReader;
+
+import junit.framework.Assert;
+
+import org.apache.solr.client.solrj.impl.XMLResponseParser;
+import org.apache.solr.common.util.NamedList;
+import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Simple test for Date facet support in QueryResponse
+ * 
+ * @since solr 1.3
+ */
+public class QueryResponseTest {
+  @Test
+  public void testDateFacets() throws Exception   {
+    XMLResponseParser parser = new XMLResponseParser();
+    FileReader in = new FileReader("sampleDateFacetResponse.xml");
+    assertTrue("in is null and it shouldn't be", in != null);
+    NamedList<Object> response = parser.processResponse(in);
+    in.close();
+    
+    QueryResponse qr = new QueryResponse(response);
+    Assert.assertNotNull(qr);
+    
+    Assert.assertNotNull(qr.getFacetDates());
+    
+    for (FacetField f : qr.getFacetDates()) {
+      Assert.assertNotNull(f);
+      System.out.println(f.toString());
+      System.out.println("GAP: " + f.getGap());
+      System.out.println("END: " + f.getEnd());
+    }
+  }
+}

Propchange: lucene/solr/trunk/client/java/solrj/test/org/apache/solr/client/solrj/response/QueryResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: lucene/solr/trunk/src/test/test-files/sampleDateFacetResponse.xml
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/test/test-files/sampleDateFacetResponse.xml?rev=638357&view=auto
==============================================================================
--- lucene/solr/trunk/src/test/test-files/sampleDateFacetResponse.xml (added)
+++ lucene/solr/trunk/src/test/test-files/sampleDateFacetResponse.xml Tue Mar 18 06:12:27
2008
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<response>
+<lst name="responseHeader"><int name="status">0</int><int name="QTime">0</int><lst
name="params"><str name="facet.date.start">NOW/DAY-5DAYS</str><str name="facet">true</str><str
name="facet.date.hardend">true</str><str name="q">*:*</str><arr name="facet.date"><str>timestamp</str><str>timestamp2</str></arr><str
name="facet.date.gap">+1DAY</str><str name="facet.date.other">ALL</str><str
name="facet.date.end">NOW/DAY+1DAY</str><str name="rows">0</str></lst></lst><result
name="response" numFound="16" start="0"/><lst name="facet_counts"><lst name="facet_queries"/><lst
name="facet_fields"/><lst name="facet_dates"><lst name="timestamp"><int
name="2008-03-06T00:00:00.000Z">0</int><int name="2008-03-07T00:00:00.000Z">0</int><int
name="2008-03-08T00:00:00.000Z">0</int><int name="2008-03-09T00:00:00.000Z">0</int><int
name="2008-03-10T00:00:00.000Z">0</int><int name="2008-03-11T00:00:00.000Z">0</int><str
name="gap">+1DAY</str><date name="end">2008-03-12T00:00:00Z</date><int
name="before
 ">16</int><int name="after">0</int><int name="between">0</int></lst><lst
name="timestamp2"><int name="2008-03-06T00:00:00.000Z">0</int><int name="2008-03-07T00:00:00.000Z">0</int><int
name="2008-03-08T00:00:00.000Z">0</int><int name="2008-03-09T00:00:00.000Z">0</int><int
name="2008-03-10T00:00:00.000Z">0</int><int name="2008-03-11T00:00:00.000Z">0</int><str
name="gap">+1DAY</str><date name="end">2008-03-12T00:00:00Z</date><int
name="before">0</int><int name="after">0</int><int name="between">0</int></lst></lst></lst>
+</response>

Propchange: lucene/solr/trunk/src/test/test-files/sampleDateFacetResponse.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message