Skip to content

Commit 37c07c2

Browse files
committed
[DE-392] nested search support (#460)
* docker images upd * arangosearch nested links (cherry picked from commit 0f80bc0)
1 parent 10ec28e commit 37c07c2

File tree

3 files changed

+70
-19
lines changed

3 files changed

+70
-19
lines changed

src/main/java/com/arangodb/entity/arangosearch/CollectionLink.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public final class CollectionLink {
4242
private Boolean trackListPositions;
4343
private StoreValuesType storeValues;
4444
private Collection<FieldLink> fields;
45+
private Collection<FieldLink> nested;
4546

4647
private CollectionLink(final String name) {
4748
super();
@@ -110,6 +111,17 @@ public CollectionLink fields(final FieldLink... fields) {
110111
return this;
111112
}
112113

114+
/**
115+
* @param nested A list of nested fields
116+
* @return link
117+
* @since ArangoDB 3.10
118+
*/
119+
@JsonDeserialize(using = InternalDeserializers.FieldLinksDeserializer.class)
120+
public CollectionLink nested(final FieldLink... nested) {
121+
this.nested = Arrays.asList(nested);
122+
return this;
123+
}
124+
113125
@JsonIgnore
114126
public String getName() {
115127
return name;
@@ -136,4 +148,9 @@ public Collection<FieldLink> getFields() {
136148
return fields;
137149
}
138150

151+
@JsonSerialize(using = InternalSerializers.FieldLinksSerializer.class)
152+
public Collection<FieldLink> getNested() {
153+
return nested;
154+
}
155+
139156
}

src/main/java/com/arangodb/entity/arangosearch/FieldLink.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.arangodb.entity.arangosearch;
22

3+
import com.arangodb.internal.serde.InternalDeserializers;
34
import com.arangodb.internal.serde.InternalSerializers;
45
import com.fasterxml.jackson.annotation.JsonCreator;
56
import com.fasterxml.jackson.annotation.JsonIgnore;
67
import com.fasterxml.jackson.annotation.JsonProperty;
8+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
79
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
810

911
import java.util.Arrays;
@@ -17,6 +19,7 @@ public final class FieldLink {
1719
private Boolean trackListPositions;
1820
private StoreValuesType storeValues;
1921
private Collection<FieldLink> fields;
22+
private Collection<FieldLink> nested;
2023

2124
private FieldLink(final String name) {
2225
super();
@@ -79,11 +82,23 @@ public FieldLink storeValues(final StoreValuesType storeValues) {
7982
* @param fields A list of linked fields
8083
* @return link
8184
*/
85+
@JsonDeserialize(using = InternalDeserializers.FieldLinksDeserializer.class)
8286
public FieldLink fields(final FieldLink... fields) {
8387
this.fields = Arrays.asList(fields);
8488
return this;
8589
}
8690

91+
/**
92+
* @param nested A list of nested fields
93+
* @return link
94+
* @since ArangoDB 3.10
95+
*/
96+
@JsonDeserialize(using = InternalDeserializers.FieldLinksDeserializer.class)
97+
public FieldLink nested(final FieldLink... nested) {
98+
this.nested = Arrays.asList(nested);
99+
return this;
100+
}
101+
87102
@JsonIgnore
88103
public String getName() {
89104
return name;
@@ -110,4 +125,8 @@ public Collection<FieldLink> getFields() {
110125
return fields;
111126
}
112127

128+
@JsonSerialize(using = InternalSerializers.FieldLinksSerializer.class)
129+
public Collection<FieldLink> getNested() {
130+
return nested;
131+
}
113132
}

src/test/java/com/arangodb/ArangoSearchTest.java

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -493,19 +493,20 @@ void enhancedTextAnalyzerTyped(ArangoDatabase db) {
493493
void arangoSearchOptions(ArangoDatabase db) {
494494
assumeTrue(isAtLeastVersion(3, 4));
495495
String viewName = "view-" + rnd();
496-
ArangoSearchCreateOptions options = new ArangoSearchCreateOptions()
497-
.link(
498-
CollectionLink.on(COLL_1)
499-
.analyzers("identity")
500-
.fields(
501-
FieldLink.on("id")
502-
.analyzers("identity")
503-
)
504-
.includeAllFields(true)
505-
.storeValues(StoreValuesType.ID)
506-
.trackListPositions(false)
507-
508-
);
496+
FieldLink field = FieldLink.on("f1");
497+
if (isEnterprise()) {
498+
field.nested(FieldLink.on("f2"));
499+
}
500+
CollectionLink link = CollectionLink.on(COLL_1)
501+
.analyzers("identity")
502+
.fields(field)
503+
.includeAllFields(true)
504+
.storeValues(StoreValuesType.ID)
505+
.trackListPositions(false);
506+
if (isEnterprise()) {
507+
link.nested(FieldLink.on("f3"));
508+
}
509+
ArangoSearchCreateOptions options = new ArangoSearchCreateOptions().link(link);
509510

510511
final ArangoSearch view = db.arangoSearch(viewName);
511512
view.create(options);
@@ -515,13 +516,27 @@ void arangoSearchOptions(ArangoDatabase db) {
515516
assertThat(properties.getId()).isNotNull();
516517
assertThat(properties.getName()).isEqualTo(viewName);
517518
assertThat(properties.getType()).isEqualTo(ViewType.ARANGO_SEARCH);
519+
assertThat(properties.getLinks()).isNotEmpty();
520+
521+
CollectionLink createdLink = properties.getLinks().iterator().next();
522+
assertThat(createdLink.getName()).isEqualTo(COLL_1);
523+
assertThat(createdLink.getAnalyzers()).contains("identity");
524+
assertThat(createdLink.getIncludeAllFields()).isTrue();
525+
assertThat(createdLink.getStoreValues()).isEqualTo(StoreValuesType.ID);
526+
assertThat(createdLink.getTrackListPositions()).isFalse();
527+
if (isEnterprise() && isAtLeastVersion(3, 10)) {
528+
assertThat(createdLink.getNested()).isNotEmpty();
529+
FieldLink nested = createdLink.getNested().iterator().next();
530+
assertThat(nested.getName()).isEqualTo("f3");
531+
}
518532

519-
CollectionLink link = properties.getLinks().iterator().next();
520-
assertThat(link.getAnalyzers()).contains("identity");
521-
assertThat(link.getName()).isEqualTo(COLL_1);
522-
assertThat(link.getIncludeAllFields()).isTrue();
523-
assertThat(link.getStoreValues()).isEqualTo(StoreValuesType.ID);
524-
assertThat(link.getTrackListPositions()).isFalse();
533+
FieldLink fieldLink = createdLink.getFields().iterator().next();
534+
assertThat(fieldLink.getName()).isEqualTo("f1");
535+
if (isEnterprise() && isAtLeastVersion(3, 10)) {
536+
assertThat(fieldLink.getNested()).isNotEmpty();
537+
FieldLink nested = fieldLink.getNested().iterator().next();
538+
assertThat(nested.getName()).isEqualTo("f2");
539+
}
525540
}
526541

527542
@ParameterizedTest(name = "{index}")

0 commit comments

Comments
 (0)