diff --git a/lib/logstorage/filter.go b/lib/logstorage/filter.go index 52e1ebd96..f18e7e85a 100644 --- a/lib/logstorage/filter.go +++ b/lib/logstorage/filter.go @@ -69,7 +69,7 @@ func (fs *streamFilter) apply(bs *blockSearch, bm *bitmap) { } } -// phraseFilter filters field entries by phrase match (aka full text search). +// filterPhrase filters field entries by phrase match (aka full text search). // // A phrase consists of any number of words with delimiters between them. // @@ -79,7 +79,7 @@ func (fs *streamFilter) apply(bs *blockSearch, bm *bitmap) { // Multi-word phrase is expressed as `fieldName:"word1 ... wordN"` in LogsQL. // // A special case `fieldName:""` matches any value without `fieldName` field. -type phraseFilter struct { +type filterPhrase struct { fieldName string phrase string @@ -87,20 +87,20 @@ type phraseFilter struct { tokens []string } -func (fp *phraseFilter) String() string { +func (fp *filterPhrase) String() string { return quoteFieldNameIfNeeded(fp.fieldName) + quoteTokenIfNeeded(fp.phrase) } -func (fp *phraseFilter) getTokens() []string { +func (fp *filterPhrase) getTokens() []string { fp.tokensOnce.Do(fp.initTokens) return fp.tokens } -func (fp *phraseFilter) initTokens() { +func (fp *filterPhrase) initTokens() { fp.tokens = tokenizeStrings(nil, []string{fp.phrase}) } -func (fp *phraseFilter) apply(bs *blockSearch, bm *bitmap) { +func (fp *filterPhrase) apply(bs *blockSearch, bm *bitmap) { fieldName := fp.fieldName phrase := fp.phrase diff --git a/lib/logstorage/filter_and.go b/lib/logstorage/filter_and.go index 5006e07a6..7b4a46e02 100644 --- a/lib/logstorage/filter_and.go +++ b/lib/logstorage/filter_and.go @@ -65,7 +65,7 @@ func (fa *filterAnd) initMsgTokens() { var a []string for _, f := range fa.filters { switch t := f.(type) { - case *phraseFilter: + case *filterPhrase: if isMsgFieldName(t.fieldName) { a = append(a, t.getTokens()...) } diff --git a/lib/logstorage/filter_and_test.go b/lib/logstorage/filter_and_test.go index bd3907ac9..66c1c9f5e 100644 --- a/lib/logstorage/filter_and_test.go +++ b/lib/logstorage/filter_and_test.go @@ -26,7 +26,7 @@ func TestFilterAnd(t *testing.T) { // non-empty intersection fa := &filterAnd{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "a", }, @@ -45,7 +45,7 @@ func TestFilterAnd(t *testing.T) { fieldName: "foo", prefix: "abc", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "a", }, @@ -60,7 +60,7 @@ func TestFilterAnd(t *testing.T) { fieldName: "foo", prefix: "bc", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "a", }, @@ -71,7 +71,7 @@ func TestFilterAnd(t *testing.T) { // the last filter mismatch fa = &filterAnd{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "abc", }, @@ -86,7 +86,7 @@ func TestFilterAnd(t *testing.T) { // empty intersection fa = &filterAnd{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "foo", }, @@ -105,7 +105,7 @@ func TestFilterAnd(t *testing.T) { fieldName: "foo", prefix: "abc", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "foo", }, diff --git a/lib/logstorage/filter_not_test.go b/lib/logstorage/filter_not_test.go index c65b89df7..b07c0b274 100644 --- a/lib/logstorage/filter_not_test.go +++ b/lib/logstorage/filter_not_test.go @@ -25,7 +25,7 @@ func TestFilterNot(t *testing.T) { // match fn := &filterNot{ - f: &phraseFilter{ + f: &filterPhrase{ fieldName: "foo", phrase: "", }, @@ -33,7 +33,7 @@ func TestFilterNot(t *testing.T) { testFilterMatchForColumns(t, columns, fn, "foo", []int{0, 1, 2, 3, 4, 6, 7, 8, 9}) fn = &filterNot{ - f: &phraseFilter{ + f: &filterPhrase{ fieldName: "foo", phrase: "a", }, @@ -41,7 +41,7 @@ func TestFilterNot(t *testing.T) { testFilterMatchForColumns(t, columns, fn, "foo", []int{5}) fn = &filterNot{ - f: &phraseFilter{ + f: &filterPhrase{ fieldName: "non-existing-field", phrase: "foobar", }, @@ -66,7 +66,7 @@ func TestFilterNot(t *testing.T) { // mismatch fn = &filterNot{ - f: &phraseFilter{ + f: &filterPhrase{ fieldName: "non-existing-field", phrase: "", }, diff --git a/lib/logstorage/filter_or_test.go b/lib/logstorage/filter_or_test.go index 297bd19b5..3377d09f2 100644 --- a/lib/logstorage/filter_or_test.go +++ b/lib/logstorage/filter_or_test.go @@ -26,7 +26,7 @@ func TestFilterOr(t *testing.T) { // non-empty union fo := &filterOr{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "23", }, @@ -45,7 +45,7 @@ func TestFilterOr(t *testing.T) { fieldName: "foo", prefix: "abc", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "23", }, @@ -60,7 +60,7 @@ func TestFilterOr(t *testing.T) { fieldName: "foo", prefix: "xabc", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "23", }, @@ -71,7 +71,7 @@ func TestFilterOr(t *testing.T) { // first non-empty result, second empty result fo = &filterOr{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "23", }, @@ -86,7 +86,7 @@ func TestFilterOr(t *testing.T) { // first match all fo = &filterOr{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "a", }, @@ -105,7 +105,7 @@ func TestFilterOr(t *testing.T) { fieldName: "foo", prefix: "23", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "a", }, @@ -116,7 +116,7 @@ func TestFilterOr(t *testing.T) { // both empty results fo = &filterOr{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "x23", }, diff --git a/lib/logstorage/filter_test.go b/lib/logstorage/filter_test.go index aab49a682..6a05cf218 100644 --- a/lib/logstorage/filter_test.go +++ b/lib/logstorage/filter_test.go @@ -69,23 +69,23 @@ func TestComplexFilters(t *testing.T) { // (foobar AND NOT baz AND (abcdef OR xyz)) f := &filterAnd{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "foobar", }, &filterNot{ - f: &phraseFilter{ + f: &filterPhrase{ fieldName: "foo", phrase: "baz", }, }, &filterOr{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "abcdef", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "xyz", }, @@ -98,23 +98,23 @@ func TestComplexFilters(t *testing.T) { // (foobaz AND NOT baz AND (abcdef OR xyz)) f = &filterAnd{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "foobaz", }, &filterNot{ - f: &phraseFilter{ + f: &filterPhrase{ fieldName: "foo", phrase: "baz", }, }, &filterOr{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "abcdef", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "xyz", }, @@ -127,27 +127,27 @@ func TestComplexFilters(t *testing.T) { // (foobaz AND NOT baz AND (abcdef OR xyz OR a)) f = &filterAnd{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "foobar", }, &filterNot{ - f: &phraseFilter{ + f: &filterPhrase{ fieldName: "foo", phrase: "baz", }, }, &filterOr{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "abcdef", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "xyz", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "a", }, @@ -160,27 +160,27 @@ func TestComplexFilters(t *testing.T) { // (foobaz AND NOT qwert AND (abcdef OR xyz OR a)) f = &filterAnd{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "foobar", }, &filterNot{ - f: &phraseFilter{ + f: &filterPhrase{ fieldName: "foo", phrase: "qwert", }, }, &filterOr{ filters: []filter{ - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "abcdef", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "xyz", }, - &phraseFilter{ + &filterPhrase{ fieldName: "foo", phrase: "a", }, @@ -225,7 +225,7 @@ func TestStreamFilter(t *testing.T) { testFilterMatchForColumns(t, columns, f, "foo", nil) } -func TestPhraseFilter(t *testing.T) { +func TestFilterPhrase(t *testing.T) { t.Run("single-row", func(t *testing.T) { columns := []column{ { @@ -243,56 +243,56 @@ func TestPhraseFilter(t *testing.T) { } // match - pf := &phraseFilter{ + pf := &filterPhrase{ fieldName: "foo", phrase: "abc", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "abc def", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "def", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "other column", phrase: "asdfdsf", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing-column", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0}) // mismatch - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "ab", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "other column", phrase: "sd", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing column", phrase: "abc", } @@ -328,80 +328,80 @@ func TestPhraseFilter(t *testing.T) { } // match - pf := &phraseFilter{ + pf := &filterPhrase{ fieldName: "foo", phrase: "abc", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "def", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: " def", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "abc def", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "other-column", phrase: "x", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "_msg", phrase: " 2 ", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing-column", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2}) // mismatch - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "abc def ", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "x", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "other-column", phrase: "foo", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing column", phrase: "x", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "_msg", phrase: "foo", } @@ -425,38 +425,38 @@ func TestPhraseFilter(t *testing.T) { } // match - pf := &phraseFilter{ + pf := &filterPhrase{ fieldName: "foo", phrase: "foobar", } testFilterMatchForColumns(t, columns, pf, "foo", []int{1, 3, 6}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "baz", } testFilterMatchForColumns(t, columns, pf, "foo", []int{3}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing-column", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2, 3, 4, 5, 6}) // mismatch - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "bar", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing column", phrase: "foobar", } @@ -483,50 +483,50 @@ func TestPhraseFilter(t *testing.T) { } // match - pf := &phraseFilter{ + pf := &filterPhrase{ fieldName: "foo", phrase: "a", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "НГКШ", } testFilterMatchForColumns(t, columns, pf, "foo", []int{8}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing-column", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "!,", } testFilterMatchForColumns(t, columns, pf, "foo", []int{9}) // mismatch - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "aa a", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "bar", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "@", } @@ -554,44 +554,44 @@ func TestPhraseFilter(t *testing.T) { } // match - pf := &phraseFilter{ + pf := &filterPhrase{ fieldName: "foo", phrase: "12", } testFilterMatchForColumns(t, columns, pf, "foo", []int{1, 5}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "0", } testFilterMatchForColumns(t, columns, pf, "foo", []int{3, 4}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing-column", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) // mismatch - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "bar", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "33", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "1234", } @@ -618,44 +618,44 @@ func TestPhraseFilter(t *testing.T) { } // match - pf := &phraseFilter{ + pf := &filterPhrase{ fieldName: "foo", phrase: "1234", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 4}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "0", } testFilterMatchForColumns(t, columns, pf, "foo", []int{1}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing-column", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) // mismatch - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "bar", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "33", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "123456", } @@ -682,44 +682,44 @@ func TestPhraseFilter(t *testing.T) { } // match - pf := &phraseFilter{ + pf := &filterPhrase{ fieldName: "foo", phrase: "1234", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 4}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "65536", } testFilterMatchForColumns(t, columns, pf, "foo", []int{3}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing-column", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}) // mismatch - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "bar", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "33", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "12345678901", } @@ -745,44 +745,44 @@ func TestPhraseFilter(t *testing.T) { } // match - pf := &phraseFilter{ + pf := &filterPhrase{ fieldName: "foo", phrase: "1234", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "12345678901", } testFilterMatchForColumns(t, columns, pf, "foo", []int{4}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing-column", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8}) // mismatch - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "bar", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "33", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "12345678901234567890", } @@ -808,86 +808,86 @@ func TestPhraseFilter(t *testing.T) { } // match - pf := &phraseFilter{ + pf := &filterPhrase{ fieldName: "foo", phrase: "1234", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 4}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "1234.5678901", } testFilterMatchForColumns(t, columns, pf, "foo", []int{4}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "5678901", } testFilterMatchForColumns(t, columns, pf, "foo", []int{4}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "-65536", } testFilterMatchForColumns(t, columns, pf, "foo", []int{3}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "65536", } testFilterMatchForColumns(t, columns, pf, "foo", []int{3}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing-column", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8}) // mismatch - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "bar", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "-1234", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "+1234", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "123", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "5678", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "33", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "12345678901234567890", } @@ -916,74 +916,74 @@ func TestPhraseFilter(t *testing.T) { } // match - pf := &phraseFilter{ + pf := &filterPhrase{ fieldName: "foo", phrase: "127.0.0.1", } testFilterMatchForColumns(t, columns, pf, "foo", []int{2, 4, 5, 7}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "127", } testFilterMatchForColumns(t, columns, pf, "foo", []int{2, 4, 5, 6, 7, 8}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "127.0.0", } testFilterMatchForColumns(t, columns, pf, "foo", []int{2, 4, 5, 7}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "2.3", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "0", } testFilterMatchForColumns(t, columns, pf, "foo", []int{1, 2, 4, 5, 6, 7, 8}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing-column", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}) // mismatch - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "bar", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "5", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "127.1", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "27.0", } testFilterMatchForColumns(t, columns, pf, "foo", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "foo", phrase: "255.255.255.255", } @@ -1009,64 +1009,64 @@ func TestPhraseFilter(t *testing.T) { } // match - pf := &phraseFilter{ + pf := &filterPhrase{ fieldName: "_msg", phrase: "2006-01-02T15:04:05.005Z", } testFilterMatchForColumns(t, columns, pf, "_msg", []int{4}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "_msg", phrase: "2006-01", } testFilterMatchForColumns(t, columns, pf, "_msg", []int{0, 1, 2, 3, 4, 5, 6, 7, 8}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "_msg", phrase: "002Z", } testFilterMatchForColumns(t, columns, pf, "_msg", []int{1}) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "non-existing-column", phrase: "", } testFilterMatchForColumns(t, columns, pf, "_msg", []int{0, 1, 2, 3, 4, 5, 6, 7, 8}) // mimatch - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "_msg", phrase: "bar", } testFilterMatchForColumns(t, columns, pf, "_msg", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "_msg", phrase: "", } testFilterMatchForColumns(t, columns, pf, "_msg", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "_msg", phrase: "2006-03-02T15:04:05.005Z", } testFilterMatchForColumns(t, columns, pf, "_msg", nil) - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "_msg", phrase: "06", } testFilterMatchForColumns(t, columns, pf, "_msg", nil) // This filter shouldn't match row=4, since it has different string representation of the timestamp - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "_msg", phrase: "2006-01-02T16:04:05.005+01:00", } testFilterMatchForColumns(t, columns, pf, "_msg", nil) // This filter shouldn't match row=4, since it contains too many digits for millisecond part - pf = &phraseFilter{ + pf = &filterPhrase{ fieldName: "_msg", phrase: "2006-01-02T15:04:05.00500Z", } diff --git a/lib/logstorage/parser.go b/lib/logstorage/parser.go index fc8e4f286..b989c2314 100644 --- a/lib/logstorage/parser.go +++ b/lib/logstorage/parser.go @@ -418,7 +418,7 @@ func parseFilterForPhrase(lex *lexer, phrase, fieldName string) (filter, error) return f, nil } // The phrase is a search phrase. - f := &phraseFilter{ + f := &filterPhrase{ fieldName: fieldName, phrase: phrase, } diff --git a/lib/logstorage/parser_test.go b/lib/logstorage/parser_test.go index 616e57cf2..9089fb837 100644 --- a/lib/logstorage/parser_test.go +++ b/lib/logstorage/parser_test.go @@ -404,7 +404,7 @@ func TestParseFilterRegexp(t *testing.T) { f(`"foo(bar|baz),x[y]"`, `foo(bar|baz),x[y]`) } -func TestParseAnyCasePhraseFilter(t *testing.T) { +func TestParseAnyCaseFilterPhrase(t *testing.T) { f := func(s, fieldNameExpected, phraseExpected string) { t.Helper() q, err := ParseQuery(s) @@ -456,16 +456,16 @@ func TestParseAnyCaseFilterPrefix(t *testing.T) { f(`"abc-de.fg":i("foo-bar*baz *"*)`, `abc-de.fg`, `foo-bar*baz *`) } -func TestParsePhraseFilter(t *testing.T) { +func TestParseFilterPhrase(t *testing.T) { f := func(s, fieldNameExpected, phraseExpected string) { t.Helper() q, err := ParseQuery(s) if err != nil { t.Fatalf("unexpected error: %s", err) } - fp, ok := q.f.(*phraseFilter) + fp, ok := q.f.(*filterPhrase) if !ok { - t.Fatalf("unexpected filter type; got %T; want *phraseFilter; filter: %s", q.f, q.f) + t.Fatalf("unexpected filter type; got %T; want *filterPhrase; filter: %s", q.f, q.f) } if fp.fieldName != fieldNameExpected { t.Fatalf("unexpected fieldName; got %q; want %q", fp.fieldName, fieldNameExpected)