@@ -7365,68 +7365,104 @@ describe.skipClassic('Pipeline search', () => {
73657365 // });
73667366 } ) ;
73677367
7368- // TODO(search) enable with backend support
7369- // describe('limit', () => {
7370- // it('limits the number of documents returned', async () => {
7371- // const ppl = firestore
7372- // .pipeline()
7373- // .collection(COLLECTION_NAME)
7374- // .search({
7375- // query: constant(true),
7376- // sort: field('location')
7377- // .geoDistance(new GeoPoint(39.6985, -105.024))
7378- // .ascending(),
7379- // limit: 5,
7380- // queryEnhancement: 'disabled',
7381- // });
7382- //
7383- // const snapshot = await ppl.execute();
7384- // expectResults(
7385- // snapshot,
7386- // 'solTacos',
7387- // 'lotusBlossomThai',
7388- // 'goldenWaffle',
7389- // );
7390- // });
7391- // it('limits the number of documents scored', async () => {
7392- // const ppl = firestore
7393- // .pipeline()
7394- // .collection(COLLECTION_NAME)
7395- // .search({
7396- // query: field('menu').matches(
7397- // 'chicken OR tacos OR fish OR waffles',
7398- // ),
7399- // retrievalDepth: 6,
7400- // queryEnhancement: 'disabled',
7401- // });
7402- //
7403- // const snapshot = await ppl.execute();
7404- // expectResults(
7405- // snapshot,
7406- // 'eastsideChicken',
7407- // 'eastsideTacos',
7408- // 'solTacos',
7409- // 'mileHighCatch',
7410- // );
7411- // });
7412- // });
7368+ describe ( 'languageCode' , ( ) => {
7369+ const rquery = 'al pastor' ;
7370+ it ( 'en' , async ( ) => {
7371+ const ppl = firestore
7372+ . pipeline ( )
7373+ . collection ( COLLECTION_NAME )
7374+ . search ( {
7375+ query : documentMatches ( rquery ) ,
7376+ sort : score ( ) . descending ( ) ,
7377+ languageCode : 'en' ,
7378+ // queryEnhancement: 'disabled'
7379+ } ) ;
74137380
7414- // TODO(search) enable with backend support
7415- // describe('offset', () => {
7416- // it('skips N documents', async () => {
7417- // const ppl = firestore
7418- // .pipeline()
7419- // .collection(COLLECTION_NAME)
7420- // .search({
7421- // query: constant(true),
7422- // limit: 2,
7423- // offset: 2,
7424- // queryEnhancement: 'disabled',
7425- // });
7426- //
7427- // const snapshot = await ppl.execute();
7428- // expectResults(snapshot, 'eastsideChicken', 'eastsideTacos');
7429- // });
7381+ const snapshot = await ppl . execute ( ) ;
7382+ expectResults ( snapshot , 'solTacos' ) ;
7383+ } ) ;
7384+
7385+ it ( 'unknown' , async ( ) => {
7386+ const ppl = firestore
7387+ . pipeline ( )
7388+ . collection ( COLLECTION_NAME )
7389+ . search ( {
7390+ query : documentMatches ( rquery ) ,
7391+ sort : score ( ) . descending ( ) ,
7392+ languageCode : 'unknown' ,
7393+ // queryEnhancement: 'disabled'
7394+ } ) ;
7395+
7396+ await expect ( ppl . execute ( ) ) . to . be . rejectedWith (
7397+ / 3 I N V A L I D _ A R G U M E N T .* / ,
7398+ ) ;
7399+ } ) ;
7400+ } ) ;
7401+
7402+ describe ( 'limit' , ( ) => {
7403+ it ( 'limits the number of documents returned' , async ( ) => {
7404+ const ppl = firestore
7405+ . pipeline ( )
7406+ . collection ( COLLECTION_NAME )
7407+ . search ( {
7408+ query : field ( 'location' )
7409+ . geoDistance ( new GeoPoint ( 39.6985 , - 105.024 ) )
7410+ . lessThanOrEqual ( 100000000 ) ,
7411+ sort : field ( 'location' )
7412+ . geoDistance ( new GeoPoint ( 39.6985 , - 105.024 ) )
7413+ . ascending ( ) ,
7414+ limit : 3 ,
7415+ // queryEnhancement: 'disabled'
7416+ } ) ;
7417+
7418+ const snapshot = await ppl . execute ( ) ;
7419+ expectResults (
7420+ snapshot ,
7421+ 'solTacos' ,
7422+ 'lotusBlossomThai' ,
7423+ 'mileHighCatch' ,
7424+ ) ;
7425+ } ) ;
7426+
7427+ it ( 'limits the number of documents scored via retrievalDepth' , async ( ) => {
7428+ const commonSearchParams = {
7429+ query : documentMatches ( 'taco' ) ,
7430+ addFields : [ score ( ) . as ( 'score' ) ] ,
7431+ sort : score ( ) . descending ( ) ,
7432+ // queryEnhancement: 'disabled' as QueryEnhancement
7433+ } ;
7434+
7435+ let ppl = firestore
7436+ . pipeline ( )
7437+ . collection ( COLLECTION_NAME )
7438+ . search ( { ...commonSearchParams , retrievalDepth : 2 } ) ;
7439+
7440+ let snapshot = await ppl . execute ( ) ;
7441+ expectResults ( snapshot , 'solTacos' , 'eastsideTacos' ) ;
7442+
7443+ ppl = firestore
7444+ . pipeline ( )
7445+ . collection ( COLLECTION_NAME )
7446+ . search ( { ...commonSearchParams , retrievalDepth : 1 } ) ;
7447+
7448+ snapshot = await ppl . execute ( ) ;
7449+ expectResults ( snapshot , 'eastsideTacos' ) ;
7450+ } ) ;
7451+ } ) ;
7452+
7453+ describe ( 'offset' , ( ) => {
7454+ it ( 'skips N documents' , async ( ) => {
7455+ const ppl = firestore . pipeline ( ) . collection ( COLLECTION_NAME ) . search ( {
7456+ query : 'chicken' ,
7457+ limit : 2 ,
7458+ offset : 2 ,
7459+ // queryEnhancement: 'disabled'
7460+ } ) ;
7461+
7462+ const snapshot = await ppl . execute ( ) ;
7463+ expectResults ( snapshot , 'goldenWaffle' ) ;
7464+ } ) ;
7465+ } ) ;
74307466 // });
74317467 } ) ;
74327468
0 commit comments