/
filter.go
120 lines (108 loc) · 3.99 KB
/
filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* _ _
*__ _____ __ ___ ___ __ _| |_ ___
*\ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
* \ V V / __/ (_| |\ V /| | (_| | || __/
* \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
*
* Copyright © 2016 - 2019 Weaviate. All rights reserved.
* LICENSE: https://github.com/creativesoftwarefdn/weaviate/blob/develop/LICENSE.md
* DESIGN & CONCEPT: Bob van Luijt (@bobvanluijt)
* CONTACT: hello@creativesoftwarefdn.org
*/
package fetch
import (
"fmt"
"github.com/creativesoftwarefdn/weaviate/database/schema/kind"
"github.com/creativesoftwarefdn/weaviate/graphqlapi/descriptions"
"github.com/creativesoftwarefdn/weaviate/graphqlapi/local/common_filters"
"github.com/graphql-go/graphql"
)
func whereFilterFields(k kind.Kind) graphql.InputObjectConfigFieldMap {
return graphql.InputObjectConfigFieldMap{
"class": &graphql.InputObjectFieldConfig{
Type: graphql.NewNonNull(whereInpObjClassInpObj(k)),
Description: descriptions.WhereClass,
},
"properties": &graphql.InputObjectFieldConfig{
Type: graphql.NewNonNull(graphql.NewList(whereInpObjPropertiesObj(k))),
Description: descriptions.WhereProperties,
},
"first": &graphql.InputObjectFieldConfig{
Type: graphql.Int,
Description: descriptions.First,
},
}
}
func whereInpObjPropertiesObj(k kind.Kind) *graphql.InputObject {
filterPropertiesElements := common_filters.BuildNew(fmt.Sprintf("WeaviateLocalFetch%s", k.TitleizedName()))
// Remove path and operands fields as they are not required here
delete(filterPropertiesElements, "path")
delete(filterPropertiesElements, "operands")
filterPropertiesElements["certainty"] = &graphql.InputObjectFieldConfig{
Type: graphql.Float,
Description: descriptions.WhereCertainty,
}
filterPropertiesElements["name"] = &graphql.InputObjectFieldConfig{
Type: graphql.String,
Description: descriptions.WhereName,
}
filterPropertiesElements["keywords"] = &graphql.InputObjectFieldConfig{
Type: graphql.NewList(keywordInpObj(fmt.Sprintf("LocalFetch%sWhereProperties", k.TitleizedName()))),
Description: descriptions.WhereKeywords,
}
networkFetchWhereInpObjPropertiesObj := graphql.NewInputObject(
graphql.InputObjectConfig{
Name: fmt.Sprintf("WeaviateLocalFetch%sWhereInpObjProperties", k.TitleizedName()),
Fields: filterPropertiesElements,
Description: descriptions.WhereProperties,
},
)
return networkFetchWhereInpObjPropertiesObj
}
func keywordInpObj(prefix string) *graphql.InputObject {
outputObject := graphql.NewInputObject(
graphql.InputObjectConfig{
Name: fmt.Sprintf("%sKeywordsInpObj", prefix),
Fields: graphql.InputObjectConfigFieldMap{
"value": &graphql.InputObjectFieldConfig{
Type: graphql.String,
Description: descriptions.WhereKeywordsValue,
},
"weight": &graphql.InputObjectFieldConfig{
Type: graphql.Float,
Description: descriptions.WhereKeywordsWeight,
},
},
Description: descriptions.WhereKeywordsInpObj,
},
)
return outputObject
}
func whereInpObjClassInpObj(k kind.Kind) *graphql.InputObject {
filterClassElements := graphql.InputObjectConfigFieldMap{
"name": &graphql.InputObjectFieldConfig{
Type: graphql.String,
Description: descriptions.WhereName,
},
"certainty": &graphql.InputObjectFieldConfig{
Type: graphql.Float,
Description: descriptions.WhereCertainty,
},
"keywords": &graphql.InputObjectFieldConfig{
Type: graphql.NewList(keywordInpObj(fmt.Sprintf("LocalFetch%sWhereClass", k.TitleizedName()))),
Description: descriptions.WhereKeywords,
},
"first": &graphql.InputObjectFieldConfig{
Type: graphql.Int,
Description: descriptions.First,
},
}
networkFetchWhereInpObjClassInpObj := graphql.NewInputObject(
graphql.InputObjectConfig{
Name: fmt.Sprintf("WeaviateLocalFetch%sWhereInpObjClassInpObj", k.TitleizedName()),
Fields: filterClassElements,
Description: descriptions.WhereClass,
},
)
return networkFetchWhereInpObjClassInpObj
}