Skip to content

Commit

Permalink
add support for statistical facet
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-jones committed Sep 25, 2014
1 parent 855290f commit ed1fbc8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
7 changes: 7 additions & 0 deletions es.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ function optionsFromQuery(query) {
break
}
}

// FIXME: support for statistical facet
}

if (qs) {
Expand Down Expand Up @@ -295,6 +297,8 @@ function elasticSearchQuery(params) {
ranges.push(robj)
}
facet["geo_distance"]["ranges"] = ranges
} else if (defn.type === "statistical") {
facet["statistical"] = {"field" : defn["field"]}
}
qs["facets"][defn["field"]] = facet
}
Expand Down Expand Up @@ -380,6 +384,9 @@ function elasticSearchSuccess(callback) {
} else if ("ranges" in facet) {
var range = facet["ranges"]
resultobj["facets"][item] = range
// handle statistical facets
} else if (facet["_type"] === "statistical") {
resultobj["facets"][item] = facet
}
}
}
Expand Down
34 changes: 28 additions & 6 deletions jquery.facetview2.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ function theFacetview(options) {
var thefacetview = '<div id="facetview"><div class="row-fluid">';

// if there are facets, give them span3 to exist, otherwise, take up all the space
if ( options.facets.length > 0 ) {
var showfacets = false
for (var i = 0; i < options.facets.length; i++) {
var f = options.facets[i]
if (!f.hidden) {
showfacets = true;
break;
}
}
if (showfacets) {
thefacetview += '<div class="span3"><div id="facetview_filters" style="padding-top:45px;"></div></div>';
thefacetview += '<div class="span9" id="facetview_rightcol">';
} else {
Expand Down Expand Up @@ -309,6 +317,7 @@ function facetList(options) {
} else if (type === "geo_distance") {
thefilters += options.render_geo_facet(facet, options)
}
// FIXME: statistical facet?
};
return thefilters
};
Expand Down Expand Up @@ -1203,7 +1212,7 @@ function getUrlVars() {
{
"field" : "<elasticsearch field>" // field upon which to facet
"display" : "<display name>", // display name for the UI
"type": "term|range|geo_distance", // the kind of facet this will be
"type": "term|range|geo_distance|statistical", // the kind of facet this will be
"open" : true|false, // whether the facet should be open or closed (initially)
"hidden" : true|false // whether the facet should be displayed at all (e.g. you may just want the data for a callback)
Expand Down Expand Up @@ -1889,6 +1898,7 @@ function getUrlVars() {
} else if (facet.type === "geo_distance") {
frag = options.render_geo_facet_values(options, facet)
}
// FIXME: how to display statistical facet?
if (frag) {
el.append(frag)
}
Expand Down Expand Up @@ -1926,6 +1936,7 @@ function getUrlVars() {
if (from) { value["from"] = from }
if (to) { value["to"] = to }
}
// FIXME: how to handle clicks on statistical facet (if that even makes sense)

// update the options and the filter display. No need to update
// the facet, as we'll issue a search straight away and it will
Expand Down Expand Up @@ -1959,6 +1970,7 @@ function getUrlVars() {
// NOTE: we are implicitly stating that geo distance range filters cannot be OR'd
options.active_filters[field] = value
}
// FIXME: statistical facet support here?
}

function deSelectFilter(facet, field, value) {
Expand All @@ -1975,6 +1987,7 @@ function getUrlVars() {
} else if (facet.type === "geo_distance") {
delete options.active_filters[field]
}
// FIXME: statistical facet support?
}
}

Expand All @@ -1991,6 +2004,7 @@ function getUrlVars() {
} else if (facet.type === "geo_distance") {
frag += options.render_active_geo_filter(options, facet, field, filter_list)
}
// FIXME: statistical facet?
}
}

Expand Down Expand Up @@ -2021,6 +2035,7 @@ function getUrlVars() {
if (from) { value["from"] = from }
if (to) { value["to"] = to }
}
// FIXMe: statistical facet

deSelectFilter(facet, field, value)
setUISelectedFilters()
Expand Down Expand Up @@ -2061,6 +2076,8 @@ function getUrlVars() {
}
visible = view
}
// FIXME: statistical facet?

options.behaviour_facet_visibility(options, obj, facet, visible)
});
}
Expand Down Expand Up @@ -2158,9 +2175,14 @@ function getUrlVars() {
// get the records to be displayed, limited by the size and record against
// the options object
var records = results["facets"][field];
if (!records) { records = [] }
facet["values"] = records.slice(0, size)

// special rule for handling statistical facets
if (records.hasOwnProperty("_type") && records["_type"] == "statistical") {
facet["values"] = records
} else {
if (!records) { records = [] }
facet["values"] = records.slice(0, size)
}

// set the results on the page
if (!facet.hidden) {
setUIFacetResults(facet)
Expand Down Expand Up @@ -2255,7 +2277,7 @@ function getUrlVars() {
obj.append(thefacetview);

// add the search controls
$(".facetview_search_options_container").html(thesearchopts)
$(".facetview_search_options_container", obj).html(thesearchopts)

// add the facets (empty at this stage)
if (thefacets != "") {
Expand Down

0 comments on commit ed1fbc8

Please sign in to comment.