From eae23e1f8e61946fb76de708ae1d622b05cc0f2d Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 12 May 2021 11:58:40 +0300 Subject: [PATCH] Added any_context option for AttributeS --- config/attributescfg.go | 4 ++++ config/config_defaults.go | 1 + config/libconfig_json.go | 1 + engine/attributes.go | 18 +++++++++++++----- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/config/attributescfg.go b/config/attributescfg.go index 38dc9c0b0..4b665987a 100644 --- a/config/attributescfg.go +++ b/config/attributescfg.go @@ -32,6 +32,7 @@ type AttributeSCfg struct { SuffixIndexedFields *[]string ProcessRuns int NestedFields bool + AnyContext bool } func (alS *AttributeSCfg) loadFromJSONCfg(jsnCfg *AttributeSJsonCfg) (err error) { @@ -101,6 +102,9 @@ func (alS *AttributeSCfg) loadFromJSONCfg(jsnCfg *AttributeSJsonCfg) (err error) if jsnCfg.Nested_fields != nil { alS.NestedFields = *jsnCfg.Nested_fields } + if jsnCfg.Any_context != nil { + alS.AnyContext = *jsnCfg.Any_context + } return } diff --git a/config/config_defaults.go b/config/config_defaults.go index cf0cf364b..524663d51 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -684,6 +684,7 @@ const CGRATES_CFG_JSON = ` "suffix_indexed_fields": [], // query indexes based on these fields for faster processing "nested_fields": false, // determines which field is checked when matching indexed filters(true: all; false: only the one on the first level) "process_runs": 1, // number of run loops when processing event + "any_context": true, // if we match the *any context }, diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 7f7f58128..504c15398 100644 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -401,6 +401,7 @@ type AttributeSJsonCfg struct { Suffix_indexed_fields *[]string Nested_fields *bool // applies when indexed fields is not defined Process_runs *int + Any_context *bool } // ChargerSJsonCfg service config section diff --git a/engine/attributes.go b/engine/attributes.go index 7de154d5c..5b11610e0 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -71,11 +71,14 @@ func (alS *AttributeService) attributeProfileForEvent(tnt string, ctx *string, a alS.cgrcfg.AttributeSCfg().IndexedSelects, alS.cgrcfg.AttributeSCfg().NestedFields, ) - if err != nil { - if err != utils.ErrNotFound { - return nil, err - } - if aPrflIDs, err = MatchingItemIDsForEvent(evNm, + if err != nil && + err != utils.ErrNotFound { + return nil, err + } + if err == utils.ErrNotFound || + alS.cgrcfg.AttributeSCfg().AnyContext { + var aPrflAnyIDs utils.StringSet + if aPrflAnyIDs, err = MatchingItemIDsForEvent(evNm, alS.cgrcfg.AttributeSCfg().StringIndexedFields, alS.cgrcfg.AttributeSCfg().PrefixIndexedFields, alS.cgrcfg.AttributeSCfg().SuffixIndexedFields, @@ -85,6 +88,11 @@ func (alS *AttributeService) attributeProfileForEvent(tnt string, ctx *string, a alS.cgrcfg.AttributeSCfg().NestedFields); err != nil { return nil, err } + if aPrflIDs.Size() == 0 { + aPrflIDs = aPrflAnyIDs + } else { + aPrflIDs = utils.JoinStringSet(aPrflIDs, aPrflAnyIDs) + } } attrIDs = aPrflIDs.AsSlice() }