From dd4796eebccde1f8c666ed47012e9112395c6660 Mon Sep 17 00:00:00 2001 From: Benjamin Gross Date: Wed, 1 Feb 2017 17:24:54 -0700 Subject: [PATCH] Retrieve index type for display --- css/style.css | 17 +++++++++++++-- es.js | 59 ++++++++++++++++++++++++++------------------------- 2 files changed, 45 insertions(+), 31 deletions(-) diff --git a/css/style.css b/css/style.css index 37ca28c..432331b 100644 --- a/css/style.css +++ b/css/style.css @@ -7,6 +7,19 @@ body { /* padding-top: 40px; /* 40px to make the container go all the way to the bottom of the topbar */ } +.label-primary-transparent { + font-size: 13px; + background: transparent; + border: 1px solid #337ab7; + color: #337ab7; + font-weight: 400; + transition: all 0.5s; +} +.label-primary-transparent:hover { + background: #337ab7; + color: #fff; +} + .content { background-color: #fff; padding: 20px; @@ -56,7 +69,7 @@ h4 { td.facetview_filtershow { cursor: pointer; - + } .btn-custom { @@ -75,7 +88,7 @@ td.facetview_filtershow { text-shadow: 0 1px 1px rgba(255, 255, 255, 0.19); -webkit-font-smoothing: antialiased; } - + .dropdown-menu .selected:after { font-family: "Glyphicons Halflings"; content:"\0020\e013"; diff --git a/es.js b/es.js index 61aa241..93ff9bb 100644 --- a/es.js +++ b/es.js @@ -49,26 +49,26 @@ function optionsFromQuery(query) { return val; } - + var opts = {}; // FIXME: note that fields are not supported here // from position if (query.hasOwnProperty("from")) { opts["from"] = query.from } - + // page size if (query.size) { opts["page_size"] = query.size } - + if (query["sort"]) { opts["sort"] = query["sort"] } - + // get hold of the bool query if it is there // and get hold of the query string and default operator if they have been provided if (query.query) { var sq = query.query; var must = []; var qs = undefined; - + // if this is a filtered query, pull must and qs out of the filter // otherwise the root of the query is the query_string object if (sq.filtered) { @@ -77,7 +77,7 @@ function optionsFromQuery(query) { } else { qs = sq } - + // go through each clause in the must and pull out the options if (must.length > 0) { opts["_active_filters"] = {}; @@ -85,7 +85,7 @@ function optionsFromQuery(query) { } for (var i = 0; i < must.length; i++) { var clause = must[i]; - + // could be a term query (implies AND on this field) if ("term" in clause) { for (var field in clause.term) { @@ -99,7 +99,7 @@ function optionsFromQuery(query) { } } } - + // could be a terms query (implies OR on this field) if ("terms" in clause) { for (var field=0; field < clause.terms.length; field=field+1) { @@ -111,7 +111,7 @@ function optionsFromQuery(query) { opts["_active_filters"][field] = opts["_active_filters"][field].concat(values) } } - + // could be a range query (which may in turn be a range or a date histogram facet) if ("range" in clause) { // get the field that we're ranging on @@ -130,16 +130,16 @@ function optionsFromQuery(query) { opts["_active_filters"][field] = range; } } - + // cound be a geo distance query if ("geo_distance_range" in clause) { var gdr = clause.geo_distance_range; - + // the range is defined at the root of the range filter var range = {}; if ("lt" in gdr) { range["to"] = stripDistanceUnits(gdr.lt) } if ("gte" in gdr) { range["from"] = stripDistanceUnits(gdr.gte) } - + // FIXME: at some point we may need to make this smarter, if we start including other data // in the geo_distance_range filter definition // then we have to go looking for the field name @@ -152,7 +152,7 @@ function optionsFromQuery(query) { // FIXME: support for statistical facet and terms_stats facet } - + if (qs) { if (qs.query_string) { var string = unescapeQueryString(qs.query_string.query); @@ -167,7 +167,7 @@ function optionsFromQuery(query) { opts["q"] = "" } } - + return opts } } @@ -318,14 +318,14 @@ function elasticSearchQuery(params) { // sort order and direction options.sort && options.sort.length > 0 ? qs['sort'] = options.sort : ""; - + // fields and partial fields if (include_fields) { options.fields ? qs['fields'] = options.fields : ""; options.partial_fields ? qs['partial_fields'] = options.partial_fields : ""; options.script_fields ? qs["script_fields"] = options.script_fields : ""; } - + // paging (number of results, and start cursor) if (options.from !== undefined) { qs["from"] = options.from @@ -333,7 +333,7 @@ function elasticSearchQuery(params) { if (options.page_size !== undefined) { qs["size"] = options.page_size } - + // facets if (include_facets) { qs['facets'] = {}; @@ -342,10 +342,10 @@ function elasticSearchQuery(params) { if (defn.disabled) { continue } var size = defn.size; - + // add a bunch of extra values to the facets to deal with the shard count issue - size += options.elasticsearch_facet_inflation - + size += options.elasticsearch_facet_inflation + var facet = {}; if (defn.type === "terms") { facet["terms"] = {"field" : defn["field"], "size" : size, "order" : defn["order"]} @@ -382,14 +382,14 @@ function elasticSearchQuery(params) { } qs["facets"][defn["field"]] = facet } - + // and any extra facets // NOTE: this does not include any treatment of the facet size inflation that may be required if (options.extra_facets) { $.extend(true, qs['facets'], options.extra_facets ); } } - + return qs } @@ -469,18 +469,19 @@ function elasticSearchSuccess(callback) { "found" : data.hits.total, "facets" : {} }; - + // load the results into the records part of the result object for (var item = 0; item < data.hits.hits.length; item++) { var res = data.hits.hits[item]; if ("fields" in res) { // partial_fields and script_fields are also included here - no special treatment resultobj.records.push(res.fields) - } else { - resultobj.records.push(res._source) + } else { // TODO Make it possible to optionally set add'l fields to append to _source, such as _type. + resultobj.records.push(res._source); + if ("res._type") {resultobj.records[item]["type"] = res._type} } } - + for (var item in data.facets) { if (data.facets.hasOwnProperty(item)) { var facet = data.facets[item]; @@ -506,7 +507,7 @@ function elasticSearchSuccess(callback) { } } } - + callback(data, resultobj) } } @@ -518,10 +519,10 @@ function doElasticSearchQuery(params) { var search_url = params.search_url; var queryobj = params.queryobj; var datatype = params.datatype; - + // serialise the query var querystring = serialiseQueryObject(queryobj); - + // make the call to the elasticsearch web service $.ajax({ type: "get",