Skip to content

Commit

Permalink
refactoring search logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Jul 4, 2018
1 parent 5bb93ee commit a51b78b
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions x-pack/plugins/ml/public/jobs/jobs_list_new/components/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ export function filterJobs(jobs, clauses) {
clauses.forEach((c) => {
// the search term could be negated with a minus, e.g. -bananas
const bool = (c.match === 'must');
let js = [];

if (c.type === 'term') {
// filter term based clauses, e.g. bananas
// match on id, description and memory_status
// if the term has been negated, AND the matches
let js = [];

if (bool === true) {
js = jobs.filter(job => ((
(stringMatch(job.id, c.value) === bool) ||
Expand All @@ -175,19 +175,17 @@ export function filterJobs(jobs, clauses) {
(stringMatch(job.memory_status, c.value) === bool)
)));
}
js.forEach(j => (matches[j.id].count++));
} else {
// filter other clauses, i.e. the toggle group buttons
// the groups value is an array of group ids
let js = [];
if (Array.isArray(c.value)) {
js = jobs.filter(job => (jobProperty(job, c.field).some((g) => (c.value.indexOf(g) >= 0))));
// the groups value is an array of group ids
js = jobs.filter(job => (jobProperty(job, c.field).some(g => (c.value.indexOf(g) >= 0))));
} else {
js = jobs.filter(job => (jobProperty(job, c.field) === c.value));
}

js.forEach(j => (matches[j.id].count++));
}

js.forEach(j => (matches[j.id].count++));
});

// loop through the matches and return only those jobs which have match all the clauses
Expand Down

0 comments on commit a51b78b

Please sign in to comment.