You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2020/12/16 18:05:04 UTC
[lucene-solr] branch branch_8x updated: SOLR-14939: JSON range
faceting to support cache=false parameter (#1992)
This is an automated email from the ASF dual-hosted git repository.
cpoerschke pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new f9dc670 SOLR-14939: JSON range faceting to support cache=false parameter (#1992)
f9dc670 is described below
commit f9dc67017c8dbc590ce94b9135a7b6985447f8cf
Author: Christine Poerschke <cp...@apache.org>
AuthorDate: Wed Dec 16 17:42:24 2020 +0000
SOLR-14939: JSON range faceting to support cache=false parameter (#1992)
Resolved Conflicts:
solr/CHANGES.txt
---
solr/CHANGES.txt | 1 +
.../java/org/apache/solr/search/facet/FacetContext.java | 2 ++
.../java/org/apache/solr/search/facet/FacetModule.java | 2 ++
.../apache/solr/search/facet/FacetRangeProcessor.java | 17 ++++++++++++++++-
.../apache/solr/search/facet/TestJsonRangeFacets.java | 6 ++++++
5 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 85d604f..27dd68e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -79,6 +79,7 @@ Bug Fixes
* SOLR-15046: Check if SOLR_SSL_ENABLED strictly equal to true for setting solr.jetty.https.port (Timothy Potter)
+* SOLR-14939: JSON range faceting to support cache=false parameter. (Christine Poerschke, Mike Drob)
Other Changes
---------------------
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetContext.java b/solr/core/src/java/org/apache/solr/search/facet/FacetContext.java
index cef9d01..1caf1bd 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/FacetContext.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetContext.java
@@ -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;
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetModule.java b/solr/core/src/java/org/apache/solr/search/facet/FacetModule.java
index 0bd6651..3cde18a 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/FacetModule.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetModule.java
@@ -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);
diff --git a/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java b/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
index 4b91a41..ee137a5 100644
--- a/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
+++ b/solr/core/src/java/org/apache/solr/search/facet/FacetRangeProcessor.java
@@ -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;
diff --git a/solr/core/src/test/org/apache/solr/search/facet/TestJsonRangeFacets.java b/solr/core/src/test/org/apache/solr/search/facet/TestJsonRangeFacets.java
index 145b84b..c3ff209 100644
--- a/solr/core/src/test/org/apache/solr/search/facet/TestJsonRangeFacets.java
+++ b/solr/core/src/test/org/apache/solr/search/facet/TestJsonRangeFacets.java
@@ -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");