mirror of https://github.com/apache/lucene.git
SOLR-14939: JSON range faceting to support cache=false parameter (#1992)
This commit is contained in:
parent
6f56a3cd73
commit
0b5003cfed
|
@ -262,6 +262,7 @@ Bug Fixes
|
|||
* SOLR-12182: Don't persist base_url in ZK as the URL scheme is variable, compute from node_name instead when reading
|
||||
state back from ZK. (Timothy Potter)
|
||||
|
||||
* SOLR-14939: JSON range faceting to support cache=false parameter. (Christine Poerschke, Mike Drob)
|
||||
|
||||
Other Changes
|
||||
---------------------
|
||||
|
|
|
@ -38,6 +38,7 @@ public class FacetContext {
|
|||
Query filter; // TODO: keep track of as a DocSet or as a Query?
|
||||
DocSet base;
|
||||
FacetContext parent;
|
||||
boolean cache = true;
|
||||
int flags;
|
||||
FacetDebugInfo debugInfo;
|
||||
|
||||
|
@ -100,6 +101,7 @@ public class FacetContext {
|
|||
ctx.filter = filter;
|
||||
|
||||
// carry over from parent
|
||||
ctx.cache = cache;
|
||||
ctx.flags = flags;
|
||||
ctx.qcontext = qcontext;
|
||||
ctx.req = req;
|
||||
|
|
|
@ -126,6 +126,7 @@ public class FacetModule extends SearchComponent {
|
|||
FacetComponentState facetState = getFacetComponentState(rb);
|
||||
if (facetState == null) return;
|
||||
|
||||
boolean cache = rb.req.getParams().getBool(CommonParams.CACHE, true);
|
||||
boolean isShard = rb.req.getParams().getBool(ShardParams.IS_SHARD, false);
|
||||
|
||||
FacetContext fcontext = new FacetContext();
|
||||
|
@ -133,6 +134,7 @@ public class FacetModule extends SearchComponent {
|
|||
fcontext.req = rb.req;
|
||||
fcontext.searcher = rb.req.getSearcher();
|
||||
fcontext.qcontext = QueryContext.newContext(fcontext.searcher);
|
||||
fcontext.cache = cache;
|
||||
if (isShard) {
|
||||
fcontext.flags |= FacetContext.IS_SHARD;
|
||||
fcontext.facetInfo = facetState.facetInfo.isEmpty() ? null : (Map<String, Object>) facetState.facetInfo.get(FACET_REFINE);
|
||||
|
|
|
@ -25,7 +25,9 @@ import org.apache.solr.common.params.FacetParams;
|
|||
import org.apache.solr.common.util.SimpleOrderedMap;
|
||||
import org.apache.solr.schema.*;
|
||||
import org.apache.solr.search.DocSet;
|
||||
import org.apache.solr.search.ExtendedQuery;
|
||||
import org.apache.solr.search.SyntaxError;
|
||||
import org.apache.solr.search.WrappedQuery;
|
||||
import org.apache.solr.util.DateMathParser;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -531,7 +533,20 @@ class FacetRangeProcessor extends FacetProcessor<FacetRange> {
|
|||
private Query[] filters;
|
||||
private DocSet[] intersections;
|
||||
private void rangeStats(Range range, int slot) throws IOException {
|
||||
Query rangeQ = sf.getType().getRangeQuery(null, sf, range.low == null ? null : calc.formatValue(range.low), range.high==null ? null : calc.formatValue(range.high), range.includeLower, range.includeUpper);
|
||||
final Query rangeQ;
|
||||
{
|
||||
final Query rangeQuery = sf.getType().getRangeQuery(null, sf, range.low == null ? null : calc.formatValue(range.low), range.high==null ? null : calc.formatValue(range.high), range.includeLower, range.includeUpper);
|
||||
if (fcontext.cache) {
|
||||
rangeQ = rangeQuery;
|
||||
} else if (rangeQuery instanceof ExtendedQuery) {
|
||||
((ExtendedQuery) rangeQuery).setCache(false);
|
||||
rangeQ = rangeQuery;
|
||||
} else {
|
||||
final WrappedQuery wrappedQuery = new WrappedQuery(rangeQuery);
|
||||
wrappedQuery.setCache(false);
|
||||
rangeQ = wrappedQuery;
|
||||
}
|
||||
}
|
||||
// TODO: specialize count only
|
||||
DocSet intersection = fcontext.searcher.getDocSet(rangeQ, fcontext.base);
|
||||
filters[slot] = rangeQ;
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.junit.Test;
|
|||
public class TestJsonRangeFacets extends SolrTestCaseHS {
|
||||
|
||||
private static SolrInstances servers; // for distributed testing
|
||||
private static String cache;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@BeforeClass
|
||||
|
@ -41,6 +42,7 @@ public class TestJsonRangeFacets extends SolrTestCaseHS {
|
|||
if (Boolean.getBoolean(NUMERIC_POINTS_SYSPROP)) System.setProperty(NUMERIC_DOCVALUES_SYSPROP,"true");
|
||||
|
||||
initCore("solrconfig-tlog.xml","schema_latest.xml");
|
||||
cache = Boolean.toString(random().nextBoolean());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,6 +101,7 @@ public class TestJsonRangeFacets extends SolrTestCaseHS {
|
|||
* will cause the correct "actual_end" to be returned
|
||||
*/
|
||||
private void doRangeOtherWhitebox(Client client) throws Exception {
|
||||
client.queryDefaults().set("cache", cache);
|
||||
indexSimple(client);
|
||||
|
||||
// false is default, but randomly check explicit false as well
|
||||
|
@ -177,6 +180,7 @@ public class TestJsonRangeFacets extends SolrTestCaseHS {
|
|||
}
|
||||
|
||||
private void doDateFacets(Client client) throws Exception {
|
||||
client.queryDefaults().set("cache", cache);
|
||||
client.deleteByQuery("*:*", null);
|
||||
boolean multiValue = random().nextBoolean();
|
||||
String dateField = multiValue? "b_dts": "b_dt";
|
||||
|
@ -244,6 +248,7 @@ public class TestJsonRangeFacets extends SolrTestCaseHS {
|
|||
}
|
||||
|
||||
private void doRangeFacetWithRanges(Client client) throws Exception {
|
||||
client.queryDefaults().set("cache", cache);
|
||||
client.deleteByQuery("*:*", null);
|
||||
indexSimple(client);
|
||||
|
||||
|
@ -315,6 +320,7 @@ public class TestJsonRangeFacets extends SolrTestCaseHS {
|
|||
}
|
||||
|
||||
private void doRangeFacetWithRangesInNewFormat(Client client) throws Exception {
|
||||
client.queryDefaults().set("cache", cache);
|
||||
client.deleteByQuery("*:*", null);
|
||||
indexSimple(client);
|
||||
SolrParams p = params("q", "*:*", "rows", "0");
|
||||
|
|
Loading…
Reference in New Issue