Skip to content

Commit

Permalink
Retrieve index type for display
Browse files Browse the repository at this point in the history
  • Loading branch information
gneissone committed Feb 2, 2017
1 parent 9b76dcf commit dd4796e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 31 deletions.
17 changes: 15 additions & 2 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,7 +69,7 @@ h4 {

td.facetview_filtershow {
cursor: pointer;

}

.btn-custom {
Expand All @@ -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";
Expand Down
59 changes: 30 additions & 29 deletions es.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -77,15 +77,15 @@ 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"] = {};
opts["_selected_operators"] = {}
}
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) {
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -167,7 +167,7 @@ function optionsFromQuery(query) {
opts["q"] = ""
}
}

return opts
}
}
Expand Down Expand Up @@ -318,22 +318,22 @@ 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
}
if (options.page_size !== undefined) {
qs["size"] = options.page_size
}

// facets
if (include_facets) {
qs['facets'] = {};
Expand All @@ -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"]}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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];
Expand All @@ -506,7 +507,7 @@ function elasticSearchSuccess(callback) {
}
}
}

callback(data, resultobj)
}
}
Expand All @@ -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",
Expand Down

0 comments on commit dd4796e

Please sign in to comment.