Skip to content

Commit

Permalink
[Uptime] Monitor list fix default search behaviour (#147336)
Browse files Browse the repository at this point in the history
Co-authored-by: Abdul Wahab Zahid <[email protected]>
Fixes #147245
  • Loading branch information
shahzad31 authored Dec 12, 2022
1 parent 3063950 commit 80a6e6c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { getQueryStringFilter } from './get_query_string_filter';

describe('get_query_string_filter', () => {
it('should return query string filter', () => {
expect(getQueryStringFilter('test')).toEqual({
query_string: {
query: '*test* or tags:test*',
fields: [
'monitor.id.text',
'monitor.name.text',
'url.full.text',
'synthetics.step.name',
'synthetics.journey.name',
],
},
});
});

it('port filter in case query is number', () => {
expect(getQueryStringFilter('443')).toEqual({
query_string: {
query: 'url.port:443 or 443',
fields: [
'monitor.id.text',
'monitor.name.text',
'url.full.text',
'synthetics.step.name',
'synthetics.journey.name',
],
},
});
});

it('do not wrap if it already has reserved char', () => {
expect(getQueryStringFilter('test*')).toEqual({
query_string: {
query: 'test*',
fields: [
'monitor.id.text',
'monitor.name.text',
'url.full.text',
'synthetics.step.name',
'synthetics.journey.name',
],
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
export const getQueryStringFilter = (query: string) => {
let queryString = query;
if (hasReservedCharsF(query) && !includesOperator(query.toLowerCase())) {
// if user doesn't specify any query string syntax we user wildcard buy default
queryString = `${query}* or tags:${query}*`;
// if user doesn't specify any query string syntax we use wildcard by default
queryString = `*${query}* or tags:${query}*`;
}

if (Number(query)) {
Expand Down

0 comments on commit 80a6e6c

Please sign in to comment.