SOLR-2064 SOLR-2065 SOLR-236: support highlighting and debugging with search grouping

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@997870 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-09-16 18:16:11 +00:00
parent 2d02e21ed3
commit c0ca131db5
4 changed files with 50 additions and 8 deletions

View File

@ -244,10 +244,15 @@ public class QueryComponent extends SearchComponent
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) {

View File

@ -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;
@ -899,6 +898,7 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
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 IndexSearcher implements SolrInfoMBean {
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 IndexSearcher implements SolrInfoMBean {
// 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 IndexSearcher implements SolrInfoMBean {
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 IndexSearcher implements SolrInfoMBean {
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 IndexSearcher implements SolrInfoMBean {
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);
}
}
/**

View File

@ -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;

View File

@ -223,6 +223,20 @@ public class TestGroupingSearch extends SolrTestCaseJ4 {
);
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:"
);
};