Added any_context option for AttributeS

This commit is contained in:
Trial97
2021-05-12 11:58:40 +03:00
committed by Dan Christian Bogos
parent 73de017591
commit eae23e1f8e
4 changed files with 19 additions and 5 deletions

View File

@@ -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
}

View File

@@ -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
},

View File

@@ -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

View File

@@ -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()
}