Skip to content

Commit

Permalink
Refactor an ambigious TermVectorsRequest constructor. (#35614)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtibshirani authored Nov 16, 2018
1 parent d62bbca commit 4fea6b6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class TermVectorsRequest implements ToXContentObject, Validatable {
private final String index;
private final String type;
private String id = null;
private XContentBuilder docBuilder = null;

private String routing = null;
private String preference = null;
private boolean realtime = true;
Expand All @@ -44,7 +46,6 @@ public class TermVectorsRequest implements ToXContentObject, Validatable {
private boolean requestTermStatistics = false;
private Map<String, String> perFieldAnalyzer = null;
private Map<String, Integer> filterSettings = null;
private XContentBuilder docBuilder = null;


/**
Expand All @@ -54,18 +55,21 @@ public class TermVectorsRequest implements ToXContentObject, Validatable {
* @param docId - id of the document
*/
public TermVectorsRequest(String index, String type, String docId) {
this(index, type);
this.index = index;
this.type = type;
this.id = docId;
}

/**
* Constructs TermVectorRequest for an artificial document
* @param index - index of the document
* @param type - type of the document
* @param docBuilder - an artificial document
*/
public TermVectorsRequest(String index, String type) {
public TermVectorsRequest(String index, String type, XContentBuilder docBuilder) {
this.index = index;
this.type = type;
this.docBuilder = docBuilder;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ public void testExists() throws IOException {
assertFalse(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
}
}
public void testSourceExists() throws IOException {

public void testSourceExists() throws IOException {
{
GetRequest getRequest = new GetRequest("index", "type", "id");
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
Expand All @@ -215,17 +215,17 @@ public void testSourceExists() throws IOException {
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
}
}
public void testSourceDoesNotExist() throws IOException {

public void testSourceDoesNotExist() throws IOException {
final String noSourceIndex = "no_source";
{
// Prepare
Settings settings = Settings.builder()
.put("number_of_shards", 1)
.put("number_of_replicas", 0)
.build();
String mapping = "\"_doc\": { \"_source\": {\n" +
" \"enabled\": false\n" +
String mapping = "\"_doc\": { \"_source\": {\n" +
" \"enabled\": false\n" +
" } }";
createIndex(noSourceIndex, settings, mapping);
assertEquals(
Expand All @@ -240,13 +240,13 @@ public void testSourceDoesNotExist() throws IOException {
RequestOptions.DEFAULT
).status()
);
}
}
{
GetRequest getRequest = new GetRequest(noSourceIndex, "_doc", "1");
assertTrue(execute(getRequest, highLevelClient()::exists, highLevelClient()::existsAsync));
assertFalse(execute(getRequest, highLevelClient()::existsSource, highLevelClient()::existsSourceAsync));
}
}
}

public void testGet() throws IOException {
{
Expand Down Expand Up @@ -1154,10 +1154,10 @@ public void testTermvectors() throws IOException {
}
{
// test _termvectors on artificial documents
TermVectorsRequest tvRequest = new TermVectorsRequest(sourceIndex, "_doc");
XContentBuilder docBuilder = XContentFactory.jsonBuilder();
docBuilder.startObject().field("field", "valuex").endObject();
tvRequest.setDoc(docBuilder);

TermVectorsRequest tvRequest = new TermVectorsRequest(sourceIndex, "_doc", docBuilder);
TermVectorsResponse tvResponse = execute(tvRequest, highLevelClient()::termvectors, highLevelClient()::termvectorsAsync);

TermVectorsResponse.TermVector.Token expectedToken = new TermVectorsResponse.TermVector.Token(0, 6, 0, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1565,10 +1565,12 @@ public void testTermVectors() throws Exception {

{
// tag::term-vectors-request-artificial
TermVectorsRequest request = new TermVectorsRequest("authors", "_doc");

XContentBuilder docBuilder = XContentFactory.jsonBuilder();
docBuilder.startObject().field("user", "guest-user").endObject();
request.setDoc(docBuilder); // <1>
TermVectorsRequest request = new TermVectorsRequest("authors",
"_doc",
docBuilder); // <1>
// end::term-vectors-request-artificial

// tag::term-vectors-request-optional-arguments
Expand Down

0 comments on commit 4fea6b6

Please sign in to comment.