MCPcopy Create free account
hub / github.com/couchbase/cbft / TestCollectionSearchRequest

Function TestCollectionSearchRequest

pindex_bleve_test.go:713–774  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

711}
712
713func TestCollectionSearchRequest(t *testing.T) {
714 testCache := getTestCache()
715 tests := []struct {
716 indexName string
717 collections []string
718 qNumDisjuncts int
719 qField string
720 qTerm []string
721 }{
722 {
723 indexName: "ftsIndexA",
724 collections: []string{"colA"},
725 qField: "_$scope_$collection",
726 qTerm: []string{"_$suid_$cuidA"},
727 qNumDisjuncts: 1,
728 },
729 {
730 indexName: "ftsIndexB",
731 collections: []string{"colA", "colB", "colC"},
732 qField: "_$scope_$collection",
733 qTerm: []string{"_$suid_$cuidA", "_$suid_$cuidB", "_$suid_$cuidC"},
734 qNumDisjuncts: 3,
735 },
736 }
737
738 var sr *SearchRequest
739 err := json.Unmarshal([]byte(`{"query": {"query": "california"}, "size": 4, "from": 5}`), &sr)
740 if err != nil {
741 t.Fatal(err)
742 }
743
744 for _, test := range tests {
745 sr.Collections = test.collections
746 bsr, err := sr.ConvertToBleveSearchRequest()
747 _, bsr.Query = sr.decorateQuery(test.indexName, bsr.Query, testCache)
748 if err != nil {
749 t.Fatal(err)
750 }
751 switch qq := bsr.Query.(type) {
752 case *query.ConjunctionQuery:
753 if len(qq.Conjuncts) != 2 {
754 t.Fatalf("Exception in conjunction query, number of conjunct clauses: %v",
755 len(qq.Conjuncts))
756 }
757 dqs := qq.Conjuncts[1].(*query.DisjunctionQuery)
758 if len(dqs.Disjuncts) != test.qNumDisjuncts {
759 t.Fatalf("Exception in disjunction query, number of disjunct clauses: %v",
760 len(dqs.Disjuncts))
761 }
762
763 for i, dq := range dqs.Disjuncts {
764 mq := dq.(*query.MatchQuery)
765 if mq.Match != test.qTerm[i] || mq.FieldVal != test.qField {
766 t.Fatalf("Exception in disjunction should query: %v, %v",
767 mq.Match, mq.FieldVal)
768 }
769 }
770 default:

Callers

nothing calls this directly

Calls 4

decorateQueryMethod · 0.95
getTestCacheFunction · 0.85
UnmarshalMethod · 0.80

Tested by

no test coverage detected