Skip to content

Commit fa34403

Browse files
committed
Cleanup: No functional changes
1 parent 0bfea6f commit fa34403

1 file changed

Lines changed: 30 additions & 36 deletions

File tree

container-search/src/main/java/com/yahoo/prelude/searcher/ValidateSortingSearcher.java

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,32 @@
2929
@After(ACCENT_REMOVAL)
3030
public 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;
@@ -178,4 +157,19 @@ private ErrorMessage validate(Query query) {
178157
return null;
179158
}
180159

160+
private static Sorting.UcaSorter.Strength config2Strength(AttributesConfig.Attribute.Sortstrength.Enum s) {
161+
if (s == AttributesConfig.Attribute.Sortstrength.PRIMARY) {
162+
return Sorting.UcaSorter.Strength.PRIMARY;
163+
} else if (s == AttributesConfig.Attribute.Sortstrength.SECONDARY) {
164+
return Sorting.UcaSorter.Strength.SECONDARY;
165+
} else if (s == AttributesConfig.Attribute.Sortstrength.TERTIARY) {
166+
return Sorting.UcaSorter.Strength.TERTIARY;
167+
} else if (s == AttributesConfig.Attribute.Sortstrength.QUATERNARY) {
168+
return Sorting.UcaSorter.Strength.QUATERNARY;
169+
} else if (s == AttributesConfig.Attribute.Sortstrength.IDENTICAL) {
170+
return Sorting.UcaSorter.Strength.IDENTICAL;
171+
}
172+
return Sorting.UcaSorter.Strength.PRIMARY;
173+
}
174+
181175
}

0 commit comments

Comments
 (0)