Skip to content

Commit

Permalink
* Adding filter chip & query support for special character only strin…
Browse files Browse the repository at this point in the history
…gs. (#3168)

* Removing the filter chip icons for fields that are known not to behave as expected.
  • Loading branch information
jkppr committed Aug 28, 2024
1 parent 29ef31f commit 7e91aef
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
13 changes: 11 additions & 2 deletions timesketch/frontend-ng/src/components/Explore/EventDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ limitations under the License.
</v-btn>

<!-- Include field:value as filter chip -->
<v-btn @click.stop="applyFilterChip(key, value, 'must')" icon x-small class="mr-1">
<v-btn
v-if="!ignoreFilterChips.has(key)"
@click.stop="applyFilterChip(key, value, 'must')"
icon
x-small
class="mr-1">
<v-icon title="Filter for value">mdi-filter-plus-outline</v-icon>
</v-btn>

<!-- Exclude field:value as filter chip -->
<v-btn
v-if="!ignoreFilterChips.has(key)"
@click.stop="applyFilterChip(key, value, 'must_not')"
icon
x-small
Expand Down Expand Up @@ -197,9 +203,12 @@ export default {
'path_spec',
'strings',
'timestamp',
'timestamp_desc',
'xml_string',
]),
ignoreFilterChips: new Set([
'datetime',
'tag',
]),
eventKey: '',
eventValue: '',
eventTimestamp: 0,
Expand Down
36 changes: 31 additions & 5 deletions timesketch/lib/datastores/opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,28 @@ def build_query(

query_dsl = {"query": {"bool": {"must": [], "must_not": [], "filter": []}}}

special_char_query = None
if query_string:
query_parts = query_string.split(":", 1)
if len(query_parts) == 2:
field_name, query_value = query_parts

# Special Character Check
if set(query_value) <= set('.+-=_&|><!(){}[]^"~?:\\/'):
# Construct the term query directly using the .keyword
special_char_query = {
"term": {f"{field_name}.keyword": query_value}
}
query_string = ""

if query_string:
query_dsl["query"]["bool"]["must"].append(
{"query_string": {"query": query_string, "default_operator": "AND"}}
)

if special_char_query:
query_dsl["query"]["bool"]["must"].append(special_char_query)

# New UI filters
if query_filter.get("chips", None):
labels = []
Expand All @@ -374,13 +391,22 @@ def build_query(
labels.append(chip["value"])

elif chip["type"] == "term":
term_filter = {
"match_phrase": {
"{}".format(chip["field"]): {
"query": "{}".format(chip["value"])
if isinstance(chip["value"], str):
term_filter = {
"match_phrase": {
"{}.keyword".format(chip["field"]): {
"query": "{}".format(chip["value"])
}
}
}
else:
term_filter = {
"match_phrase": {
"{}".format(chip["field"]): {
"query": "{}".format(chip["value"])
}
}
}
}

if chip["operator"] == "must":
must_filters.append(term_filter)
Expand Down

0 comments on commit 7e91aef

Please sign in to comment.