@@ -75,7 +75,8 @@ describe("boolean search logic", () => {
75
75
} )
76
76
77
77
describe ( 'empty terms' , ( ) => {
78
- it ( `should exclude all results that do not match required terms` , async ( ) => {
78
+ it ( `should bring back all results
79
+ when empty string/array is passed` , async ( ) => {
79
80
80
81
const info = await view . get ( )
81
82
expect ( info . name ) . to . be . a ( 'string' )
@@ -93,18 +94,16 @@ describe("boolean search logic", () => {
93
94
let has = cursor . hasNext ( )
94
95
expect ( has ) . to . be . ok
95
96
96
- let result = await cursor . next ( )
97
- expect ( result . title ) . to . match ( / d o c / )
97
+ let result = await cursor . all ( )
98
+ expect ( result ) . to . have . length ( 2 )
98
99
} )
99
100
} )
100
101
101
- describe ( 'ANDS' , ( ) => {
102
- it ( `only bring back results that include required words and phrases` , async ( ) => {
103
-
102
+ describe ( 'ANDS' , async ( ) => {
103
+ it ( `should bring back only results matching AND'ed values
104
+ when +'ed PHRASE's are passed` , async ( ) => {
104
105
const info = await view . get ( )
105
106
expect ( info . name ) . to . be . a ( 'string' )
106
-
107
- /* phrase */
108
107
let query = {
109
108
view : info . name ,
110
109
collections : [ {
@@ -114,8 +113,8 @@ describe("boolean search logic", () => {
114
113
/* should match both results */
115
114
terms : '+"word"'
116
115
}
116
+
117
117
let aqlQuery = buildAQL ( query )
118
- expect ( Object . keys ( aqlQuery . bindVars ) ) . to . have . length ( 6 )
119
118
120
119
/* should match 2 documents */
121
120
let cursor = await db . query ( aqlQuery )
@@ -125,11 +124,6 @@ describe("boolean search logic", () => {
125
124
await cursor . next ( )
126
125
expect ( cursor . hasNext ( ) ) . to . not . be . ok
127
126
128
- /* should match 0 documents */
129
- query . terms = '+"wyuxaouw"'
130
- cursor = await db . query ( buildAQL ( query ) )
131
- expect ( cursor . hasNext ( ) ) . to . not . be . ok
132
-
133
127
/* should match 1 document */
134
128
query . terms = '+"in document"'
135
129
cursor = await db . query ( buildAQL ( query ) )
@@ -138,6 +132,7 @@ describe("boolean search logic", () => {
138
132
expect ( result ) . to . have . length ( 1 )
139
133
expect ( result [ 0 ] . title ) . to . equal ( 'doc A' )
140
134
135
+ /* should match 1 document */
141
136
query . terms = '+"across"'
142
137
cursor = await db . query ( buildAQL ( query ) )
143
138
expect ( cursor . hasNext ( ) ) . to . be . ok
@@ -146,37 +141,58 @@ describe("boolean search logic", () => {
146
141
expect ( result [ 0 ] . title ) . to . equal ( 'doc B' )
147
142
expect ( cursor . hasNext ( ) ) . to . not . be . ok
148
143
144
+ /* should match 0 documents */
145
+ query . terms = '+"wyuxaouw"'
146
+ cursor = await db . query ( buildAQL ( query ) )
147
+ expect ( cursor . hasNext ( ) ) . to . not . be . ok
149
148
149
+ /* should match 0 documents */
150
150
query . terms = '+"nowhere found"'
151
151
cursor = await db . query ( buildAQL ( query ) )
152
152
expect ( cursor . hasNext ( ) ) . to . not . be . ok
153
+ } )
154
+
155
+ it ( `should bring back only results matching AND'ed values
156
+ when +'ed TOKEN's are passed` , async ( ) => {
153
157
154
- /* tokens */
155
- query = {
158
+ const info = await view . get ( )
159
+ expect ( info . name ) . to . be . a ( 'string' )
160
+ let query = {
156
161
view : info . name ,
157
162
collections : [ {
158
163
name : collectionName ,
159
164
analyzer : 'text_en'
160
165
} ] ,
166
+ /* should match both results */
161
167
terms : '+word'
162
168
}
163
- aqlQuery = buildAQL ( query )
164
169
165
- expect ( Object . keys ( aqlQuery . bindVars ) ) . to . have . length ( 7 )
166
- expect ( aqlQuery . bindVars . value0 ) . to . equal ( 'word' )
167
- expect ( aqlQuery . bindVars . value1 ) . to . equal ( 'text_en' )
168
- expect ( aqlQuery . bindVars . value2 ) . to . equal ( 'text' )
169
- expect ( aqlQuery . bindVars . value3 ) . to . equal ( 1 )
170
- expect ( aqlQuery . bindVars . value4 ) . to . deep . equal ( { collections : [ collectionName ] } )
171
- expect ( aqlQuery . bindVars . value5 ) . to . equal ( 0 )
172
- expect ( aqlQuery . bindVars . value6 ) . to . equal ( 20 )
170
+ /* should bring back 2 document */
171
+ let aqlQuery = buildAQL ( query )
172
+ let cursor = await db . query ( aqlQuery )
173
+ expect ( cursor . hasNext ( ) ) . to . be . ok
174
+ let result = await cursor . all ( )
175
+ expect ( result ) . to . have . length ( 2 )
173
176
177
+ /* should bring back 1 document */
178
+ // in A
179
+ query . terms = 'not in only in is in'
180
+ aqlQuery = buildAQL ( query )
174
181
cursor = await db . query ( aqlQuery )
175
182
expect ( cursor . hasNext ( ) ) . to . be . ok
183
+ result = await cursor . all ( )
184
+ expect ( result ) . to . have . length ( 1 )
185
+ expect ( result [ 0 ] . title ) . to . equal ( 'doc A' )
176
186
177
- result = await cursor . next ( )
178
- expect ( result . title ) . to . deep . equal ( 'doc A' )
187
+ // sample B
188
+ /* should bring back 1 document, partially testing text_en analyzer */
189
+ query . terms = 'samples of things'
190
+ aqlQuery = buildAQL ( query )
191
+ cursor = await db . query ( aqlQuery )
179
192
expect ( cursor . hasNext ( ) ) . to . be . ok
193
+ result = await cursor . all ( )
194
+ expect ( result ) . to . have . length ( 1 )
195
+ expect ( result [ 0 ] . title ) . to . equal ( 'doc B' )
180
196
} )
181
197
} )
182
198
0 commit comments