Fix autocomplete misses certain queries

For some of the queries, the fuzzy lookup was not filtering properly.
The problem is due to the "replace" beind made on the query itself. It
accidently removes only the first underscore. This patch changes it so
that it removes all of the whitespaces, letting the fuzzy algorithm do
its magic, also fixing this problem.

Originally, the underscore were replaced by a space for this specific
reason, to let the user type a space and have the lookup treat it as the
word break.

Fixes #2380
This commit is contained in:
Or Cohen 2017-02-05 16:20:52 +02:00
parent 4daffbef12
commit 81d37a04aa
2 changed files with 7 additions and 8 deletions

File diff suppressed because one or more lines are too long

View file

@ -212,13 +212,12 @@ Prometheus.Graph.prototype.populateInsertableMetrics = function() {
items: "all",
matcher: function(item) {
// If we have result for current query, skip
if (!self.fuzzyResult.query || self.fuzzyResult.query !== this.query) {
if (self.fuzzyResult.query === null || self.fuzzyResult.query !== this.query) {
self.fuzzyResult.query = this.query;
self.fuzzyResult.map = {};
self.fuzzyResult.result = fuzzy.filter(this.query.replace('_', ' '), metrics, {
self.fuzzyResult.result = fuzzy.filter(this.query.replace(/ /g, ''), metrics, {
pre: '<strong>',
post: '</strong>',
extract: function(el) { return el.replace('_', ' ') }
post: '</strong>'
});
self.fuzzyResult.result.forEach(function(r) {
self.fuzzyResult.map[r.original] = r;
@ -237,7 +236,7 @@ Prometheus.Graph.prototype.populateInsertableMetrics = function() {
},
highlighter: function (item) {
return $('<div>' + self.fuzzyResult.map[item].string.replace(' ', '_') + '</div>')
return $('<div>' + self.fuzzyResult.map[item].string + '</div>')
},
});
// This needs to happen after attaching the typeahead plugin, as it