Skip to content

Commit 93afdd8

Browse files
committed
test: AND/PHRASE
1 parent d97cd9e commit 93afdd8

File tree

1 file changed

+43
-27
lines changed

1 file changed

+43
-27
lines changed

tests/bool.ts

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ describe("boolean search logic", () => {
7575
})
7676

7777
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 () => {
7980

8081
const info = await view.get()
8182
expect(info.name).to.be.a('string')
@@ -93,18 +94,16 @@ describe("boolean search logic", () => {
9394
let has = cursor.hasNext()
9495
expect(has).to.be.ok
9596

96-
let result = await cursor.next()
97-
expect(result.title).to.match(/doc/)
97+
let result = await cursor.all()
98+
expect(result).to.have.length(2)
9899
})
99100
})
100101

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 () => {
104105
const info = await view.get()
105106
expect(info.name).to.be.a('string')
106-
107-
/* phrase */
108107
let query = {
109108
view: info.name,
110109
collections: [ {
@@ -114,8 +113,8 @@ describe("boolean search logic", () => {
114113
/* should match both results */
115114
terms: '+"word"'
116115
}
116+
117117
let aqlQuery = buildAQL(query)
118-
expect(Object.keys(aqlQuery.bindVars)).to.have.length(6)
119118

120119
/* should match 2 documents */
121120
let cursor = await db.query(aqlQuery)
@@ -125,11 +124,6 @@ describe("boolean search logic", () => {
125124
await cursor.next()
126125
expect(cursor.hasNext()).to.not.be.ok
127126

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-
133127
/* should match 1 document */
134128
query.terms = '+"in document"'
135129
cursor = await db.query(buildAQL(query))
@@ -138,6 +132,7 @@ describe("boolean search logic", () => {
138132
expect(result).to.have.length(1)
139133
expect(result[ 0 ].title).to.equal('doc A')
140134

135+
/* should match 1 document */
141136
query.terms = '+"across"'
142137
cursor = await db.query(buildAQL(query))
143138
expect(cursor.hasNext()).to.be.ok
@@ -146,37 +141,58 @@ describe("boolean search logic", () => {
146141
expect(result[ 0 ].title).to.equal('doc B')
147142
expect(cursor.hasNext()).to.not.be.ok
148143

144+
/* should match 0 documents */
145+
query.terms = '+"wyuxaouw"'
146+
cursor = await db.query(buildAQL(query))
147+
expect(cursor.hasNext()).to.not.be.ok
149148

149+
/* should match 0 documents */
150150
query.terms = '+"nowhere found"'
151151
cursor = await db.query(buildAQL(query))
152152
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 () => {
153157

154-
/* tokens */
155-
query = {
158+
const info = await view.get()
159+
expect(info.name).to.be.a('string')
160+
let query = {
156161
view: info.name,
157162
collections: [ {
158163
name: collectionName,
159164
analyzer: 'text_en'
160165
} ],
166+
/* should match both results */
161167
terms: '+word'
162168
}
163-
aqlQuery = buildAQL(query)
164169

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)
173176

177+
/* should bring back 1 document */
178+
// in A
179+
query.terms = 'not in only in is in'
180+
aqlQuery = buildAQL(query)
174181
cursor = await db.query(aqlQuery)
175182
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')
176186

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)
179192
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')
180196
})
181197
})
182198

0 commit comments

Comments
 (0)