@@ -31,7 +31,8 @@ const fullTextHelper = () => {
31
31
const request = {
32
32
method : "POST" ,
33
33
body : {
34
- subject : subjects [ i ]
34
+ subject : subjects [ i ] ,
35
+ comment : subjects [ i ] ,
35
36
} ,
36
37
path : "/1/classes/TestObject"
37
38
} ;
@@ -280,42 +281,83 @@ describe('Parse.Query Full Text Search testing', () => {
280
281
} ) ;
281
282
282
283
describe_only_db ( 'mongo' ) ( 'Parse.Query Full Text Search testing' , ( ) => {
283
- it ( 'fullTextSearch: $search, only one text index' , ( done ) => {
284
- return reconfigureServer ( {
285
- appId : 'test' ,
286
- restAPIKey : 'test' ,
287
- publicServerURL : 'http://localhost:8378/1' ,
288
- databaseAdapter : new MongoStorageAdapter ( { uri : mongoURI } )
284
+ it ( 'fullTextSearch: does not create text index if compound index exist' , ( done ) => {
285
+ fullTextHelper ( ) . then ( ( ) => {
286
+ return databaseAdapter . dropAllIndexes ( 'TestObject' ) ;
289
287
} ) . then ( ( ) => {
290
- return rp . post ( {
291
- url : 'http://localhost:8378/1/batch' ,
292
- body : {
293
- requests : [
294
- {
295
- method : "POST" ,
296
- body : {
297
- subject : "coffee is java"
298
- } ,
299
- path : "/1/classes/TestObject"
300
- } ,
301
- {
302
- method : "POST" ,
303
- body : {
304
- subject : "java is coffee"
305
- } ,
306
- path : "/1/classes/TestObject"
288
+ return databaseAdapter . getIndexes ( 'TestObject' ) ;
289
+ } ) . then ( ( indexes ) => {
290
+ expect ( indexes . length ) . toEqual ( 1 ) ;
291
+ return databaseAdapter . createIndex ( 'TestObject' , { subject : 'text' , comment : 'text' } ) ;
292
+ } ) . then ( ( ) => {
293
+ return databaseAdapter . getIndexes ( 'TestObject' ) ;
294
+ } ) . then ( ( indexes ) => {
295
+ expect ( indexes . length ) . toEqual ( 2 ) ;
296
+ const where = {
297
+ subject : {
298
+ $text : {
299
+ $search : {
300
+ $term : 'coffee'
307
301
}
308
- ]
309
- } ,
310
- json : true ,
302
+ }
303
+ }
304
+ } ;
305
+ return rp . post ( {
306
+ url : 'http://localhost:8378/1/classes/TestObject' ,
307
+ json : { where, '_method' : 'GET' } ,
311
308
headers : {
312
309
'X-Parse-Application-Id' : 'test' ,
313
310
'X-Parse-REST-API-Key' : 'test'
314
311
}
315
312
} ) ;
313
+ } ) . then ( ( resp ) => {
314
+ expect ( resp . results . length ) . toEqual ( 3 ) ;
315
+ return databaseAdapter . getIndexes ( 'TestObject' ) ;
316
+ } ) . then ( ( indexes ) => {
317
+ expect ( indexes . length ) . toEqual ( 2 ) ;
318
+ rp . get ( {
319
+ url : 'http://localhost:8378/1/schemas/TestObject' ,
320
+ headers : {
321
+ 'X-Parse-Application-Id' : 'test' ,
322
+ 'X-Parse-Master-Key' : 'test' ,
323
+ } ,
324
+ json : true ,
325
+ } , ( error , response , body ) => {
326
+ expect ( body . indexes . _id_ ) . toBeDefined ( ) ;
327
+ expect ( body . indexes . _id_ . _id ) . toEqual ( 1 ) ;
328
+ expect ( body . indexes . subject_text_comment_text ) . toBeDefined ( ) ;
329
+ expect ( body . indexes . subject_text_comment_text . subject ) . toEqual ( 'text' ) ;
330
+ expect ( body . indexes . subject_text_comment_text . comment ) . toEqual ( 'text' ) ;
331
+ done ( ) ;
332
+ } ) ;
333
+ } ) . catch ( done . fail ) ;
334
+ } ) ;
335
+
336
+ it ( 'fullTextSearch: does not create text index if schema compound index exist' , ( done ) => {
337
+ fullTextHelper ( ) . then ( ( ) => {
338
+ return databaseAdapter . dropAllIndexes ( 'TestObject' ) ;
316
339
} ) . then ( ( ) => {
317
- return databaseAdapter . createIndex ( 'TestObject' , { random : 'text' } ) ;
340
+ return databaseAdapter . getIndexes ( 'TestObject' ) ;
341
+ } ) . then ( ( indexes ) => {
342
+ expect ( indexes . length ) . toEqual ( 1 ) ;
343
+ return rp . put ( {
344
+ url : 'http://localhost:8378/1/schemas/TestObject' ,
345
+ json : true ,
346
+ headers : {
347
+ 'X-Parse-Application-Id' : 'test' ,
348
+ 'X-Parse-REST-API-Key' : 'test' ,
349
+ 'X-Parse-Master-Key' : 'test' ,
350
+ } ,
351
+ body : {
352
+ indexes : {
353
+ text_test : { subject : 'text' , comment : 'text' } ,
354
+ } ,
355
+ } ,
356
+ } ) ;
318
357
} ) . then ( ( ) => {
358
+ return databaseAdapter . getIndexes ( 'TestObject' ) ;
359
+ } ) . then ( ( indexes ) => {
360
+ expect ( indexes . length ) . toEqual ( 2 ) ;
319
361
const where = {
320
362
subject : {
321
363
$text : {
@@ -334,12 +376,26 @@ describe_only_db('mongo')('Parse.Query Full Text Search testing', () => {
334
376
}
335
377
} ) ;
336
378
} ) . then ( ( resp ) => {
337
- fail ( `Should not be more than one text index: ${ JSON . stringify ( resp ) } ` ) ;
338
- done ( ) ;
339
- } ) . catch ( ( err ) => {
340
- expect ( err . error . code ) . toEqual ( Parse . Error . INTERNAL_SERVER_ERROR ) ;
341
- done ( ) ;
342
- } ) ;
379
+ expect ( resp . results . length ) . toEqual ( 3 ) ;
380
+ return databaseAdapter . getIndexes ( 'TestObject' ) ;
381
+ } ) . then ( ( indexes ) => {
382
+ expect ( indexes . length ) . toEqual ( 2 ) ;
383
+ rp . get ( {
384
+ url : 'http://localhost:8378/1/schemas/TestObject' ,
385
+ headers : {
386
+ 'X-Parse-Application-Id' : 'test' ,
387
+ 'X-Parse-Master-Key' : 'test' ,
388
+ } ,
389
+ json : true ,
390
+ } , ( error , response , body ) => {
391
+ expect ( body . indexes . _id_ ) . toBeDefined ( ) ;
392
+ expect ( body . indexes . _id_ . _id ) . toEqual ( 1 ) ;
393
+ expect ( body . indexes . text_test ) . toBeDefined ( ) ;
394
+ expect ( body . indexes . text_test . subject ) . toEqual ( 'text' ) ;
395
+ expect ( body . indexes . text_test . comment ) . toEqual ( 'text' ) ;
396
+ done ( ) ;
397
+ } ) ;
398
+ } ) . catch ( done . fail ) ;
343
399
} ) ;
344
400
345
401
it ( 'fullTextSearch: $diacriticSensitive - false' , ( done ) => {
0 commit comments