github.com/weaviate/weaviate@v1.24.6/test/acceptance/graphql_resolvers/local_aggregate_hybrid_search_test.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package test 13 14 import ( 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 "github.com/stretchr/testify/require" 19 "github.com/weaviate/weaviate/test/helper" 20 graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql" 21 ) 22 23 func aggregationWithHybridSearch(t *testing.T) { 24 t.Run("without search vector", func(t *testing.T) { 25 query := ` 26 { 27 Aggregate { 28 Company 29 ( 30 objectLimit: 3 31 hybrid: { 32 alpha: 0.5 33 query: "Apple" 34 } 35 ) 36 { 37 name { 38 topOccurrences { 39 value 40 } 41 } 42 } 43 } 44 }` 45 result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query).Get("Aggregate", "Company").AsSlice() 46 require.Len(t, result, 1) 47 topOccur := result[0].(map[string]interface{})["name"].(map[string]interface{})["topOccurrences"].([]interface{}) 48 require.Len(t, topOccur, 3) 49 assert.Contains(t, topOccur, map[string]interface{}{"value": "Apple"}) 50 assert.Contains(t, topOccur, map[string]interface{}{"value": "Apple Inc."}) 51 assert.Contains(t, topOccur, map[string]interface{}{"value": "Apple Incorporated"}) 52 }) 53 54 t.Run("with grouping, sparse search only", func(t *testing.T) { 55 query := ` 56 { 57 Aggregate { 58 Company 59 ( 60 groupBy: "name" 61 hybrid: { 62 alpha: 0 63 query: "Google" 64 } 65 ) 66 { 67 name { 68 topOccurrences { 69 value 70 } 71 } 72 } 73 } 74 }` 75 76 type object = map[string]interface{} 77 78 result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query).Get("Aggregate", "Company").AsSlice() 79 require.Len(t, result, 3) 80 assert.Contains(t, result, object{ 81 "name": object{ 82 "topOccurrences": []interface{}{ 83 object{"value": "Google"}, 84 }, 85 }, 86 }) 87 assert.Contains(t, result, object{ 88 "name": object{ 89 "topOccurrences": []interface{}{ 90 object{"value": "Google Inc."}, 91 }, 92 }, 93 }) 94 assert.Contains(t, result, object{ 95 "name": object{ 96 "topOccurrences": []interface{}{ 97 object{"value": "Google Incorporated"}, 98 }, 99 }, 100 }) 101 }) 102 }