-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathnodejs-documents-query-stream.js
More file actions
183 lines (173 loc) · 5.5 KB
/
Copy pathnodejs-documents-query-stream.js
File metadata and controls
183 lines (173 loc) · 5.5 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright (c) 2015-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
*/
var should = require('should');
//var should = require('chai').should();
var testconfig = require('../etc/test-config-qa.js');
var marklogic = require('../');
var q = marklogic.queryBuilder;
var db = marklogic.createDatabaseClient(testconfig.restReaderConnection);
var dbWriter = marklogic.createDatabaseClient(testconfig.restWriterConnection);
var dbAdmin = marklogic.createDatabaseClient(testconfig.restAdminConnection);
describe('Document query stream test', function () {
before(function (done) {
this.timeout(10000);
dbWriter.documents.write({
uri: '/test/query/matchDir/doc1.json',
collections: ['matchCollection1'],
contentType: 'application/json',
content: {
title: 'Vannevar Bush',
popularity: 5,
id: '0011',
date: '2005-01-01',
price: {
amt: 0.1
},
p: 'Vannevar Bush wrote an article for The Atlantic Monthly'
}
}, {
uri: '/test/query/matchDir/doc2.json',
collections: ['matchCollection1', 'matchCollection2'],
contentType: 'application/json',
content: {
title: 'The Bush article',
popularity: 4,
id: '0012',
date: '2006-02-02',
price: {
amt: 0.12
},
p: 'The Bush article described a device called a Memex'
}
}, {
uri: '/test/query/matchDir/doc3.json',
collections: ['matchCollection2'],
contentType: 'application/json',
content: {
title: 'For 1945',
popularity: 3,
id: '0013',
date: '2007-03-03',
price: {
amt: 1.23
},
p: 'For 1945, the thoughts expressed in the Atlantic Monthly were groundbreaking'
}
}, {
uri: '/test/query/matchDir/doc4.json',
collections: [],
contentType: 'application/json',
content: {
title: 'Vannevar served',
popularity: 5,
id: '0024',
date: '2008-04-04',
price: {
amt: 12.34
},
p: 'Vannevar served as a prominent policymaker and public intellectual'
}
}, {
uri: '/test/query/matchList/doc5.json',
collections: ['matchList'],
contentType: 'application/json',
content: {
title: 'The memex',
popularity: 5,
id: '0026',
date: '2009-05-05',
price: {
amt: 123.45
},
p: 'The Memex, unfortunately, had no automated search feature'
}
}).
result(function (response) {
done();
}, done);
});
it('should do word query', function (done) {
db.documents.query(
q.where(
q.word('title', 'vannevar bush')
)
).
stream().
on('data', function (data) {
data.content.id.should.equal('0011');
}).
on('end', function () {
done();
}, done);
});
it('should do simple parse', function (done) {
db.documents.query(
q.where(
q.parsedFrom('intitle:"The memex"',
q.parseBindings(
q.value('title', q.bind('intitle'))
)
)
)
).
stream().
on('data', function (data) {
data.content.id.should.equal('0026');
}).
on('end', function () {
done();
}, done);
});
it('should do extract with include-with-ancestors', function (done) {
db.documents.query(
q.where(
q.word('title', '1945')
).
slice(1, 10,
q.extract({
selected: 'include-with-ancestors',
paths: [
'/node("id")'
]
})
)
).
stream().
on('data', function (data) {
//console.log(data);
data.content.id.should.equal('0013');
}).
on('end', function () {
done();
}, done);
});
it('should do collections query', function (done) {
var count = 0;
var str = '';
var chunks = [];
db.documents.query(
q.where(
q.collection('matchCollection1')
)
.slice(0, 5)
)
.stream()
.on('data', function (chunk) {
count++;
})
.on('end', function () {
//console.log(count);
count.should.equal(2);
done();
}, done);
});
it('should delete all documents', function (done) {
dbAdmin.documents.removeAll({
all: true
}).
result(function (response) {
done();
}, done);
});
});