forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathViewSearchRequest.java
74 lines (59 loc) · 2.18 KB
/
ViewSearchRequest.java
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
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.action.search;
import org.opensearch.action.ActionRequestValidationException;
import org.opensearch.cluster.metadata.View;
import org.opensearch.common.annotation.ExperimentalApi;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import java.io.IOException;
import java.util.Objects;
import java.util.function.Function;
import static org.opensearch.action.ValidateActions.addValidationError;
/** Wraps the functionality of search requests and tailors for what is available when searching through views
*/
@ExperimentalApi
public class ViewSearchRequest extends SearchRequest {
public final View view;
public ViewSearchRequest(final View view) {
super();
this.view = view;
}
public ViewSearchRequest(final StreamInput in) throws IOException {
super(in);
view = new View(in);
}
@Override
public ActionRequestValidationException validate() {
final Function<String, String> unsupported = (String x) -> x + " is not supported when searching views";
ActionRequestValidationException validationException = super.validate();
if (scroll() != null) {
validationException = addValidationError(unsupported.apply("Scroll"), validationException);
}
// TODO: Filter out anything additional search features that are not supported
return validationException;
}
@Override
public void writeTo(final StreamOutput out) throws IOException {
super.writeTo(out);
view.writeTo(out);
}
@Override
public boolean equals(final Object o) {
// TODO: Maybe this isn't standard practice
return this.hashCode() == o.hashCode();
}
@Override
public int hashCode() {
return Objects.hash(view, super.hashCode());
}
@Override
public String toString() {
return super.toString().replace("SearchRequest{", "ViewSearchRequest{view=" + view + ",");
}
}