-
Notifications
You must be signed in to change notification settings - Fork 16
/
ravendb_5669_test.go
142 lines (109 loc) · 3.02 KB
/
ravendb_5669_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package tests
import (
"testing"
ravendb "github.com/ravendb/ravendb-go-client"
"github.com/stretchr/testify/assert"
)
func ravendb5669WorkingTestWithDifferentSearchTermOrder(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
index := NewAnimalIndex()
err = store.ExecuteIndex(index, "")
assert.NoError(t, err)
ravendb5669storeAnimals(t, store, driver)
{
session := openSessionMust(t, store)
var results []*Animal
query := session.Advanced().QueryIndex(index.IndexName)
query.OpenSubclause()
query = query.WhereEquals("type", "Cat")
query = query.OrElse()
query = query.Search("name", "Peter*")
query = query.AndAlso()
query = query.Search("name", "Pan*")
query.CloseSubclause()
err = query.GetResults(&results)
assert.NoError(t, err)
assert.Equal(t, len(results), 1)
session.Close()
}
}
func ravendb5669workingTestWithSubclause(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
index := NewAnimalIndex()
err = store.ExecuteIndex(index, "")
assert.NoError(t, err)
ravendb5669storeAnimals(t, store, driver)
{
session := openSessionMust(t, store)
query := session.Advanced().QueryIndex(index.IndexName)
query.OpenSubclause()
{
query = query.WhereEquals("type", "Cat")
query = query.OrElse()
query.OpenSubclause()
{
query = query.Search("name", "Pan*")
query = query.AndAlso()
query = query.Search("name", "Peter*")
}
query = query.CloseSubclause()
}
query.CloseSubclause()
var results []*Animal
err = query.GetResults(&results)
assert.NoError(t, err)
assert.Equal(t, len(results), 1)
session.Close()
}
}
func ravendb5669storeAnimals(t *testing.T, store *ravendb.DocumentStore, driver *RavenTestDriver) {
var err error
{
session := openSessionMust(t, store)
animal1 := &Animal{
Name: "Peter Pan",
Type: "Dog",
}
animal2 := &Animal{
Name: "Peter Poo",
Type: "Dog",
}
animal3 := &Animal{
Name: "Peter Foo",
Type: "Dog",
}
err = session.Store(animal1)
assert.NoError(t, err)
err = session.Store(animal2)
assert.NoError(t, err)
err = session.Store(animal3)
assert.NoError(t, err)
err = session.SaveChanges()
assert.NoError(t, err)
session.Close()
}
driver.waitForIndexing(store, store.GetDatabase(), 0)
}
type Animal struct {
Type string `json:"type"`
Name string `json:"name"`
}
func NewAnimalIndex() *ravendb.IndexCreationTask {
res := ravendb.NewIndexCreationTask("Animal_Index")
res.Map = "from animal in docs.Animals select new { name = animal.name, type = animal.type }"
res.Analyze("name", "StandardAnalyzer")
res.Index("name", ravendb.FieldIndexingSearch)
return res
}
func TestRavenDB5669(t *testing.T) {
driver := createTestDriver(t)
destroy := func() { destroyDriver(t, driver) }
defer recoverTest(t, destroy)
// matches the order of Java tests
ravendb5669workingTestWithSubclause(t, driver)
ravendb5669WorkingTestWithDifferentSearchTermOrder(t, driver)
}