29
29
@ After (ACCENT_REMOVAL )
30
30
public class ValidateSortingSearcher extends Searcher {
31
31
32
+ // TODO: Use SchemaInfo instead and validate with streaming as well
33
+
34
+ private final boolean isStreaming ;
35
+
32
36
private Map <String , AttributesConfig .Attribute > attributeNames = null ;
33
37
private String clusterName = "" ;
34
- private final boolean enabled ;
35
38
36
39
public ValidateSortingSearcher (ClusterConfig clusterConfig , AttributesConfig attributesConfig ) {
37
40
initAttributeNames (attributesConfig );
38
41
setClusterName (clusterConfig .clusterName ());
39
- enabled = clusterConfig .indexMode () ! = ClusterConfig .IndexMode .Enum .STREAMING ;
42
+ isStreaming = clusterConfig .indexMode () = = ClusterConfig .IndexMode .Enum .STREAMING ;
40
43
}
41
44
42
- public String getClusterName () {
43
- return clusterName ;
45
+ @ Override
46
+ public Result search (Query query , Execution execution ) {
47
+ ErrorMessage error = validate (query );
48
+ if (! isStreaming && error != null )
49
+ return new Result (query , error );
50
+ return execution .search (query );
44
51
}
45
52
46
- public void setClusterName (String clusterName ) {
47
- this .clusterName = clusterName ;
48
- }
53
+ public String getClusterName () { return clusterName ; }
49
54
50
- private Map < String , AttributesConfig . Attribute > getAttributeNames ( ) {
51
- return attributeNames ;
52
- }
55
+ public void setClusterName ( String clusterName ) { this . clusterName = clusterName ; }
56
+
57
+ private Map < String , AttributesConfig . Attribute > getAttributeNames () { return attributeNames ; }
53
58
54
59
public void setAttributeNames (Map <String , AttributesConfig .Attribute > attributeNames ) {
55
60
this .attributeNames = attributeNames ;
@@ -64,32 +69,6 @@ public void initAttributeNames(AttributesConfig config) {
64
69
setAttributeNames (attributes );
65
70
}
66
71
67
- @ Override
68
- public Result search (Query query , Execution execution ) {
69
- ErrorMessage e = validate (query );
70
- if (enabled && e != null ) {
71
- Result r = new Result (query );
72
- r .hits ().addError (e );
73
- return r ;
74
- }
75
- return execution .search (query );
76
- }
77
-
78
- private static Sorting .UcaSorter .Strength config2Strength (AttributesConfig .Attribute .Sortstrength .Enum s ) {
79
- if (s == AttributesConfig .Attribute .Sortstrength .PRIMARY ) {
80
- return Sorting .UcaSorter .Strength .PRIMARY ;
81
- } else if (s == AttributesConfig .Attribute .Sortstrength .SECONDARY ) {
82
- return Sorting .UcaSorter .Strength .SECONDARY ;
83
- } else if (s == AttributesConfig .Attribute .Sortstrength .TERTIARY ) {
84
- return Sorting .UcaSorter .Strength .TERTIARY ;
85
- } else if (s == AttributesConfig .Attribute .Sortstrength .QUATERNARY ) {
86
- return Sorting .UcaSorter .Strength .QUATERNARY ;
87
- } else if (s == AttributesConfig .Attribute .Sortstrength .IDENTICAL ) {
88
- return Sorting .UcaSorter .Strength .IDENTICAL ;
89
- }
90
- return Sorting .UcaSorter .Strength .PRIMARY ;
91
- }
92
-
93
72
private ErrorMessage validate (Query query ) {
94
73
Sorting sorting = query .getRanking ().getSorting ();
95
74
List <Sorting .FieldOrder > l = (sorting != null ) ? sorting .fieldOrders () : null ;
@@ -145,6 +124,11 @@ private ErrorMessage validate(Query query) {
145
124
f .setSorter (new Sorting .LowerCaseSorter (name ));
146
125
}
147
126
}
127
+ else if (attrConfig .datatype () == AttributesConfig .Attribute .Datatype .TENSOR ) {
128
+ throw new IllegalArgumentException ("Cannot sort on field '" + attrConfig .name () +
129
+ "' because it is a tensor" );
130
+ }
131
+
148
132
}
149
133
if (f .getSorter () instanceof Sorting .UcaSorter sorter ) {
150
134
String locale = sorter .getLocale ();
@@ -178,4 +162,19 @@ private ErrorMessage validate(Query query) {
178
162
return null ;
179
163
}
180
164
165
+ private static Sorting .UcaSorter .Strength config2Strength (AttributesConfig .Attribute .Sortstrength .Enum s ) {
166
+ if (s == AttributesConfig .Attribute .Sortstrength .PRIMARY ) {
167
+ return Sorting .UcaSorter .Strength .PRIMARY ;
168
+ } else if (s == AttributesConfig .Attribute .Sortstrength .SECONDARY ) {
169
+ return Sorting .UcaSorter .Strength .SECONDARY ;
170
+ } else if (s == AttributesConfig .Attribute .Sortstrength .TERTIARY ) {
171
+ return Sorting .UcaSorter .Strength .TERTIARY ;
172
+ } else if (s == AttributesConfig .Attribute .Sortstrength .QUATERNARY ) {
173
+ return Sorting .UcaSorter .Strength .QUATERNARY ;
174
+ } else if (s == AttributesConfig .Attribute .Sortstrength .IDENTICAL ) {
175
+ return Sorting .UcaSorter .Strength .IDENTICAL ;
176
+ }
177
+ return Sorting .UcaSorter .Strength .PRIMARY ;
178
+ }
179
+
181
180
}
0 commit comments