Skip to content

Commit ee4a404

Browse files
committed
[DE-434] ArangoSearch cache
1 parent 19c4d97 commit ee4a404

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public final class CollectionLink {
4444
private Collection<FieldLink> fields;
4545
private Collection<FieldLink> nested;
4646
private Boolean inBackground;
47+
private Boolean cache;
4748

4849
private CollectionLink(final String name) {
4950
super();
@@ -135,6 +136,19 @@ public CollectionLink inBackground(final Boolean inBackground) {
135136
return this;
136137
}
137138

139+
/**
140+
* @param cache If you enable this option, then field normalization values are always cached in memory. This can
141+
* improve the performance of scoring and ranking queries. Otherwise, these values are memory-mapped
142+
* and it is up to the operating system to load them from disk into memory and to evict them from
143+
* memory.
144+
* @return link
145+
* @since ArangoDB 3.9.5, Enterprise Edition only
146+
*/
147+
public CollectionLink cache(final Boolean cache) {
148+
this.cache = cache;
149+
return this;
150+
}
151+
138152
@JsonIgnore
139153
public String getName() {
140154
return name;
@@ -169,4 +183,9 @@ public Collection<FieldLink> getNested() {
169183
public Boolean getInBackground() {
170184
return inBackground;
171185
}
186+
187+
public Boolean getCache() {
188+
return cache;
189+
}
190+
172191
}

driver/src/main/java/com/arangodb/entity/arangosearch/StoredValue.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,24 @@ public final class StoredValue {
3636

3737
private final List<String> fields;
3838
private final ArangoSearchCompression compression;
39+
private final Boolean cache;
3940

4041
/**
4142
* @param fields A list of attribute paths. The . character denotes sub-attributes.
4243
* @param compression Defines how to compress the attribute values.
44+
* @param cache Whether to cache stored values in memory. (Since ArangoDB 3.9.5, Enterprise Edition only)
4345
*/
4446
@JsonCreator
4547
public StoredValue(@JsonProperty("fields") List<String> fields,
46-
@JsonProperty("compression") ArangoSearchCompression compression) {
48+
@JsonProperty("compression") ArangoSearchCompression compression,
49+
@JsonProperty("cache") Boolean cache) {
4750
this.fields = fields;
4851
this.compression = compression;
52+
this.cache = cache;
53+
}
54+
55+
public StoredValue(List<String> fields, ArangoSearchCompression compression) {
56+
this(fields, compression, null);
4957
}
5058

5159
public StoredValue(List<String> fields) {
@@ -60,16 +68,20 @@ public ArangoSearchCompression getCompression() {
6068
return compression;
6169
}
6270

71+
public Boolean getCache() {
72+
return cache;
73+
}
74+
6375
@Override
6476
public boolean equals(Object o) {
6577
if (this == o) return true;
6678
if (o == null || getClass() != o.getClass()) return false;
6779
StoredValue that = (StoredValue) o;
68-
return Objects.equals(fields, that.fields) && compression == that.compression;
80+
return Objects.equals(fields, that.fields) && compression == that.compression && Objects.equals(cache, that.cache);
6981
}
7082

7183
@Override
7284
public int hashCode() {
73-
return Objects.hash(fields, compression);
85+
return Objects.hash(fields, compression, cache);
7486
}
7587
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,15 @@ void arangoSearchOptions(ArangoDatabase db) {
657657
.includeAllFields(true)
658658
.storeValues(StoreValuesType.ID)
659659
.trackListPositions(false)
660-
.inBackground(true);
660+
.inBackground(true)
661+
.cache(true);
662+
661663
if (isEnterprise()) {
662664
link.nested(FieldLink.on("f3"));
663665
}
664666
ArangoSearchCreateOptions options = new ArangoSearchCreateOptions().link(link);
667+
StoredValue storedValue = new StoredValue(Arrays.asList("a", "b"), ArangoSearchCompression.none, true);
668+
options.storedValues(storedValue);
665669

666670
final ArangoSearch view = db.arangoSearch(viewName);
667671
view.create(options);
@@ -679,6 +683,14 @@ void arangoSearchOptions(ArangoDatabase db) {
679683
assertThat(createdLink.getIncludeAllFields()).isTrue();
680684
assertThat(createdLink.getStoreValues()).isEqualTo(StoreValuesType.ID);
681685
assertThat(createdLink.getTrackListPositions()).isFalse();
686+
687+
if (isEnterprise() && isAtLeastVersion(3, 9, 5) && isLessThanVersion(3, 10)) {
688+
assertThat(createdLink.getCache()).isTrue();
689+
assertThat(properties.getStoredValues())
690+
.isNotEmpty()
691+
.allSatisfy(it -> assertThat(it.getCache()).isTrue());
692+
}
693+
682694
if (isEnterprise() && isAtLeastVersion(3, 10)) {
683695
assertThat(createdLink.getNested()).isNotEmpty();
684696
FieldLink nested = createdLink.getNested().iterator().next();

0 commit comments

Comments
 (0)