@@ -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