Repository navigation
[Management] Allow wildcard anywhere in the search query - #16109
Conversation
cjcenizal
left a comment
There was a problem hiding this comment.
Nice! I tested this in browser and it works. I have a couple small comments. Have you tested that MAX_SEARCH_SIZE has the expected result when you have a massive number of indices?
| }); | ||
| }); | ||
|
|
||
| it('should support queries with wildcards in various places again', () => { |
There was a problem hiding this comment.
What is this test verifying which the one before it does not?
There was a problem hiding this comment.
It should be verifying that a wildcard not at the end of the query still works
| if (query.endsWith('*') && name.indexOf(query.substring(0, query.length - 1)) === 0) { | ||
| return true; | ||
|
|
||
| const regexQuery = query.startsWith('*') |
There was a problem hiding this comment.
How about extracting this logic into a helper function, and adding a couple light tests for it? I think it would improve readability of this code.
There was a problem hiding this comment.
Sounds like the right move!
| allIndices: [{ name: 'kibana' }, { name: 'kibana2' }, { name: 'es' }], | ||
| exactMatchedIndices: [{ name: 'kibana' }, { name: 'kibana2' }], | ||
| partialMatchedIndices: [{ name: 'kibana' }, { name: 'kibana2' }], | ||
| visibleIndices: [{ name: 'kibana' }, { name: 'kibana2' }] |
There was a problem hiding this comment.
Something to think about in a later iteration, but I think we might be able to make these tests clearer if we pared the tests down to make assertions against just allIndices, exactMatchedIndices, partialMatchedIndices, and visibleIndices. This would result in more focused tests and I think it'd be easier to spot the relationships between the input and each specific type of output. It would result in more tests, however. What do you think?
There was a problem hiding this comment.
Totally agree. Great suggestion!
|
@cjcenizal I haven't tested it like that. Rather, I've just decreased the number to something small, like 3 and it works as expected. Do you think it's necessary to test it like you're describing? |
|
I was just thinking of this part of the PR description:
Is there a way we can verify this behaves as expected now? |
cjcenizal
left a comment
There was a problem hiding this comment.
🏇 Sweet! Just had a couple minor comments about test readability.
| import { isQueryAMatch } from '../is_query_a_match'; | ||
|
|
||
| describe('isQueryAMatch', () => { | ||
| it('should handle straight up matches', () => { |
There was a problem hiding this comment.
"Handles" is a bit ambiguous to me. Can we rephrase/restructure these statements to assert the nature of the outcome? I'd suggest:
describe('returns true', () => {
it('for an exact value')
it('for a pattern with a trailing wildcard')
it('for a pattern with a leading wildcard')
it('for a pattern with a middle and trailing wildcard')
it('for a pattern with a middle wildcard')
it(`for a pattern that's only a wildcard`)
});
describe('returns false', () => {
it('for a non-matching pattern')
});|
|
||
| // This shouldn't be necessary but just used as a safety net | ||
| // so the page doesn't bust if the user types in some weird | ||
| // query that throws an exception when converting to a RegExp |
| ]; | ||
|
|
||
| const result = getMatchedIndices(indices, matchedIndices, query, true); | ||
| describe('visibleIndices', () => { |
There was a problem hiding this comment.
Re our convo, I think these test would be easier to follow if we reverse the order of the "filtered" and "not filtered" assertions, so that the reader understands the baseline behavior first, and then can compare that with the "filtered" test to see how changing the last argument to false affects the output.
I also think being more verbose with the description would help make these tests clearer, e.g. by changing "should return unfiltered" to "returns all indices" and "should return filtered" to "excludes system indices".
I just made a code change to handle and test this: ab6535d Thoughts? |
* Allow wildcard anywhere in the search query * PR feedback for tests * Update tests * Throw exception when missing required parameter
|
Backport: 6.x: #16154 |
* Allow wildcard anywhere in the search query * PR feedback for tests * Update tests * Throw exception when missing required parameter
Fixes #16098
This PR addresses two things:
Ensures that queries like
*o*properly match an index likefoo. Before this PR, only ending wildcards did anything.Addresses a bug where the number of results showing on the index pattern creation page was fewer than expected. This is because the proper limit was never passed into the ES query and it used the default limit (which I think is 10)
Testing
Ensure that using a wildcard in the search query, in places other than the end, match indices properly.
Tests
Tests have been updated to handle this scenario.