github.com/weaviate/weaviate@v1.24.6/test/acceptance/graphql_resolvers/unindexed_property_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/go-openapi/strfmt" 18 "github.com/stretchr/testify/assert" 19 "github.com/stretchr/testify/require" 20 "github.com/weaviate/weaviate/client/objects" 21 clschema "github.com/weaviate/weaviate/client/schema" 22 "github.com/weaviate/weaviate/entities/models" 23 "github.com/weaviate/weaviate/entities/schema" 24 "github.com/weaviate/weaviate/test/helper" 25 testhelper "github.com/weaviate/weaviate/test/helper" 26 graphqlhelper "github.com/weaviate/weaviate/test/helper/graphql" 27 ) 28 29 func Test_UnindexedProperty(t *testing.T) { 30 className := "NoIndexTestClass" 31 32 defer func() { 33 delParams := clschema.NewSchemaObjectsDeleteParams().WithClassName(className) 34 delResp, err := helper.Client(t).Schema.SchemaObjectsDelete(delParams, nil) 35 helper.AssertRequestOk(t, delResp, err, nil) 36 }() 37 38 t.Run("creating a class with two string props", func(t *testing.T) { 39 vFalse := false 40 vTrue := true 41 42 c := &models.Class{ 43 Class: className, 44 ModuleConfig: map[string]interface{}{ 45 "text2vec-contextionary": map[string]interface{}{ 46 "vectorizeClassName": true, 47 }, 48 }, 49 Properties: []*models.Property{ 50 { 51 Name: "name", 52 DataType: schema.DataTypeText.PropString(), 53 Tokenization: models.PropertyTokenizationWhitespace, 54 IndexFilterable: &vTrue, 55 IndexSearchable: &vTrue, 56 }, 57 { 58 Name: "hiddenName", 59 DataType: schema.DataTypeText.PropString(), 60 Tokenization: models.PropertyTokenizationWhitespace, 61 IndexFilterable: &vFalse, 62 IndexSearchable: &vFalse, 63 }, 64 }, 65 } 66 67 params := clschema.NewSchemaObjectsCreateParams().WithObjectClass(c) 68 resp, err := helper.Client(t).Schema.SchemaObjectsCreate(params, nil) 69 helper.AssertRequestOk(t, resp, err, nil) 70 }) 71 72 t.Run("creating an object", func(t *testing.T) { 73 params := objects.NewObjectsCreateParams().WithBody( 74 &models.Object{ 75 Class: className, 76 ID: "f5ffb60f-4c13-4d07-a395-829b2396c7b9", 77 Properties: map[string]interface{}{ 78 "name": "elephant", 79 "hiddenName": "zebra", 80 }, 81 }) 82 resp, err := helper.Client(t).Objects.ObjectsCreate(params, nil) 83 helper.AssertRequestOk(t, resp, err, nil) 84 }) 85 86 assertGetObjectEventually(t, "f5ffb60f-4c13-4d07-a395-829b2396c7b9") 87 88 t.Run("searching for the indexed prop", func(t *testing.T) { 89 query := ` 90 { 91 Get { 92 NoIndexTestClass(where:{ 93 operator: Equal, 94 valueText: "elephant" 95 path:["name"] 96 }){ 97 name 98 hiddenName 99 } 100 } 101 } 102 ` 103 104 result := graphqlhelper.AssertGraphQL(t, helper.RootAuth, query) 105 objects := result.Get("Get", className).AsSlice() 106 107 expected := []interface{}{ 108 map[string]interface{}{"name": "elephant", "hiddenName": "zebra"}, 109 } 110 111 assert.ElementsMatch(t, expected, objects) 112 }) 113 114 t.Run("searching for the non-indexed prop", func(t *testing.T) { 115 query := ` 116 { 117 Get { 118 NoIndexTestClass(where:{ 119 operator: Equal, 120 valueText: "zebra" 121 path:["hiddenName"] 122 }){ 123 name 124 hiddenName 125 } 126 } 127 } 128 ` 129 res, err := graphqlhelper.QueryGraphQL(t, helper.RootAuth, "", query, nil) 130 require.Nil(t, err) 131 assert.True(t, len(res.Errors) > 0, "this query should be impossible as the field was not indexed") 132 }) 133 } 134 135 func assertGetObjectEventually(t *testing.T, uuid strfmt.UUID) *models.Object { 136 var ( 137 resp *objects.ObjectsGetOK 138 err error 139 ) 140 141 checkThunk := func() interface{} { 142 resp, err = helper.Client(t).Objects.ObjectsGet(objects.NewObjectsGetParams().WithID(uuid), nil) 143 return err == nil 144 } 145 146 testhelper.AssertEventuallyEqual(t, true, checkThunk) 147 148 var object *models.Object 149 150 helper.AssertRequestOk(t, resp, err, func() { 151 object = resp.Payload 152 }) 153 154 return object 155 }