github.com/weaviate/weaviate@v1.24.6/test/modules/text2vec-contextionary/near_text_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 "os" 16 "reflect" 17 "testing" 18 19 "github.com/weaviate/weaviate/test/helper" 20 graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql" 21 "github.com/weaviate/weaviate/test/helper/sample-schema/books" 22 "github.com/weaviate/weaviate/test/helper/sample-schema/multishard" 23 ) 24 25 func Test_Text2Vec_NearText(t *testing.T) { 26 helper.SetupClient(os.Getenv(weaviateNode1Endpoint)) 27 booksClass := books.ClassContextionaryVectorizer() 28 multiShardClass := multishard.ClassContextionaryVectorizer() 29 helper.CreateClass(t, booksClass) 30 helper.CreateClass(t, multiShardClass) 31 defer helper.DeleteClass(t, booksClass.Class) 32 defer helper.DeleteClass(t, multiShardClass.Class) 33 34 t.Run("import data", func(t *testing.T) { 35 for _, book := range books.Objects() { 36 helper.CreateObject(t, book) 37 helper.AssertGetObjectEventually(t, book.Class, book.ID) 38 } 39 for _, multi := range multishard.Objects() { 40 helper.CreateObject(t, multi) 41 helper.AssertGetObjectEventually(t, multi.Class, multi.ID) 42 } 43 }) 44 45 t.Run("nearText with sorting, asc", func(t *testing.T) { 46 query := ` 47 { 48 Get { 49 Books( 50 nearText: {concepts: ["novel"]} 51 sort: [{path: ["title"], order: asc}] 52 ) { 53 title 54 } 55 } 56 }` 57 58 expected := []interface{}{ 59 map[string]interface{}{"title": "Dune"}, 60 map[string]interface{}{"title": "Project Hail Mary"}, 61 map[string]interface{}{"title": "The Lord of the Ice Garden"}, 62 } 63 result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query) 64 received := result.Get("Get", "Books").AsSlice() 65 if !reflect.DeepEqual(expected, received) { 66 t.Errorf("sort objects expected = %v, received %v", expected, received) 67 } 68 }) 69 70 t.Run("nearText with sorting, desc", func(t *testing.T) { 71 query := ` 72 { 73 Get { 74 Books( 75 nearText: {concepts: ["novel"]} 76 sort: [{path: ["title"], order: desc}] 77 ) { 78 title 79 } 80 } 81 }` 82 83 expected := []interface{}{ 84 map[string]interface{}{"title": "The Lord of the Ice Garden"}, 85 map[string]interface{}{"title": "Project Hail Mary"}, 86 map[string]interface{}{"title": "Dune"}, 87 } 88 result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query) 89 received := result.Get("Get", "Books").AsSlice() 90 if !reflect.DeepEqual(expected, received) { 91 t.Errorf("sort objects expected = %v, received %v", expected, received) 92 } 93 }) 94 }