SOLR-652 -- fixing highlighting error when q.alt="*:* and no q is sent

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@679477 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2008-07-24 18:07:01 +00:00
parent c0f037cd1f
commit c16ddbb9b9
2 changed files with 25 additions and 12 deletions

View File

@ -17,6 +17,7 @@
package org.apache.solr.handler.component;
import org.apache.lucene.search.Query;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.params.CommonParams;
import org.apache.solr.common.params.HighlightParams;
@ -62,26 +63,32 @@ public class HighlightComponent extends SearchComponent
defaultHighlightFields = params.getParams(CommonParams.DF);
}
if(rb.getHighlightQuery()==null) {
Query highlightQuery = rb.getHighlightQuery();
if(highlightQuery==null) {
if (rb.getQparser() != null) {
try {
rb.setHighlightQuery( rb.getQparser().getHighlightQuery() );
highlightQuery = rb.getQparser().getHighlightQuery();
rb.setHighlightQuery( highlightQuery );
} catch (Exception e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
} else {
rb.setHighlightQuery( rb.getQuery() );
highlightQuery = rb.getQuery();
rb.setHighlightQuery( highlightQuery );
}
}
NamedList sumData = highlighter.doHighlighting(
rb.getResults().docList,
rb.getHighlightQuery().rewrite(req.getSearcher().getReader()),
req, defaultHighlightFields );
// No highlighting if there is no query -- consider q.alt="*:*
if( highlightQuery != null ) {
NamedList sumData = highlighter.doHighlighting(
rb.getResults().docList,
highlightQuery.rewrite(req.getSearcher().getReader()),
req, defaultHighlightFields );
if(sumData != null) {
// TODO ???? add this directly to the response?
rb.rsp.add("highlighting", sumData);
if(sumData != null) {
// TODO ???? add this directly to the response?
rb.rsp.add("highlighting", sumData);
}
}
}
}

View File

@ -148,6 +148,7 @@ public class HighlighterTest extends AbstractSolrTestCase {
args.put("hl", "true");
args.put("hl.fl", "tv_text");
args.put("qf", "tv_text");
args.put("q.alt", "*:*");
TestHarness.LocalRequestFactory sumLRF = h.getRequestFactory(
"dismax",0,200,args);
@ -160,6 +161,11 @@ public class HighlighterTest extends AbstractSolrTestCase {
"//lst[@name='1']/arr[@name='tv_text']/str"
);
// try the same thing without a q param
assertQ("Should not explode...", // q.alt should return everything
sumLRF.makeRequest( new String[] { null } ), // empty query
"//result[@numFound='1']"
);
}