lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r997870 - in /lucene/dev/trunk/solr/src: java/org/apache/solr/handler/component/QueryComponent.java java/org/apache/solr/search/SolrIndexSearcher.java test/org/apache/solr/JSONTestUtil.java test/org/apache/solr/TestGroupingSearch.java
Date Thu, 16 Sep 2010 18:16:12 GMT
Author: yonik
Date: Thu Sep 16 18:16:11 2010
New Revision: 997870

URL: http://svn.apache.org/viewvc?rev=997870&view=rev
Log:
SOLR-2064 SOLR-2065 SOLR-236: support highlighting and debugging with search grouping

Modified:
    lucene/dev/trunk/solr/src/java/org/apache/solr/handler/component/QueryComponent.java
    lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/JSONTestUtil.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/TestGroupingSearch.java

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/handler/component/QueryComponent.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/handler/component/QueryComponent.java?rev=997870&r1=997869&r2=997870&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/handler/component/QueryComponent.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/handler/component/QueryComponent.java Thu
Sep 16 18:16:11 2010
@@ -244,10 +244,15 @@ public class QueryComponent extends Sear
           cmd.groupCommands = null;
 
         if (cmd.groupCommands != null) {
+          if (rb.doHighlights || rb.isDebug()) {
+            // we need a single list of the returned docs
+            cmd.setFlags(cmd.getFlags() | SolrIndexSearcher.GET_DOCLIST);
+          }
+
           searcher.search(result,cmd);
           rb.setResult( result );
           rsp.add("grouped", result.groupedResults);
-          // TODO: get "hits" a different way
+          // TODO: get "hits" a different way to log
           return;
         }
       } catch (ParseException e) {

Modified: lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java?rev=997870&r1=997869&r2=997870&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java (original)
+++ lucene/dev/trunk/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java Thu Sep 16
18:16:11 2010
@@ -38,7 +38,6 @@ import java.io.IOException;
 import java.net.URL;
 import java.util.*;
 
-import org.apache.solr.search.function.DocValues;
 import org.apache.solr.search.function.ValueSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -898,7 +897,8 @@ public class SolrIndexSearcher extends I
   private static final int NO_CHECK_QCACHE       = 0x80000000;
   private static final int GET_DOCSET            = 0x40000000;
   private static final int NO_CHECK_FILTERCACHE  = 0x20000000;
-
+  
+  public static final int GET_DOCLIST           =        0x02; // get the documents actually
returned in a response
   public static final int GET_SCORES             =       0x01;
 
 
@@ -913,6 +913,7 @@ public class SolrIndexSearcher extends I
 
     boolean needScores = (cmd.getFlags() & GET_SCORES) != 0;
     boolean getDocSet = (cmd.getFlags() & GET_DOCSET) != 0;
+    boolean getDocList = (cmd.getFlags() & GET_DOCLIST) != 0; // doclist needed for debugging
or highlighting
     Query query = QueryUtils.makeQueryable(cmd.getQuery());
 
     final Filter luceneFilter = filter==null ? null : filter.getTopFilter();
@@ -977,6 +978,9 @@ public class SolrIndexSearcher extends I
     // TODO: optionally cache docs and feed them back through rather than re-searching
     search(query, luceneFilter, MultiCollector.wrap(phase2Collectors));
 
+    Set<Integer> idSet = new LinkedHashSet<Integer>();  // used for tracking
unique docs when we need a doclist
+    int maxMatches = 0;
+    float maxScore = Float.NEGATIVE_INFINITY;
 
     NamedList grouped = new SimpleOrderedMap();
     for (int cmdnum=0; cmdnum<cmd.groupCommands.size(); cmdnum++) {
@@ -990,7 +994,9 @@ public class SolrIndexSearcher extends I
       NamedList groupResult = new SimpleOrderedMap();
       grouped.add(groupCommand.key, groupResult);  // grouped={ key={
 
-      groupResult.add("matches", collector.getMatches());
+      int this_matches = collector.getMatches();
+      groupResult.add("matches", this_matches);
+      maxMatches = Math.max(maxMatches, this_matches);
 
       List groupList = new ArrayList();
       groupResult.add("groups", groupList);        // grouped={ key={ groups=[
@@ -1014,9 +1020,15 @@ public class SolrIndexSearcher extends I
             scores[i] = topDocs.scoreDocs[i].score;
         }
 
-        DocSlice docs = new DocSlice(0, ids.length, ids, scores, topDocs.totalHits, topDocs.getMaxScore());
+        float score = topDocs.getMaxScore();
+        maxScore = Math.max(maxScore, score);
+        DocSlice docs = new DocSlice(0, ids.length, ids, scores, topDocs.totalHits, score);
         nl.add("doclist", docs);
 
+        if (getDocList) {
+          for (int id : ids)
+            idSet.add(id);
+        }
 
         /*** values from stage 1
          DocSlice docs = new DocSlice(0, 1, new int[] {group.topDoc}, null, 1, 0);
@@ -1030,9 +1042,20 @@ public class SolrIndexSearcher extends I
          groupResult.add(nl);
          ***/
       }
-      qr.groupedResults = grouped;
+    }
 
+    qr.groupedResults = grouped;    
+
+    if (getDocList) {
+      int sz = idSet.size();
+      int[] ids = new int[sz];
+      int idx = 0;
+      for (int val : idSet) {
+        ids[idx++] = val;
+      }
+      qr.docListAndSet.docList = new DocSlice(0, sz, ids, null, maxMatches, maxScore);
     }
+
   }
 
   /**

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/JSONTestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/JSONTestUtil.java?rev=997870&r1=997869&r2=997870&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/JSONTestUtil.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/JSONTestUtil.java Thu Sep 16 18:16:11 2010
@@ -230,7 +230,7 @@ class CollectionTester {
           break;
         }
 
-        if (entry.getKey().equals(expectedKey)) {
+        if (!entry.getKey().equals(expectedKey)) {
           popPath();          
           setErr("expected key '" + expectedKey + "' instead of '"+entry.getKey()+"' in ordered
map");
           return false;

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/TestGroupingSearch.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/TestGroupingSearch.java?rev=997870&r1=997869&r2=997870&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/TestGroupingSearch.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/TestGroupingSearch.java Thu Sep 16 18:16:11
2010
@@ -223,6 +223,20 @@ public class TestGroupingSearch extends 
     );
     purgeFieldCache(FieldCache.DEFAULT);   // avoid FC insanity
 
+    // test that grouping works with highlighting
+    assertJQ(req("fq",filt,  "q","{!func}"+f2, "group","true", "group.field",f, "fl","id"
+                 ,"hl","true", "hl.fl",f)
+      ,"/grouped/foo_i/matches:10:"
+      ,"/highlighting:{'_ORDERED_':'', '8':{},'3':{},'4':{},'1':{},'2':{}}"
+    );
+
+    // test that grouping works with debugging
+    assertJQ(req("fq",filt,  "q","{!func}"+f2, "group","true", "group.field",f, "fl","id"
+                 ,"debugQuery","true")
+      ,"/grouped/foo_i/matches:10:"
+      ,"/debug/explain/8:"
+      ,"/debug/explain/2:"
+    );
   };
 
 



Mime
View raw message