@@ -25,7 +25,6 @@ test('can search', t => {
2525 const start = Date . now ( )
2626 idx . SEARCH ( [ 'gremlins' ] , { DOCUMENTS : true } ) . then ( res => {
2727 t . pass ( 'Search took ' + ( Date . now ( ) - start ) + 'ms' )
28- // console.log(JSON.stringify(res, null, 2))
2928 console . log (
3029 JSON . stringify (
3130 res . RESULT . map ( item => item . _doc . title ) ,
@@ -51,10 +50,44 @@ test('can IMPORT a serialized index into an empty search-index', t => {
5150 name : sandbox + indexName + '2' ,
5251 stopwords : eng
5352 } )
54- t . plan ( 1 )
53+ t . plan ( 2 )
5554 const moviesDump = JSON . parse ( readFileSync ( sandbox + indexName + '-dump' ) )
56- const start = Date . now ( )
55+ let start = Date . now ( )
56+
5757 idx2
5858 . IMPORT ( moviesDump )
5959 . then ( ( ) => t . pass ( 'index IMPORTed in ' + ( Date . now ( ) - start ) + 'ms' ) )
60+ . then ( ( ) => {
61+ console . log ( 'closing yo' )
62+ start = Date . now ( )
63+ idx2 . INDEX . STORE . close ( ) . then ( ( ) =>
64+ t . pass ( 'index closed in ' + ( Date . now ( ) - start ) + 'ms' )
65+ )
66+ } )
67+ } )
68+
69+ test ( 'can reopen index' , t => {
70+ t . plan ( 2 )
71+ let start = Date . now ( )
72+ const idx3 = new SearchIndex ( {
73+ name : sandbox + indexName + '2' ,
74+ stopwords : eng
75+ } )
76+ idx3 . EVENTS . on ( 'ready' , ( ) => {
77+ t . pass ( 'index reopened and ready in ' + ( Date . now ( ) - start ) + 'ms' )
78+ idx3 . SEARCH ( [ 'gremlins' ] , { DOCUMENTS : true } ) . then ( res => {
79+ t . pass (
80+ 'Time from reopening to getting results from new index took ' +
81+ ( Date . now ( ) - start ) +
82+ 'ms'
83+ )
84+ console . log (
85+ JSON . stringify (
86+ res . RESULT . map ( item => item . _doc . title ) ,
87+ null ,
88+ 2
89+ )
90+ )
91+ } )
92+ } )
6093} )
0 commit comments