2929@ After (ACCENT_REMOVAL )
3030public class ValidateSortingSearcher extends Searcher {
3131
32+ // TODO: Use SchemaInfo instead and validate with streaming as well
33+
34+ private final boolean isStreaming ;
35+
3236 private Map <String , AttributesConfig .Attribute > attributeNames = null ;
3337 private String clusterName = "" ;
34- private final boolean enabled ;
3538
3639 public ValidateSortingSearcher (ClusterConfig clusterConfig , AttributesConfig attributesConfig ) {
3740 initAttributeNames (attributesConfig );
3841 setClusterName (clusterConfig .clusterName ());
39- enabled = clusterConfig .indexMode () ! = ClusterConfig .IndexMode .Enum .STREAMING ;
42+ isStreaming = clusterConfig .indexMode () = = ClusterConfig .IndexMode .Enum .STREAMING ;
4043 }
4144
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 );
4451 }
4552
46- public void setClusterName (String clusterName ) {
47- this .clusterName = clusterName ;
48- }
53+ public String getClusterName () { return clusterName ; }
4954
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 ; }
5358
5459 public void setAttributeNames (Map <String , AttributesConfig .Attribute > attributeNames ) {
5560 this .attributeNames = attributeNames ;
@@ -64,32 +69,6 @@ public void initAttributeNames(AttributesConfig config) {
6469 setAttributeNames (attributes );
6570 }
6671
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-
9372 private ErrorMessage validate (Query query ) {
9473 Sorting sorting = query .getRanking ().getSorting ();
9574 List <Sorting .FieldOrder > l = (sorting != null ) ? sorting .fieldOrders () : null ;
@@ -145,6 +124,11 @@ private ErrorMessage validate(Query query) {
145124 f .setSorter (new Sorting .LowerCaseSorter (name ));
146125 }
147126 }
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+
148132 }
149133 if (f .getSorter () instanceof Sorting .UcaSorter sorter ) {
150134 String locale = sorter .getLocale ();
@@ -178,4 +162,19 @@ private ErrorMessage validate(Query query) {
178162 return null ;
179163 }
180164
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+
181180}
0 commit comments