@@ -326,5 +326,84 @@ describe('FT.SEARCH', () => {
326326 }
327327 ) ;
328328 } , GLOBAL . SERVERS . OPEN ) ;
329+
330+ testUtils . testWithClient ( 'properly parse content/nocontent scenarios' , async client => {
331+
332+ const indexName = 'foo' ;
333+ await client . ft . create (
334+ indexName ,
335+ {
336+ itemOrder : {
337+ type : 'NUMERIC' ,
338+ SORTABLE : true ,
339+ } ,
340+ name : {
341+ type : 'TEXT' ,
342+ } ,
343+ } ,
344+ {
345+ ON : 'HASH' ,
346+ PREFIX : 'item:' ,
347+ }
348+ ) ;
349+
350+ await client . hSet ( "item:1" , {
351+ itemOrder : 1 ,
352+ name : "First item" ,
353+ } ) ;
354+
355+ await client . hSet ( "item:2" , {
356+ itemOrder : 2 ,
357+ name : "Second item" ,
358+ } ) ;
359+
360+ await client . hSet ( "item:3" , {
361+ itemOrder : 3 ,
362+ name : "Third item" ,
363+ } ) ;
364+
365+ // Search with SORTBY and LIMIT
366+ let result = await client . ft . search ( indexName , "@itemOrder:[0 10]" , {
367+ SORTBY : {
368+ BY : "itemOrder" ,
369+ DIRECTION : "ASC" ,
370+ } ,
371+ LIMIT : {
372+ from : 0 ,
373+ size : 1 , // only get first result
374+ } ,
375+ } ) ;
376+
377+ assert . equal ( result . total , 3 , "Result's `total` value reflects the total scanned documents" ) ;
378+ assert . equal ( result . documents . length , 1 ) ;
379+ let doc = result . documents [ 0 ] ;
380+ assert . equal ( doc . id , 'item:1' ) ;
381+ assert . equal ( doc . value . itemOrder , '1' ) ;
382+ assert . equal ( doc . value . name , 'First item' ) ;
383+
384+ await client . del ( "item:3" ) ;
385+
386+ // Search again after removing item:3
387+ result = await client . ft . search ( indexName , "@itemOrder:[0 10]" , {
388+ SORTBY : {
389+ BY : "itemOrder" ,
390+ DIRECTION : "ASC" ,
391+ } ,
392+ LIMIT : {
393+ from : 0 ,
394+ size : 1 , // only get first result
395+ } ,
396+ } ) ;
397+
398+ assert . equal ( result . total , 2 , "Result's `total` value reflects the total scanned documents" ) ;
399+ assert . equal ( result . documents . length , 1 ) ;
400+ doc = result . documents [ 0 ] ;
401+ assert . equal ( doc . id , 'item:1' ) ;
402+ assert . equal ( doc . value . itemOrder , '1' ) ;
403+ assert . equal ( doc . value . name , 'First item' ) ;
404+
405+
406+ } , GLOBAL . SERVERS . OPEN ) ;
407+
329408 } ) ;
330409} ) ;
0 commit comments