Skip to content

Commit

Permalink
support filtering out empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-jones committed Mar 27, 2015
1 parent 46710fe commit 1fe70b4
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions jquery.facetview2.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ function getUrlVars() {
{
"field" : "<elasticsearch field>" // field upon which to facet
"display" : "<display name>", // display name for the UI
"type": "term|range|geo_distance|statistical|date_histogram", // the kind of facet this will be
"type": "terms|range|geo_distance|statistical|date_histogram", // 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)
"disabled" : true|false // whether the facet should be acted upon in any way. This might be useful if you want to enable/disable facets under different circumstances via a callback
Expand All @@ -284,6 +284,7 @@ function getUrlVars() {
"hide_inactive" : true|false, // whether to hide or just disable the facet if below deactivate threshold
"value_function" : <function>, // function to be called on each value before display
"controls" : true|false // should the facet sort/size/bool controls be shown?
"ignore_empty_string" : true|false // should the terms facet ignore empty strings in display
// range facet only
Expand Down Expand Up @@ -339,6 +340,7 @@ function getUrlVars() {
"default_hide_empty_date_bin" : true,
"default_date_histogram_sort" : "asc",
"default_short_display" : false,
"default_ignore_empty_string" : false, // because filtering out empty strings is less performant


///// search bar configuration /////////////////////////////
Expand Down Expand Up @@ -660,6 +662,7 @@ function getUrlVars() {
if (!("sort" in facet)) { facet["sort"] = provided_options.default_date_histogram_sort }
if (!("disabled" in facet)) { facet["disabled"] = false } // no default setter for this - if you don't specify disabled, they are not disabled
if (!("short_display" in facet)) { facet["short_display"] = provided_options.default_short_display }
if (!("ignore_empty_string" in facet)) { facet["ignore_empty_string"] = provided_options.default_ignore_empty_string }
}

return provided_options
Expand Down Expand Up @@ -1308,7 +1311,19 @@ function getUrlVars() {
} else {
if (!records) { records = [] }
if (size) { // this means you can set the size of a facet to something false (like, false, or 0, and size will be ignored)
facet["values"] = records.slice(0, size)
if (facet.type === "terms" && facet.ignore_empty_string) {
facet["values"] = [];
for (var i = 0; i < records.length; i++) {
if (facet.values.length > size) {
break;
}
if (records[i].term !== "") {
facet["values"].push(records[i]);
}
}
} else {
facet["values"] = records.slice(0, size)
}
} else {
facet["values"] = records
}
Expand Down

0 comments on commit 1fe70b4

Please sign in to comment.