github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/segment/reader/segread/dechecker.go (about) 1 /* 2 Copyright 2023. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package segread 18 19 import ( 20 "errors" 21 22 "github.com/siglens/siglens/pkg/segment/structs" 23 "github.com/siglens/siglens/pkg/segment/utils" 24 "github.com/siglens/siglens/pkg/segment/writer" 25 ) 26 27 /* 28 parameters: 29 30 matchFilter : input query mf 31 dictData: mapping of dict keywords --> raw recNums buf slice 32 33 returns: 34 35 bool: if there is a match 36 err 37 */ 38 func (sfr *SegmentFileReader) ApplySearchToMatchFilterDictCsg(match *structs.MatchFilter, 39 bsh *structs.BlockSearchHelper) (bool, error) { 40 41 if len(match.MatchWords) == 0 { 42 return false, nil 43 } 44 45 for dwordIdx, dWord := range sfr.deTlv { 46 matched, err := writer.ApplySearchToMatchFilterRawCsg(match, dWord) 47 if err != nil { 48 return false, err 49 } 50 if matched { 51 addRecNumsToMr(uint16(dwordIdx), bsh, sfr) 52 } 53 } 54 55 return false, nil 56 } 57 58 /* 59 parameters: 60 61 DtypeEnclosure : input qVal 62 FilterOperator: filter operator 63 isRegexSearch: 64 dictData: mapping of dict keywords --> raw recNums buf slice 65 66 returns: 67 68 bool: if there is a match 69 err 70 */ 71 func (sfr *SegmentFileReader) ApplySearchToExpressionFilterDictCsg(qValDte *utils.DtypeEnclosure, 72 fop utils.FilterOperator, isRegexSearch bool, bsh *structs.BlockSearchHelper) (bool, error) { 73 74 if qValDte == nil { 75 return false, nil 76 } 77 78 if isRegexSearch && qValDte.GetRegexp() == nil { 79 return false, errors.New("qValDte had nil regexp compilation") 80 } 81 82 dte := &utils.DtypeEnclosure{} 83 for dwordIdx, dWord := range sfr.deTlv { 84 matched, err := writer.ApplySearchToExpressionFilterSimpleCsg(qValDte, fop, dWord, isRegexSearch, dte) 85 if err != nil { 86 return false, err 87 } 88 if matched { 89 addRecNumsToMr(uint16(dwordIdx), bsh, sfr) 90 } 91 } 92 93 return false, nil 94 } 95 96 func addRecNumsToMr(dwordIdx uint16, bsh *structs.BlockSearchHelper, sfr *SegmentFileReader) { 97 98 for i := uint16(0); i < sfr.blockSummaries[sfr.currBlockNum].RecCount; i++ { 99 if sfr.deRecToTlv[i] == dwordIdx { 100 bsh.AddMatchedRecord(uint(i)) 101 } 102 } 103 }