Skip to content

Commit 0a5af86

Browse files
committed
MLE-15458 : Specify search options when using fromSearchDocs with the Node Client
1 parent 4d8fe87 commit 0a5af86

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

lib/plan-builder-generated.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8699,9 +8699,9 @@ fromSQL(...args) {
86998699
*/
87008700
fromSearchDocs(...args) {
87018701
const namer = bldrbase.getNamer(args, 'query');
8702-
const paramdefs = [['query', [types.XsString, types.CtsQuery], true, false], ['qualifierName', [types.XsString], false, false]];
8702+
const paramdefs = [['query', [types.XsString, types.CtsQuery], true, false], ['qualifierName', [types.XsString], false, false], ['option', [PlanSearchOption], false, false]];
87038703
const checkedArgs = (namer !== null) ?
8704-
bldrbase.makeNamedArgs(namer, 'PlanBuilder.fromSearchDocs', 1, new Set(['query', 'qualifierName']), paramdefs, args) :
8704+
bldrbase.makeNamedArgs(namer, 'PlanBuilder.fromSearchDocs', 1, new Set(['query', 'qualifierName', 'option']), paramdefs, args) :
87058705
bldrbase.makePositionalArgs('PlanBuilder.fromSearchDocs', 1, false, paramdefs, args);
87068706
return new PlanAccessPlan(null, 'op', 'from-search-docs', checkedArgs);
87078707

test-basic/plan-search.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ describe('search', function() {
183183
// console.log(JSON.stringify(output, null, 2));
184184
});
185185

186-
describe('tests for new scoring methods - bm25, random and zero.', function() {
186+
describe('tests for new scoring methods - bm25, random and zero using fromSearch.', function() {
187187
before(function (done) {
188188
if(serverConfiguration.serverVersion < 12) {
189189
this.skip();
@@ -253,4 +253,70 @@ describe('search', function() {
253253
}).catch(error => done(error));
254254
});
255255
});
256+
257+
describe('tests for new scoring methods - bm25, random and zero using fromSearchDocs.', function() {
258+
before(function (done) {
259+
if(serverConfiguration.serverVersion < 12) {
260+
this.skip();
261+
}
262+
done();
263+
});
264+
265+
it('should search documents with bm25', function(done) {
266+
execPlan(
267+
p.fromSearchDocs('Armstrong', null, {scoreMethod:'bm25', bm25LengthWeight:0.75})
268+
).then(function(response) {
269+
assert(response.columns != null)
270+
assert(response.rows != null)
271+
done();
272+
}).catch(error => done(error));
273+
});
274+
275+
it('should throw error with invalid bm25LengthWeight', function(done) {
276+
execPlan(
277+
p.fromSearchDocs('Armstrong', null, {scoreMethod:'bm25', bm25LengthWeight:87})
278+
).catch(error => {
279+
try{
280+
assert(error.body.errorResponse.message.toString().includes('Invalid option "bm25-length-weight=87'));
281+
done();
282+
} catch(error){
283+
done(error);
284+
}
285+
});
286+
});
287+
288+
it('should throw error with string values for bm25LengthWeight', function(done) {
289+
try {
290+
execPlan(
291+
p.fromSearchDocs('Armstrong', null, {scoreMethod:'bm25', bm25LengthWeight: 'abc'})
292+
);
293+
} catch(error){
294+
assert(error.message.toString().includes('bm25LengthWeight must be a number'));
295+
done();
296+
}
297+
});
298+
299+
it('should search documents with zero scoring method', function(done) {
300+
execPlan(
301+
p.fromSearchDocs('Armstrong', null, { scoreMethod: 'zero'})
302+
).then(function(response) {
303+
assert(response.columns != null)
304+
assert(response.rows != null)
305+
for(let i=0; i<response.rows.length; i++){
306+
assert(response.rows[i].score.value == 0)
307+
}
308+
done();
309+
}).catch(error => done(error));
310+
});
311+
312+
it('should search documents with random scoring method', function(done) {
313+
execPlan(
314+
p.fromSearchDocs('Armstrong', null, { scoreMethod: 'random'})
315+
).then(function(response) {
316+
assert(response.columns != null)
317+
assert(response.rows != null)
318+
done();
319+
}).catch(error => done(error));
320+
});
321+
});
256322
});

0 commit comments

Comments
 (0)