From 26c2d4dd45888b87500b5c90a2baae96e2abbd15 Mon Sep 17 00:00:00 2001 From: "MoessnerFabian(Group)" Date: Wed, 18 Dec 2024 10:25:48 +0100 Subject: [PATCH] Refactoring --- logprep/filter/lucene_filter.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/logprep/filter/lucene_filter.py b/logprep/filter/lucene_filter.py index 745f09805..2254c24a2 100644 --- a/logprep/filter/lucene_filter.py +++ b/logprep/filter/lucene_filter.py @@ -335,13 +335,22 @@ def _create_field(self, tree: luqum.tree) -> Optional[FilterExpression]: return self._get_filter_expression_regex(key, value) return None - def _get_filter_expression( - self, key: List[str], value - ) -> Union[RegExFilterExpression, StringFilterExpression]: + @staticmethod + def _check_key_and_modifier(key, value): key_and_modifier = key[-1].split("|") if len(key_and_modifier) == 2: if key_and_modifier[-1] == "re": return RegExFilterExpression(key[:-1] + key_and_modifier[:-1], value) + return None + + + def _get_filter_expression( + self, key: List[str], value + ) -> Union[RegExFilterExpression, StringFilterExpression]: + + key_and_modifier_check = LuceneTransformer._check_key_and_modifier(key, value) + if key_and_modifier_check is not None: + return key_and_modifier_check dotted_field = ".".join(key) @@ -361,11 +370,10 @@ def _get_filter_expression( def _get_filter_expression_regex( self, key: List[str], value ) -> Union[RegExFilterExpression, StringFilterExpression]: - key_and_modifier = key[-1].split("|") - if len(key_and_modifier) == 2: - if key_and_modifier[-1] == "re": - return RegExFilterExpression(key[:-1] + key_and_modifier[:-1], value) + key_and_modifier_check = LuceneTransformer._check_key_and_modifier(key, value) + if key_and_modifier_check is not None: + return key_and_modifier_check value = value.strip("/") return RegExFilterExpression(key, value)