-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
522 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
.../rest-high-level/src/main/java/org/elasticsearch/client/core/MultiTermVectorsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.core; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.client.core.TermVectorsRequest.createFromTemplate; | ||
|
||
public class MultiTermVectorsRequest implements ToXContentObject, Validatable { | ||
|
||
private List<TermVectorsRequest> requests = new ArrayList<>(); | ||
|
||
/** | ||
* Constructs an empty MultiTermVectorsRequest | ||
* After that use {@code add} method to add individual {@code TermVectorsRequest} to it. | ||
*/ | ||
public MultiTermVectorsRequest() {}; | ||
|
||
/** | ||
* Constructs a MultiTermVectorsRequest from the given document ids | ||
* and a template {@code TermVectorsRequest}. | ||
* Used when individual requests share the same index, type and other settings. | ||
* @param ids - ids of documents for which term vectors are requested | ||
* @param template - a template {@code TermVectorsRequest} that allows to set all | ||
* settings only once for all requests. | ||
*/ | ||
public MultiTermVectorsRequest(String[] ids, TermVectorsRequest template) { | ||
for (String id : ids) { | ||
TermVectorsRequest request = createFromTemplate(template, id); | ||
requests.add(request); | ||
} | ||
} | ||
|
||
/** | ||
* Adds another {@code TermVectorsRequest} to this {@code MultiTermVectorsRequest} | ||
* @param request - {@code TermVectorsRequest} to add | ||
*/ | ||
public void add(TermVectorsRequest request) { | ||
requests.add(request); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
builder.startObject(); | ||
builder.startArray("docs"); | ||
for (TermVectorsRequest request : requests) { | ||
request.toXContent(builder, params); | ||
} | ||
builder.endArray(); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
...rest-high-level/src/main/java/org/elasticsearch/client/core/MultiTermVectorsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.core; | ||
|
||
|
||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ConstructingObjectParser; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constructorArg; | ||
|
||
public class MultiTermVectorsResponse { | ||
private final List<TermVectorsResponse> responses; | ||
|
||
public MultiTermVectorsResponse(List<TermVectorsResponse> responses) { | ||
this.responses = responses; | ||
} | ||
|
||
private static ConstructingObjectParser<MultiTermVectorsResponse, Void> PARSER = | ||
new ConstructingObjectParser<>("multi_term_vectors", true, | ||
args -> { | ||
// as the response comes from server, we are sure that args[0] will be a list of TermVectorsResponse | ||
@SuppressWarnings("unchecked") List<TermVectorsResponse> termVectorsResponsesList = (List<TermVectorsResponse>) args[0]; | ||
return new MultiTermVectorsResponse(termVectorsResponsesList); | ||
} | ||
); | ||
|
||
static { | ||
PARSER.declareObjectArray(constructorArg(), (p,c) -> TermVectorsResponse.fromXContent(p), new ParseField("docs")); | ||
} | ||
|
||
public static MultiTermVectorsResponse fromXContent(XContentParser parser) { | ||
return PARSER.apply(parser, null); | ||
} | ||
|
||
/** | ||
* Returns the list of {@code TermVectorsResponse} for this {@code MultiTermVectorsResponse} | ||
*/ | ||
public List<TermVectorsResponse> getTermVectorsResponses() { | ||
return responses; | ||
} | ||
|
||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) return true; | ||
if (!(obj instanceof MultiTermVectorsResponse)) return false; | ||
MultiTermVectorsResponse other = (MultiTermVectorsResponse) obj; | ||
return Objects.equals(responses, other.responses); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(responses); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.