Skip to content

Commit

Permalink
Refactors BoolQueryBuilder and Parser. Splits the parse(QueryParseCon…
Browse files Browse the repository at this point in the history
…text ctx) method into a parsing

and a query building part, adding NamedWriteable implementation for serialization and hashCode(),
equals() for testing.

This change also adds tests using fixed set of leaf queries (Terms, Ids, MatchAll) as nested Queries in test query setup.
Also QueryParseContext is adapted to return QueryBuilder instances for inner filter parses instead of
previously returning Query instances, keeping old methods in place but deprecating them.

Relates to elastic#10217
Closes elastic#11427
  • Loading branch information
Christoph Büscher authored and cbuescher committed Jun 11, 2015
1 parent 74db0de commit 79b0332
Show file tree
Hide file tree
Showing 7 changed files with 496 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,20 @@ public <C> C readNamedWriteable() throws IOException {
return namedWriteable.readFrom(this);
}

/**
* Reads a list of {@link NamedWriteable} from the current stream, by first reading its size and then
* reading the individual objects using {@link #readNamedWriteable()}.
*/
public <C> List<C> readNamedWritableList() throws IOException {
List<C> list = new ArrayList<>();
int size = readInt();
for (int i = 0; i < size; i++) {
C obj = readNamedWriteable();
list.add(obj);
}
return list;
}

public static StreamInput wrap(BytesReference reference) {
if (reference.hasArray() == false) {
reference = reference.toBytesArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,15 @@ public void writeNamedWriteable(NamedWriteable namedWriteable) throws IOExceptio
writeString(namedWriteable.getName());
namedWriteable.writeTo(this);
}

/**
* Writes a list of {@link NamedWriteable} to the current stream, by first writing its size and then iterating over the objects
* in the list
*/
public void writeNamedWritableList(List<? extends NamedWriteable> list) throws IOException {
writeInt(list.size());
for (NamedWriteable obj : list) {
writeNamedWriteable(obj);
}
}
}
Loading

0 comments on commit 79b0332

Please sign in to comment.