This commit is contained in:
Aliaksandr Valialkin 2024-05-30 13:50:12 +02:00
parent 833e413cc0
commit 15598986e6
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
2 changed files with 73 additions and 63 deletions

View file

@ -117,35 +117,13 @@ func (fa *filterAnd) initByFieldTokens() {
byFieldFilters := make(map[string]int) byFieldFilters := make(map[string]int)
var fieldNames []string var fieldNames []string
for _, f := range fa.filters { mergeFieldTokens := func(fieldName string, tokens []string) {
fieldName := ""
var tokens []string
switch t := f.(type) {
case *filterExact:
fieldName = t.fieldName
tokens = t.getTokens()
case *filterExactPrefix:
fieldName = t.fieldName
tokens = t.getTokens()
case *filterPhrase:
fieldName = t.fieldName
tokens = t.getTokens()
case *filterPrefix:
fieldName = t.fieldName
tokens = t.getTokens()
case *filterRegexp:
fieldName = t.fieldName
tokens = t.getTokens()
case *filterSequence:
fieldName = t.fieldName
tokens = t.getTokens()
}
fieldName = getCanonicalColumnName(fieldName) fieldName = getCanonicalColumnName(fieldName)
byFieldFilters[fieldName]++ byFieldFilters[fieldName]++
if len(tokens) == 0 {
return
}
if len(tokens) > 0 {
mTokens, ok := m[fieldName] mTokens, ok := m[fieldName]
if !ok { if !ok {
fieldNames = append(fieldNames, fieldName) fieldNames = append(fieldNames, fieldName)
@ -156,6 +134,33 @@ func (fa *filterAnd) initByFieldTokens() {
mTokens[token] = struct{}{} mTokens[token] = struct{}{}
} }
} }
for _, f := range fa.filters {
switch t := f.(type) {
case *filterExact:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterExactPrefix:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterPhrase:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterPrefix:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterRegexp:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterSequence:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterOr:
bfts := t.getByFieldTokens()
for _, bft := range bfts {
mergeFieldTokens(bft.field, bft.tokens)
}
}
} }
var byFieldTokens []fieldTokens var byFieldTokens []fieldTokens

View file

@ -130,40 +130,45 @@ func (fo *filterOr) initByFieldTokens() {
byFieldFilters := make(map[string]int) byFieldFilters := make(map[string]int)
var fieldNames []string var fieldNames []string
for _, f := range fo.filters { mergeFieldTokens := func(fieldName string, tokens []string) {
fieldName := ""
var tokens []string
switch t := f.(type) {
case *filterExact:
fieldName = t.fieldName
tokens = t.getTokens()
case *filterExactPrefix:
fieldName = t.fieldName
tokens = t.getTokens()
case *filterPhrase:
fieldName = t.fieldName
tokens = t.getTokens()
case *filterPrefix:
fieldName = t.fieldName
tokens = t.getTokens()
case *filterRegexp:
fieldName = t.fieldName
tokens = t.getTokens()
case *filterSequence:
fieldName = t.fieldName
tokens = t.getTokens()
}
fieldName = getCanonicalColumnName(fieldName) fieldName = getCanonicalColumnName(fieldName)
byFieldFilters[fieldName]++ byFieldFilters[fieldName]++
if len(tokens) == 0 {
return
}
if len(tokens) > 0 {
if _, ok := m[fieldName]; !ok { if _, ok := m[fieldName]; !ok {
fieldNames = append(fieldNames, fieldName) fieldNames = append(fieldNames, fieldName)
} }
m[fieldName] = append(m[fieldName], tokens) m[fieldName] = append(m[fieldName], tokens)
} }
for _, f := range fo.filters {
switch t := f.(type) {
case *filterExact:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterExactPrefix:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterPhrase:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterPrefix:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterRegexp:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterSequence:
tokens := t.getTokens()
mergeFieldTokens(t.fieldName, tokens)
case *filterAnd:
bfts := t.getByFieldTokens()
for _, bft := range bfts {
mergeFieldTokens(bft.field, bft.tokens)
}
}
} }
var byFieldTokens []fieldTokens var byFieldTokens []fieldTokens