|
35 | 35 | import java.util.List; |
36 | 36 | import java.util.Map; |
37 | 37 | import java.util.Objects; |
| 38 | +import java.util.concurrent.ExecutionException; |
38 | 39 | import java.util.concurrent.TimeUnit; |
39 | 40 | import java.util.stream.Collectors; |
| 41 | +import org.junit.Assert; |
40 | 42 | import org.junit.BeforeClass; |
41 | 43 | import org.junit.Test; |
42 | 44 | import org.junit.runner.RunWith; |
@@ -238,21 +240,28 @@ private void assertResultIds(Pipeline.Snapshot snapshot, String... ids) { |
238 | 240 | // --- DISABLE query expansion --- |
239 | 241 |
|
240 | 242 | // query |
241 | | - // TODO(search) enable with backend support |
242 | | - // @Test |
243 | | - // public void searchWithLanguageCode() throws Exception { |
244 | | - // Pipeline pipeline = |
245 | | - // firestore |
246 | | - // .pipeline() |
247 | | - // .collection(COLLECTION_NAME) |
248 | | - // .search( |
249 | | - // Search.withQuery("waffles") |
250 | | - // .withLanguageCode("en") |
251 | | - // .withQueryEnhancement(Search.QueryEnhancement.DISABLED)); |
252 | | - // |
253 | | - // Pipeline.Snapshot snapshot = pipeline.execute().get(); |
254 | | - // assertResultIds(snapshot, "goldenWaffle"); |
255 | | - // } |
| 243 | + @Test |
| 244 | + public void searchWithLanguageCode() throws Exception { |
| 245 | + Pipeline pipeline = |
| 246 | + firestore |
| 247 | + .pipeline() |
| 248 | + .collection(COLLECTION_NAME) |
| 249 | + .search(Search.withQuery("waffles").withLanguageCode("en")); |
| 250 | + |
| 251 | + Pipeline.Snapshot snapshot = pipeline.execute().get(); |
| 252 | + assertResultIds(snapshot, "goldenWaffle"); |
| 253 | + } |
| 254 | + |
| 255 | + @Test |
| 256 | + public void searchWithInvalidLanguageCode() throws Exception { |
| 257 | + Pipeline pipeline = |
| 258 | + firestore |
| 259 | + .pipeline() |
| 260 | + .collection(COLLECTION_NAME) |
| 261 | + .search(Search.withQuery("waffles").withLanguageCode("unknown")); |
| 262 | + |
| 263 | + Assert.assertThrows(ExecutionException.class, () -> pipeline.execute().get()); |
| 264 | + } |
256 | 265 |
|
257 | 266 | @Test |
258 | 267 | public void searchFullDocument() throws Exception { |
@@ -584,69 +593,64 @@ public void sort_byDistance() throws Exception { |
584 | 593 | // } |
585 | 594 |
|
586 | 595 | // limit |
587 | | - // TODO(search) enable with backend support |
588 | | - // @Test |
589 | | - // public void limit_limitsTheNumberOfDocumentsReturned() throws Exception { |
590 | | - // Pipeline pipeline = |
591 | | - // firestore |
592 | | - // .pipeline() |
593 | | - // .collection(COLLECTION_NAME) |
594 | | - // .search( |
595 | | - // Search.withQuery(constant(true)) |
596 | | - // .withSort( |
597 | | - // field("location").geoDistance(new GeoPoint(39.6985, |
598 | | - // -105.024)).ascending()) |
599 | | - // .withLimit(5) |
600 | | - // .withQueryEnhancement(Search.QueryEnhancement.DISABLED)); |
601 | | - // |
602 | | - // Pipeline.Snapshot snapshot = pipeline.execute().get(); |
603 | | - // assertResultIds(snapshot, "solTacos", "lotusBlossomThai", "goldenWaffle"); |
604 | | - // } |
| 596 | + @Test |
| 597 | + public void limit_limitsTheNumberOfDocumentsReturned() throws Exception { |
| 598 | + Pipeline pipeline = |
| 599 | + firestore |
| 600 | + .pipeline() |
| 601 | + .collection(COLLECTION_NAME) |
| 602 | + .search( |
| 603 | + Search.withQuery( |
| 604 | + field("location") |
| 605 | + .geoDistance(new GeoPoint(39.6985, -105.024)) |
| 606 | + .lessThanOrEqual(100000000)) |
| 607 | + .withSort(geoDistance("location", new GeoPoint(39.6985, -105.024)).ascending()) |
| 608 | + .withLimit(3)); |
605 | 609 |
|
606 | | - // @Test |
607 | | - // public void limit_limitsTheNumberOfDocumentsRetrieved() throws Exception { |
608 | | - // Pipeline pipeline = |
609 | | - // firestore |
610 | | - // .pipeline() |
611 | | - // .collection(COLLECTION_NAME) |
612 | | - // .search( |
613 | | - // Search.withQuery(documentMatches("chicken")) |
614 | | - // .withRetrievalDepth(3)); |
615 | | - //// .withQueryEnhancement(Search.QueryEnhancement.DISABLED)); |
616 | | - // |
617 | | - // Pipeline.Snapshot snapshot = pipeline.execute().get(); |
618 | | - // assertResultIds(snapshot, "eastsideChicken", "lotusBlossomThai", "goldenWaffle"); |
619 | | - // |
620 | | - // pipeline = |
621 | | - // firestore |
622 | | - // .pipeline() |
623 | | - // .collection(COLLECTION_NAME) |
624 | | - // .search( |
625 | | - // Search.withQuery(documentMatches("chicken"))); |
626 | | - //// .withQueryEnhancement(Search.QueryEnhancement.DISABLED)); |
627 | | - // |
628 | | - // snapshot = pipeline.execute().get(); |
629 | | - // assertResultIds(snapshot, "eastsideChicken", "lotusBlossomThai", "goldenWaffle", |
630 | | - // "eastsideCantina"); |
631 | | - // } |
| 610 | + Pipeline.Snapshot snapshot = pipeline.execute().get(); |
| 611 | + assertResultIds(snapshot, "solTacos", "lotusBlossomThai", "mileHighCatch"); |
| 612 | + } |
632 | 613 |
|
633 | | - // offset |
634 | | - // TODO(search) enable with backend support |
635 | | - // @Test |
636 | | - // public void offset_skipsNDocuments() throws Exception { |
637 | | - // Pipeline pipeline = |
638 | | - // firestore |
639 | | - // .pipeline() |
640 | | - // .collection(COLLECTION_NAME) |
641 | | - // .search( |
642 | | - // Search.withQuery(constant(true)) |
643 | | - // .withLimit(2) |
644 | | - // .withOffset(2) |
645 | | - // .withQueryEnhancement(Search.QueryEnhancement.DISABLED)); |
646 | | - // |
647 | | - // Pipeline.Snapshot snapshot = pipeline.execute().get(); |
648 | | - // assertResultIds(snapshot, "eastsideChicken", "eastsideTacos"); |
649 | | - // } |
| 614 | + @Test |
| 615 | + public void limit_limitsTheNumberOfDocumentsScoredViaRetrievalDepth() throws Exception { |
| 616 | + Pipeline pipeline = |
| 617 | + firestore |
| 618 | + .pipeline() |
| 619 | + .collection(COLLECTION_NAME) |
| 620 | + .search( |
| 621 | + Search.withQuery(documentMatches("taco")) |
| 622 | + .withAddFields(score().as("score")) |
| 623 | + .withSort(score().descending()) |
| 624 | + .withRetrievalDepth(2)); |
| 625 | + |
| 626 | + Pipeline.Snapshot snapshot = pipeline.execute().get(); |
| 627 | + assertResultIds(snapshot, "solTacos", "eastsideTacos"); |
| 628 | + |
| 629 | + pipeline = |
| 630 | + firestore |
| 631 | + .pipeline() |
| 632 | + .collection(COLLECTION_NAME) |
| 633 | + .search( |
| 634 | + Search.withQuery(documentMatches("taco")) |
| 635 | + .withAddFields(score().as("score")) |
| 636 | + .withSort(score().descending()) |
| 637 | + .withRetrievalDepth(1)); |
| 638 | + |
| 639 | + snapshot = pipeline.execute().get(); |
| 640 | + assertResultIds(snapshot, "eastsideTacos"); |
| 641 | + } |
| 642 | + |
| 643 | + @Test |
| 644 | + public void offset_skipsNDocuments() throws Exception { |
| 645 | + Pipeline pipeline = |
| 646 | + firestore |
| 647 | + .pipeline() |
| 648 | + .collection(COLLECTION_NAME) |
| 649 | + .search(Search.withQuery("chicken").withLimit(2).withOffset(2)); |
| 650 | + |
| 651 | + Pipeline.Snapshot snapshot = pipeline.execute().get(); |
| 652 | + assertResultIds(snapshot, "goldenWaffle"); |
| 653 | + } |
650 | 654 |
|
651 | 655 | // ========================================================================= |
652 | 656 | // Snippet |
|
0 commit comments