insights: generate new queries from captured values
Created by: coury-clark
To facilitate drill down when viewing an aggregation insight that is grouping on values we need to be able to produce new search queries
Limitations
For v1, the limitation is being applied that matches will only originate from the leftmost capturing group in the pattern (ie. group $1
). This replacement will also not work for patternType:structural
. Additionally, there is a limitation that only a single value can be replaced (we will not allow multiple selections).
Implementation notes
For a patternType:literal
the entire search content
can simply be replaced.
For a patternType:regexp
we need to generate new regexp strings that have replaced a portion of the pattern with the literal matches. When a pattern is generated it should be wrapped in a non-capturing group, allowing the query to effectively iterate and drill down. The replacement string should be regexp escaped.
Examples
Regexp
old pattern | text | new pattern |
---|---|---|
(\w+) |
bear |
(?:bear) |
(\w+)-(\w+) |
dog-cat |
(?:dog)-(\w+) |
(?:\w+)-(\w+) |
dog-cat |
(?:\w+)-(?:cat) |
(.*) |
\w |
(?:\\w) |