diff --git a/config/attributescfg.go b/config/attributescfg.go index 9b782e776..e277b2820 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) { @@ -68,6 +69,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 } @@ -143,6 +147,7 @@ type AttributeSJsonCfg struct { Suffix_indexed_fields *[]string Nested_fields *bool // applies when indexed fields is not defined Process_runs *int + Any_context *bool } func diffAttributeSJsonCfg(d *AttributeSJsonCfg, v1, v2 *AttributeSCfg) *AttributeSJsonCfg { diff --git a/config/config_defaults.go b/config/config_defaults.go index 0d8e63c48..045559997 100644 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -624,6 +624,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/engine/attributes.go b/engine/attributes.go index 7971ef793..1ed94140f 100644 --- a/engine/attributes.go +++ b/engine/attributes.go @@ -73,11 +73,14 @@ func (alS *AttributeService) attributeProfileForEvent(apiCtx *context.Context, t alS.cgrcfg.AttributeSCfg().IndexedSelects, alS.cgrcfg.AttributeSCfg().NestedFields, ) - if err != nil { - if err != utils.ErrNotFound { - return nil, err - } - if aPrflIDs, err = MatchingItemIDsForEvent(apiCtx, 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, @@ -87,6 +90,11 @@ func (alS *AttributeService) attributeProfileForEvent(apiCtx *context.Context, t alS.cgrcfg.AttributeSCfg().NestedFields); err != nil { return nil, err } + if aPrflIDs.Size() == 0 { + aPrflIDs = aPrflAnyIDs + } else { + aPrflIDs = utils.JoinStringSet(aPrflIDs, aPrflAnyIDs) + } } attrIDs = aPrflIDs.AsSlice() }