moved filter logic into query
This commit is contained in:
parent
15d372ac55
commit
3b458f6ff1
4 changed files with 94 additions and 70 deletions
|
|
@ -55,17 +55,17 @@ var (
|
|||
)
|
||||
|
||||
func TestNewQuery(t *testing.T) {
|
||||
_, err := NewQuery("String:1 String:2", AND)
|
||||
_, err := NewQuery("String:1 String:2")
|
||||
if err == nil {
|
||||
t.Error("multiple AND fields")
|
||||
}
|
||||
|
||||
_, err = NewQuery("String:1 sdcs Int:1", AND)
|
||||
_, err = NewQuery("String:1 sdcs Int:1")
|
||||
if err == nil {
|
||||
t.Error("invalid match")
|
||||
}
|
||||
|
||||
_, err = NewQuery("String:1 sort:Bool:ASC", AND)
|
||||
_, err = NewQuery("String:1 sort:Bool:ASC")
|
||||
if err == nil {
|
||||
t.Error("invalid sort")
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ const (
|
|||
|
||||
func TestFilter(t *testing.T) {
|
||||
f1 := makefilter(data)
|
||||
q1, err := NewQuery(filter1, AND)
|
||||
q1, err := NewQuery("AND " + filter1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -94,7 +94,7 @@ func TestFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
f2 := makefilter(data)
|
||||
q2, err := NewQuery(filter2, OR)
|
||||
q2, err := NewQuery("OR " + filter2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -110,7 +110,7 @@ func TestFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
f3 := makefilter(data)
|
||||
q3, err := NewQuery(filter2, NOT)
|
||||
q3, err := NewQuery("NOT " + filter2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -130,7 +130,7 @@ const (
|
|||
|
||||
func TestSortFilter(t *testing.T) {
|
||||
f1 := makefilter(benchData)
|
||||
q1, err := NewQuery(sort1, AND)
|
||||
q1, err := NewQuery(sort1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -146,7 +146,7 @@ func TestSortFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
f2 := makefilter(benchData)
|
||||
q2, err := NewQuery(sort2, OR)
|
||||
q2, err := NewQuery("OR " + sort2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -162,7 +162,7 @@ func TestSortFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
f3 := makefilter(benchData)
|
||||
q3, err := NewQuery(sort2, NOT)
|
||||
q3, err := NewQuery("NOT " + sort2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -179,7 +179,7 @@ func TestSortFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGenericFilter(t *testing.T) {
|
||||
q1, err := NewQuery(filter1, AND)
|
||||
q1, err := NewQuery(filter1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -198,7 +198,7 @@ func TestGenericFilter(t *testing.T) {
|
|||
t.Error("f1[1] != data[1]")
|
||||
}
|
||||
|
||||
q2, err := NewQuery(filter2, OR)
|
||||
q2, err := NewQuery("OR " + filter2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -217,7 +217,7 @@ func TestGenericFilter(t *testing.T) {
|
|||
t.Error("f2[1] != data[2]")
|
||||
}
|
||||
|
||||
q3, err := NewQuery(filter2, NOT)
|
||||
q3, err := NewQuery("NOT " + filter2)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
@ -235,67 +235,67 @@ func TestGenericFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
const (
|
||||
simple = "Bool:true"
|
||||
simple = "OR Bool:true"
|
||||
comp = "String:*st* Bool:false Struct.Struct.Int:1"
|
||||
compOr = "Int:47 Bool:false Struct.String:s1*"
|
||||
sortOnly = "sort:Int:desc"
|
||||
simpleSort = "sort:Int:desc Bool:true"
|
||||
compOr = "OR Int:47 Bool:false Struct.String:s1*"
|
||||
sortOnly = "OR sort:Int:desc"
|
||||
simpleSort = "OR sort:Int:desc Bool:true"
|
||||
compSort = "sort:Int:desc String:*st* Bool:false Struct.Struct.Int:1"
|
||||
compOrSort = "sort:Int:desc Int:47 Bool:false Struct.String:s1*"
|
||||
compOrSort = "OR sort:Int:desc Int:47 Bool:false Struct.String:s1*"
|
||||
)
|
||||
|
||||
func BenchmarkNewQuerySimple(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
NewQuery(simple, OR)
|
||||
NewQuery(simple)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNewQueryComplex(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
NewQuery(comp, AND)
|
||||
NewQuery(comp)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNewQueryComplexOr(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
NewQuery(compOr, OR)
|
||||
NewQuery(compOr)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNewQuerySort(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
NewQuery(sortOnly, OR)
|
||||
NewQuery(sortOnly)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNewQuerySortSimple(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
NewQuery(simpleSort, OR)
|
||||
NewQuery(simpleSort)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNewQuerySortComplex(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
NewQuery(compSort, AND)
|
||||
NewQuery(compSort)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNewQuerySortComplexOr(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
for i := 0; i < b.N; i++ {
|
||||
NewQuery(compOrSort, OR)
|
||||
NewQuery(compOrSort)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkFilterSimple(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery(simple, OR)
|
||||
q, err := NewQuery(simple)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
|
@ -307,7 +307,7 @@ func BenchmarkFilterSimple(b *testing.B) {
|
|||
|
||||
func BenchmarkFilterComplex(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery(comp, AND)
|
||||
q, err := NewQuery(comp)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
|
@ -319,7 +319,7 @@ func BenchmarkFilterComplex(b *testing.B) {
|
|||
|
||||
func BenchmarkFilterComplexOr(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery(compOr, OR)
|
||||
q, err := NewQuery(compOr)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
|
@ -331,7 +331,7 @@ func BenchmarkFilterComplexOr(b *testing.B) {
|
|||
|
||||
func BenchmarkSort(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery(sortOnly, OR)
|
||||
q, err := NewQuery(sortOnly)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
|
@ -343,7 +343,7 @@ func BenchmarkSort(b *testing.B) {
|
|||
|
||||
func BenchmarkSortFilterSimple(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery(simpleSort, OR)
|
||||
q, err := NewQuery(simpleSort)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
|
@ -355,7 +355,7 @@ func BenchmarkSortFilterSimple(b *testing.B) {
|
|||
|
||||
func BenchmarkSortFilterComplex(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery(compSort, AND)
|
||||
q, err := NewQuery(compSort)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
|
@ -367,7 +367,7 @@ func BenchmarkSortFilterComplex(b *testing.B) {
|
|||
|
||||
func BenchmarkSortFilterComplexOr(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery(compOrSort, OR)
|
||||
q, err := NewQuery(compOrSort)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
|
@ -379,7 +379,7 @@ func BenchmarkSortFilterComplexOr(b *testing.B) {
|
|||
|
||||
func BenchmarkGenericFilterSimple(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery(simple, OR)
|
||||
q, err := NewQuery(simple)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
|
@ -390,7 +390,7 @@ func BenchmarkGenericFilterSimple(b *testing.B) {
|
|||
|
||||
func BenchmarkGenericFilterComplex(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery(comp, AND)
|
||||
q, err := NewQuery(comp)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
|
@ -401,7 +401,7 @@ func BenchmarkGenericFilterComplex(b *testing.B) {
|
|||
|
||||
func BenchmarkGenericFilterComplexOr(b *testing.B) {
|
||||
b.ReportAllocs()
|
||||
q, err := NewQuery(compOr, OR)
|
||||
q, err := NewQuery(compOr)
|
||||
if err != nil {
|
||||
b.Error(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue