|
| 1 | +/* |
| 2 | + * Licensed to Elastic Search and Shay Banon under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. Elastic Search licenses this |
| 6 | + * file to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.action.terms; |
| 21 | + |
| 22 | +import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest; |
| 23 | + |
| 24 | +import java.io.DataInput; |
| 25 | +import java.io.DataOutput; |
| 26 | +import java.io.IOException; |
| 27 | + |
| 28 | +/** |
| 29 | + * @author kimchy (Shay Banon) |
| 30 | + */ |
| 31 | +public class ShardTermsRequest extends BroadcastShardOperationRequest { |
| 32 | + |
| 33 | + private String[] fields; |
| 34 | + |
| 35 | + private String from; |
| 36 | + |
| 37 | + private String to; |
| 38 | + |
| 39 | + private boolean fromInclusive = true; |
| 40 | + |
| 41 | + private boolean toInclusive = false; |
| 42 | + |
| 43 | + private String prefix; |
| 44 | + |
| 45 | + private String regexp; |
| 46 | + |
| 47 | + private int size = 10; |
| 48 | + |
| 49 | + private boolean convert = true; |
| 50 | + |
| 51 | + private TermsRequest.SortType sortType; |
| 52 | + |
| 53 | + private boolean exact = false; |
| 54 | + |
| 55 | + ShardTermsRequest() { |
| 56 | + } |
| 57 | + |
| 58 | + public ShardTermsRequest(String index, int shardId, TermsRequest request) { |
| 59 | + super(index, shardId); |
| 60 | + this.fields = request.fields(); |
| 61 | + this.from = request.from(); |
| 62 | + this.to = request.to(); |
| 63 | + this.fromInclusive = request.fromInclusive(); |
| 64 | + this.toInclusive = request.toInclusive(); |
| 65 | + this.prefix = request.prefix(); |
| 66 | + this.regexp = request.regexp(); |
| 67 | + this.size = request.size(); |
| 68 | + this.convert = request.convert(); |
| 69 | + this.sortType = request.sortType(); |
| 70 | + this.exact = request.exact(); |
| 71 | + } |
| 72 | + |
| 73 | + public String[] fields() { |
| 74 | + return fields; |
| 75 | + } |
| 76 | + |
| 77 | + public String from() { |
| 78 | + return from; |
| 79 | + } |
| 80 | + |
| 81 | + public String to() { |
| 82 | + return to; |
| 83 | + } |
| 84 | + |
| 85 | + public boolean fromInclusive() { |
| 86 | + return fromInclusive; |
| 87 | + } |
| 88 | + |
| 89 | + public boolean toInclusive() { |
| 90 | + return toInclusive; |
| 91 | + } |
| 92 | + |
| 93 | + public String prefix() { |
| 94 | + return prefix; |
| 95 | + } |
| 96 | + |
| 97 | + public String regexp() { |
| 98 | + return regexp; |
| 99 | + } |
| 100 | + |
| 101 | + public int size() { |
| 102 | + return size; |
| 103 | + } |
| 104 | + |
| 105 | + public boolean convert() { |
| 106 | + return convert; |
| 107 | + } |
| 108 | + |
| 109 | + public TermsRequest.SortType sortType() { |
| 110 | + return sortType; |
| 111 | + } |
| 112 | + |
| 113 | + public boolean exact() { |
| 114 | + return this.exact; |
| 115 | + } |
| 116 | + |
| 117 | + @Override public void readFrom(DataInput in) throws IOException, ClassNotFoundException { |
| 118 | + super.readFrom(in); |
| 119 | + fields = new String[in.readInt()]; |
| 120 | + for (int i = 0; i < fields.length; i++) { |
| 121 | + fields[i] = in.readUTF(); |
| 122 | + } |
| 123 | + if (in.readBoolean()) { |
| 124 | + from = in.readUTF(); |
| 125 | + } |
| 126 | + if (in.readBoolean()) { |
| 127 | + to = in.readUTF(); |
| 128 | + } |
| 129 | + fromInclusive = in.readBoolean(); |
| 130 | + toInclusive = in.readBoolean(); |
| 131 | + if (in.readBoolean()) { |
| 132 | + prefix = in.readUTF(); |
| 133 | + } |
| 134 | + if (in.readBoolean()) { |
| 135 | + regexp = in.readUTF(); |
| 136 | + } |
| 137 | + size = in.readInt(); |
| 138 | + convert = in.readBoolean(); |
| 139 | + sortType = TermsRequest.SortType.fromValue(in.readByte()); |
| 140 | + exact = in.readBoolean(); |
| 141 | + } |
| 142 | + |
| 143 | + @Override public void writeTo(DataOutput out) throws IOException { |
| 144 | + super.writeTo(out); |
| 145 | + out.writeInt(fields.length); |
| 146 | + for (String field : fields) { |
| 147 | + out.writeUTF(field); |
| 148 | + } |
| 149 | + if (from == null) { |
| 150 | + out.writeBoolean(false); |
| 151 | + } else { |
| 152 | + out.writeBoolean(true); |
| 153 | + out.writeUTF(from); |
| 154 | + } |
| 155 | + if (to == null) { |
| 156 | + out.writeBoolean(false); |
| 157 | + } else { |
| 158 | + out.writeBoolean(true); |
| 159 | + out.writeUTF(to); |
| 160 | + } |
| 161 | + out.writeBoolean(fromInclusive); |
| 162 | + out.writeBoolean(toInclusive); |
| 163 | + if (prefix == null) { |
| 164 | + out.writeBoolean(false); |
| 165 | + } else { |
| 166 | + out.writeBoolean(true); |
| 167 | + out.writeUTF(prefix); |
| 168 | + } |
| 169 | + if (regexp == null) { |
| 170 | + out.writeBoolean(false); |
| 171 | + } else { |
| 172 | + out.writeBoolean(true); |
| 173 | + out.writeUTF(regexp); |
| 174 | + } |
| 175 | + out.writeInt(size); |
| 176 | + out.writeBoolean(convert); |
| 177 | + out.writeByte(sortType.value()); |
| 178 | + out.writeBoolean(exact); |
| 179 | + } |
| 180 | +} |
0 commit comments