mirror of https://github.com/apache/lucene.git
SOLR-7422: "type" param for JSON Facet API for flatter structure
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1674519 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
beea9c2733
commit
3b94724907
|
@ -100,6 +100,11 @@ New Features
|
|||
* SOLR-7376: Return raw XML or JSON (in the appropriate writer) using DocumentTransformers.
|
||||
?fl=id,name,json_s:[json],xml_s:[xml] (ryan)
|
||||
|
||||
* SOLR-7422: Optional flatter form for the JSON Facet API via a "type" parameter:
|
||||
top_authors : { type:terms, field:author, limit:5 } is equivalent to
|
||||
top_authors : { terms : { field:author, limit:5 } }
|
||||
(yonik)
|
||||
|
||||
|
||||
Bug Fixes
|
||||
----------------------
|
||||
|
|
|
@ -366,24 +366,38 @@ abstract class FacetParser<FacetRequestT extends FacetRequest> {
|
|||
}
|
||||
|
||||
public Object parseFacetOrStat(String key, Object o) throws SyntaxError {
|
||||
if (o instanceof String) {
|
||||
return parseStringFacetOrStat(key, (String)o);
|
||||
}
|
||||
|
||||
if (!(o instanceof Map)) {
|
||||
throw err("expected Map but got " + o);
|
||||
}
|
||||
if (o instanceof String) {
|
||||
return parseStringFacetOrStat(key, (String)o);
|
||||
}
|
||||
|
||||
// { "range" : { "field":...
|
||||
Map<String,Object> m = (Map<String,Object>)o;
|
||||
if (m.size() != 1) {
|
||||
throw err("expected facet/stat type name, like {range:{... but got " + m);
|
||||
}
|
||||
if (!(o instanceof Map)) {
|
||||
throw err("expected Map but got " + o);
|
||||
}
|
||||
|
||||
// The type can be in a one element map, or inside the args as the "type" field
|
||||
// { "query" : "foo:bar" }
|
||||
// { "range" : { "field":... } }
|
||||
// { "type" : range, field : myfield, ... }
|
||||
Map<String,Object> m = (Map<String,Object>)o;
|
||||
String type;
|
||||
Object args;
|
||||
|
||||
if (m.size() == 1) {
|
||||
Map.Entry<String,Object> entry = m.entrySet().iterator().next();
|
||||
type = entry.getKey();
|
||||
args = entry.getValue();
|
||||
// throw err("expected facet/stat type name, like {range:{... but got " + m);
|
||||
} else {
|
||||
// type should be inside the map as a parameter
|
||||
Object typeObj = m.get("type");
|
||||
if (!(typeObj instanceof String)) {
|
||||
throw err("expected facet/stat type name, like {type:range, field:price, ...} but got " + typeObj);
|
||||
}
|
||||
type = (String)typeObj;
|
||||
args = m;
|
||||
}
|
||||
|
||||
// Is this most efficient way?
|
||||
Map.Entry<String,Object> entry = m.entrySet().iterator().next();
|
||||
String type = entry.getKey();
|
||||
Object args = entry.getValue();
|
||||
return parseFacetOrStat(key, type, args);
|
||||
}
|
||||
|
||||
|
|
|
@ -309,7 +309,7 @@ public class TestJsonFacets extends SolrTestCaseHS {
|
|||
|
||||
// nested query facets
|
||||
client.testJQ(params(p, "q", "*:*"
|
||||
, "json.facet", "{ catB:{query:{q:'${cat_s}:B', facet:{nj:{query:'${where_s}:NJ'}, ny:{query:'${where_s}:NY'}} }}}"
|
||||
, "json.facet", "{ catB:{type:query, q:'${cat_s}:B', facet:{nj:{query:'${where_s}:NJ'}, ny:{query:'${where_s}:NY'}} }}"
|
||||
)
|
||||
, "facets=={ 'count':6, 'catB':{'count':3, 'nj':{'count':2}, 'ny':{'count':1}}}"
|
||||
);
|
||||
|
@ -331,12 +331,12 @@ public class TestJsonFacets extends SolrTestCaseHS {
|
|||
|
||||
// field/terms facet
|
||||
client.testJQ(params(p, "q", "*:*"
|
||||
, "json.facet", "{c1:{field:'${cat_s}'}, c2:{field:{field:'${cat_s}'}}, c3:{terms:{field:'${cat_s}'}} }"
|
||||
, "json.facet", "{c1:{field:'${cat_s}'}, c2:{field:{field:'${cat_s}'}}, c3:{type:terms, field:'${cat_s}'} }"
|
||||
)
|
||||
, "facets=={ 'count':6, " +
|
||||
"'c1':{ 'buckets':[{ 'val':'B', 'count':3}, { 'val':'A', 'count':2}]}, " +
|
||||
"'c2':{ 'buckets':[{ 'val':'B', 'count':3}, { 'val':'A', 'count':2}]}, " +
|
||||
"'c3':{ 'buckets':[{ 'val':'B', 'count':3}, { 'val':'A', 'count':2}]}} "
|
||||
"'c2':{ 'buckets':[{ 'val':'B', 'count':3}, { 'val':'A', 'count':2}]}, " +
|
||||
"'c3':{ 'buckets':[{ 'val':'B', 'count':3}, { 'val':'A', 'count':2}]}} "
|
||||
);
|
||||
|
||||
// test mincount
|
||||
|
@ -552,7 +552,7 @@ public class TestJsonFacets extends SolrTestCaseHS {
|
|||
|
||||
// basic range facet
|
||||
client.testJQ(params(p, "q", "*:*"
|
||||
, "json.facet", "{f:{range:{field:${num_d}, start:-5, end:10, gap:5}}}"
|
||||
, "json.facet", "{f:{type:range, field:${num_d}, start:-5, end:10, gap:5}}"
|
||||
)
|
||||
, "facets=={count:6, f:{buckets:[ {val:-5.0,count:1}, {val:0.0,count:2}, {val:5.0,count:0} ] } }"
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue