@@ -22,40 +22,57 @@ const dataset = [
2222 {
2323 id : 123 ,
2424 title : "Pride and Prejudice" ,
25+ author : "Jane Austen" ,
2526 comment : "A great book" ,
26- genre : "romance" ,
27+ genre : [ "romance" ] ,
2728 } ,
2829 {
2930 id : 456 ,
3031 title : "Le Petit Prince" ,
32+ author : "Antoine de Saint-Exupéry" ,
3133 comment : "A french book about a prince that walks on little cute planets" ,
32- genre : "adventure" ,
34+ genre : [ "adventure" ] ,
3335 } ,
3436 {
3537 id : 2 ,
3638 title : "Le Rouge et le Noir" ,
39+ author : "Stendhal" ,
3740 comment : "Another french book" ,
38- genre : "romance" ,
41+ genre : [ "romance" ] ,
3942 } ,
4043 {
4144 id : 1 ,
4245 title : "Alice In Wonderland" ,
46+ author : "Lewis Carroll" ,
4347 comment : "A weird book" ,
44- genre : "adventure" ,
48+ genre : [ "adventure" ] ,
4549 } ,
4650 {
4751 id : 1344 ,
4852 title : "The Hobbit" ,
53+ author : "J.R.R. Tolkien" ,
4954 comment : "An awesome book" ,
50- genre : "sci fi" ,
55+ genre : [ "fantasy" , "adventure" ] ,
5156 } ,
5257 {
5358 id : 4 ,
5459 title : "Harry Potter and the Half-Blood Prince" ,
60+ author : "J.K. Rowling" ,
5561 comment : "The best book" ,
56- genre : "fantasy" ,
62+ genre : [ "fantasy" , "adventure" ] ,
63+ } ,
64+ {
65+ id : 5 ,
66+ title : "Harry Potter and the Deathly Hallows" ,
67+ author : "J.K. Rowling" ,
68+ genre : [ "fantasy" , "adventure" ] ,
69+ } ,
70+ {
71+ id : 42 ,
72+ title : "The Hitchhiker's Guide to the Galaxy" ,
73+ author : "Douglas Adams" ,
74+ genre : [ "sci fi" , "comedy" ] ,
5775 } ,
58- { id : 42 , title : "The Hitchhiker's Guide to the Galaxy" , genre : "fantasy" } ,
5976] ;
6077
6178afterAll ( ( ) => {
@@ -75,7 +92,7 @@ describe.each([
7592 const { taskUid : task2 } = await client . createIndex ( emptyIndex . uid ) ;
7693 await client . waitForTask ( task2 ) ;
7794
78- const newFilterableAttributes = [ "genre" , "title" , "id" ] ;
95+ const newFilterableAttributes = [ "genre" , "title" , "id" , "author" ] ;
7996 const { taskUid : task3 } : EnqueuedTask = await client
8097 . index ( index . uid )
8198 . updateSettings ( {
@@ -188,8 +205,9 @@ describe.each([
188205 {
189206 id : 4 ,
190207 title : "Harry Potter and the Half-Blood Prince" ,
208+ author : "J.K. Rowling" ,
191209 comment : "The best book" ,
192- genre : "fantasy" ,
210+ genre : [ "fantasy" , "adventure" ] ,
193211 } ,
194212 ] ) ;
195213 expect ( response ) . toHaveProperty ( "offset" , 1 ) ;
@@ -415,9 +433,9 @@ describe.each([
415433 facets : [ "genre" ] ,
416434 } ) ;
417435 expect ( response ) . toHaveProperty ( "facetDistribution" , {
418- genre : { fantasy : 2 } ,
436+ genre : { adventure : 3 , fantasy : 3 } ,
419437 } ) ;
420- expect ( response . hits . length ) . toEqual ( 2 ) ;
438+ expect ( response . hits . length ) . toEqual ( 3 ) ;
421439 } ) ;
422440
423441 test ( `${ permission } key: search with multiple filter and null query (placeholder)` , async ( ) => {
@@ -427,10 +445,13 @@ describe.each([
427445 facets : [ "genre" ] ,
428446 } ) ;
429447 expect ( response ) . toHaveProperty ( "facetDistribution" , {
430- genre : { fantasy : 2 } ,
448+ genre : {
449+ adventure : 3 ,
450+ fantasy : 3 ,
451+ } ,
431452 } ) ;
432- expect ( response . hits . length ) . toEqual ( 2 ) ;
433- expect ( response . estimatedTotalHits ) . toEqual ( 2 ) ;
453+ expect ( response . hits . length ) . toEqual ( 3 ) ;
454+ expect ( response . estimatedTotalHits ) . toEqual ( 3 ) ;
434455 } ) ;
435456
436457 test ( `${ permission } key: search with multiple filter and empty string query (placeholder)` , async ( ) => {
@@ -441,9 +462,9 @@ describe.each([
441462 } ) ;
442463
443464 expect ( response ) . toHaveProperty ( "facetDistribution" , {
444- genre : { fantasy : 2 } ,
465+ genre : { adventure : 3 , fantasy : 3 } ,
445466 } ) ;
446- expect ( response . hits . length ) . toEqual ( 2 ) ;
467+ expect ( response . hits . length ) . toEqual ( 3 ) ;
447468 } ) ;
448469
449470 test ( `${ permission } key: Try to search with wrong format filter` , async ( ) => {
@@ -492,9 +513,9 @@ describe.each([
492513 const client = await getClient ( permission ) ;
493514 const response = await client
494515 . index ( index . uid )
495- . search ( "" , { distinct : "genre " } ) ;
516+ . search ( "" , { distinct : "author " } ) ;
496517
497- expect ( response . hits . length ) . toEqual ( 4 ) ;
518+ expect ( response . hits . length ) . toEqual ( 7 ) ;
498519 } ) ;
499520
500521 test ( `${ permission } key: search with retrieveVectors to true` , async ( ) => {
@@ -539,6 +560,17 @@ describe.each([
539560 expect ( response . hits [ 0 ] ) . not . toHaveProperty ( "_vectors" ) ;
540561 } ) ;
541562
563+ test ( `${ permission } key: matches position contain indices` , async ( ) => {
564+ const client = await getClient ( permission ) ;
565+ const response = await client . index ( index . uid ) . searchGet ( "fantasy" , {
566+ showMatchesPosition : true ,
567+ } ) ;
568+ expect ( response . hits [ 0 ] . _matchesPosition ) . toEqual ( {
569+ genre : [ { start : 0 , length : 7 , indices : [ 0 ] } ] ,
570+ } ) ;
571+ } ) ;
572+
573+ // This test deletes the index, so following tests may fail if they need an existing index
542574 test ( `${ permission } key: Try to search on deleted index and fail` , async ( ) => {
543575 const client = await getClient ( permission ) ;
544576 const masterClient = await getClient ( "Master" ) ;
0 commit comments