mirror of https://github.com/apache/lucene.git
SOLR-9681: move "filter" inside "domain" block
This commit is contained in:
parent
4383bec84c
commit
359f981b0e
|
@ -85,21 +85,15 @@ public abstract class FacetProcessor<FacetRequestT extends FacetRequest> {
|
|||
}
|
||||
|
||||
public void process() throws IOException {
|
||||
// Check filters... if we do have filters they apply after domain changes.
|
||||
// We still calculate them first because we can use it in a parent->child domain change.
|
||||
evalFilters();
|
||||
boolean appliedFilters = handleDomainChanges();
|
||||
if (filter != null && !appliedFilters) {
|
||||
fcontext.base = fcontext.base.intersection( filter );
|
||||
}
|
||||
handleDomainChanges();
|
||||
}
|
||||
|
||||
private void evalFilters() throws IOException {
|
||||
if (freq.filters == null || freq.filters.isEmpty()) return;
|
||||
if (freq.domain.filters == null || freq.domain.filters.isEmpty()) return;
|
||||
|
||||
List<Query> qlist = new ArrayList<>(freq.filters.size());
|
||||
List<Query> qlist = new ArrayList<>(freq.domain.filters.size());
|
||||
// TODO: prevent parsing filters each time!
|
||||
for (Object rawFilter : freq.filters) {
|
||||
for (Object rawFilter : freq.domain.filters) {
|
||||
Query symbolicFilter;
|
||||
if (rawFilter instanceof String) {
|
||||
QParser parser = null;
|
||||
|
@ -119,11 +113,19 @@ public abstract class FacetProcessor<FacetRequestT extends FacetRequest> {
|
|||
this.filter = fcontext.searcher.getDocSet(qlist);
|
||||
}
|
||||
|
||||
private boolean handleDomainChanges() throws IOException {
|
||||
if (freq.domain == null) return false;
|
||||
private void handleDomainChanges() throws IOException {
|
||||
if (freq.domain == null) return;
|
||||
handleFilterExclusions();
|
||||
|
||||
// Check filters... if we do have filters they apply after domain changes.
|
||||
// We still calculate them first because we can use it in a parent->child domain change.
|
||||
evalFilters();
|
||||
|
||||
boolean appliedFilters = handleBlockJoin();
|
||||
return appliedFilters;
|
||||
|
||||
if (this.filter != null && !appliedFilters) {
|
||||
fcontext.base = fcontext.base.intersection( filter );
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFilterExclusions() throws IOException {
|
||||
|
@ -187,7 +189,7 @@ public abstract class FacetProcessor<FacetRequestT extends FacetRequest> {
|
|||
fcontext.base = fcontext.searcher.getDocSet(qlist);
|
||||
}
|
||||
|
||||
// returns "true" if filters have already been applied.
|
||||
// returns "true" if filters were applied to fcontext.base already
|
||||
private boolean handleBlockJoin() throws IOException {
|
||||
boolean appliedFilters = false;
|
||||
if (!(freq.domain.toChildren || freq.domain.toParent)) return appliedFilters;
|
||||
|
|
|
@ -78,7 +78,6 @@ public abstract class FacetRequest {
|
|||
|
||||
protected Map<String,AggValueSource> facetStats; // per-bucket statistics
|
||||
protected Map<String,FacetRequest> subFacets; // per-bucket sub-facets
|
||||
protected List<Object> filters;
|
||||
protected boolean processEmpty;
|
||||
protected Domain domain;
|
||||
|
||||
|
@ -87,7 +86,8 @@ public abstract class FacetRequest {
|
|||
public List<String> excludeTags;
|
||||
public boolean toParent;
|
||||
public boolean toChildren;
|
||||
public String parents;
|
||||
public String parents; // identifies the parent filter... the full set of parent documents for any block join operation
|
||||
public List<Object> filters; // list of symbolic filters (JSON query format)
|
||||
}
|
||||
|
||||
public FacetRequest() {
|
||||
|
@ -359,33 +359,38 @@ abstract class FacetParser<FacetRequestT extends FacetRequest> {
|
|||
|
||||
Map<String,Object> domainMap = (Map<String,Object>) m.get("domain");
|
||||
if (domainMap != null) {
|
||||
FacetRequest.Domain domain = getDomain();
|
||||
|
||||
excludeTags = getStringList(domainMap, "excludeTags");
|
||||
if (excludeTags != null) {
|
||||
getDomain().excludeTags = excludeTags;
|
||||
domain.excludeTags = excludeTags;
|
||||
}
|
||||
|
||||
String blockParent = (String)domainMap.get("blockParent");
|
||||
String blockChildren = (String)domainMap.get("blockChildren");
|
||||
|
||||
if (blockParent != null) {
|
||||
getDomain().toParent = true;
|
||||
getDomain().parents = blockParent;
|
||||
domain.toParent = true;
|
||||
domain.parents = blockParent;
|
||||
} else if (blockChildren != null) {
|
||||
getDomain().toChildren = true;
|
||||
getDomain().parents = blockChildren;
|
||||
domain.toChildren = true;
|
||||
domain.parents = blockChildren;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Object filterOrList = m.get("filter");
|
||||
if (filterOrList != null) {
|
||||
if (filterOrList instanceof List) {
|
||||
facet.filters = (List<Object>)filterOrList;
|
||||
} else {
|
||||
facet.filters = new ArrayList<>(1);
|
||||
facet.filters.add(filterOrList);
|
||||
Object filterOrList = domainMap.get("filter");
|
||||
if (filterOrList != null) {
|
||||
assert domain.filters == null;
|
||||
if (filterOrList instanceof List) {
|
||||
domain.filters = (List<Object>)filterOrList;
|
||||
} else {
|
||||
domain.filters = new ArrayList<>(1);
|
||||
domain.filters.add(filterOrList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // end "domain"
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1167,12 +1167,12 @@ public class TestJsonFacets extends SolrTestCaseHS {
|
|||
// test filter
|
||||
client.testJQ(params(p, "q", "*:*", "myfilt","${cat_s}:A"
|
||||
, "json.facet", "{" +
|
||||
"t:{${terms} type:terms, field:${cat_s}, filter:[]}" + // empty filter list
|
||||
",t_filt:{${terms} type:terms, field:${cat_s}, filter:'${cat_s}:B'}" +
|
||||
",t_filt2:{${terms} type:terms, field:${cat_s}, filter:'{!query v=$myfilt}'}" + // test access to qparser and other query parameters
|
||||
",t_filt3:{${terms} type:terms, field:${cat_s}, filter:['-id:1','-id:2']}" +
|
||||
",q:{type:query, q:'${cat_s}:B', filter:['-id:5']}" + // also tests a top-level negative filter
|
||||
",r:{type:range, field:${num_d}, start:-5, end:10, gap:5, filter:'-id:4'}" +
|
||||
"t:{${terms} type:terms, field:${cat_s}, domain:{filter:[]} }" + // empty filter list
|
||||
",t_filt:{${terms} type:terms, field:${cat_s}, domain:{filter:'${cat_s}:B'} }" +
|
||||
",t_filt2:{${terms} type:terms, field:${cat_s}, domain:{filter:'{!query v=$myfilt}'} }" + // test access to qparser and other query parameters
|
||||
",t_filt3:{${terms} type:terms, field:${cat_s}, domain:{filter:['-id:1','-id:2']} }" +
|
||||
",q:{type:query, q:'${cat_s}:B', domain:{filter:['-id:5']} }" + // also tests a top-level negative filter
|
||||
",r:{type:range, field:${num_d}, start:-5, end:10, gap:5, domain:{filter:'-id:4'} }" +
|
||||
"}"
|
||||
)
|
||||
, "facets=={ count:6, " +
|
||||
|
@ -1419,10 +1419,10 @@ public class TestJsonFacets extends SolrTestCaseHS {
|
|||
// test filter after block join
|
||||
client.testJQ(params(p, "q", "*:*"
|
||||
, "json.facet", "{ " +
|
||||
"pages1:{type:terms, field:v_t, domain:{blockChildren:'type_s:book'}, filter:'*:*' }" +
|
||||
",pages2:{type:terms, field:v_t, domain:{blockChildren:'type_s:book'}, filter:'-id:3.1' }" +
|
||||
",books:{type:terms, field:v_t, domain:{blockParent:'type_s:book'}, filter:'*:*' }" +
|
||||
",books2:{type:terms, field:v_t, domain:{blockParent:'type_s:book'}, filter:'id:1' }" +
|
||||
"pages1:{type:terms, field:v_t, domain:{blockChildren:'type_s:book', filter:'*:*'} }" +
|
||||
",pages2:{type:terms, field:v_t, domain:{blockChildren:'type_s:book', filter:'-id:3.1'} }" +
|
||||
",books:{type:terms, field:v_t, domain:{blockParent:'type_s:book', filter:'*:*'} }" +
|
||||
",books2:{type:terms, field:v_t, domain:{blockParent:'type_s:book', filter:'id:1'} }" +
|
||||
"}"
|
||||
)
|
||||
, "facets=={ count:10" +
|
||||
|
|
Loading…
Reference in New Issue