Skip to content

Commit 6ace6fc

Browse files
committed
feat(stats): add indexSize and usedIndexSize to IndexStats (#988)
1 parent 740d3f6 commit 6ace6fc

3 files changed

Lines changed: 74 additions & 0 deletions

File tree

‎src/main/java/com/meilisearch/sdk/model/IndexStats.java‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.meilisearch.sdk.model;
22

3+
import com.fasterxml.jackson.annotation.JsonProperty;
34
import java.util.Map;
45
import lombok.Getter;
6+
import lombok.Setter;
57

68
/**
79
* Stats data structure of a Meilisearch Index
@@ -10,15 +12,35 @@
1012
* specification</a>
1113
*/
1214
@Getter
15+
@Setter
1316
public class IndexStats {
17+
@JsonProperty("numberOfDocuments")
1418
protected long numberOfDocuments;
19+
20+
@JsonProperty("isIndexing")
1521
protected boolean isIndexing;
22+
23+
@JsonProperty("fieldDistribution")
1624
protected Map<String, Integer> fieldDistribution;
25+
26+
@JsonProperty("rawDocumentDbSize")
1727
protected long rawDocumentDbSize;
28+
29+
@JsonProperty("avgDocumentSize")
1830
protected long avgDocumentSize;
31+
32+
@JsonProperty("numberOfEmbeddedDocuments")
1933
protected long numberOfEmbeddedDocuments;
34+
35+
@JsonProperty("numberOfEmbeddings")
2036
protected long numberOfEmbeddings;
2137

38+
@JsonProperty("indexSize")
39+
protected long indexSize;
40+
41+
@JsonProperty("usedIndexSize")
42+
protected long usedIndexSize;
43+
2244
public IndexStats() {}
2345

2446
public IndexStats(
@@ -29,12 +51,36 @@ public IndexStats(
2951
long avgDocumentSize,
3052
long numberOfEmbeddedDocuments,
3153
long numberOfEmbeddings) {
54+
this(
55+
numberOfDocuments,
56+
isIndexing,
57+
fieldDistribution,
58+
rawDocumentDbSize,
59+
avgDocumentSize,
60+
numberOfEmbeddedDocuments,
61+
numberOfEmbeddings,
62+
0L,
63+
0L);
64+
}
65+
66+
public IndexStats(
67+
long numberOfDocuments,
68+
boolean isIndexing,
69+
Map<String, Integer> fieldDistribution,
70+
long rawDocumentDbSize,
71+
long avgDocumentSize,
72+
long numberOfEmbeddedDocuments,
73+
long numberOfEmbeddings,
74+
long indexSize,
75+
long usedIndexSize) {
3276
this.numberOfDocuments = numberOfDocuments;
3377
this.isIndexing = isIndexing;
3478
this.fieldDistribution = fieldDistribution;
3579
this.rawDocumentDbSize = rawDocumentDbSize;
3680
this.avgDocumentSize = avgDocumentSize;
3781
this.numberOfEmbeddedDocuments = numberOfEmbeddedDocuments;
3882
this.numberOfEmbeddings = numberOfEmbeddings;
83+
this.indexSize = indexSize;
84+
this.usedIndexSize = usedIndexSize;
3985
}
4086
}

‎src/test/java/com/meilisearch/sdk/json/GsonJsonHandlerTest.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,20 @@ void granularFilterableAttributesWithNullPatternRoundTrip() throws Exception {
291291
assertThat(decoded[0].getAttributePatterns(), arrayContaining("director", null, "genres"));
292292
}
293293

294+
@Test
295+
void decodeIndexStatsWithIndexSizeAndUsedIndexSize() {
296+
String json =
297+
"{\"numberOfDocuments\":10,\"isIndexing\":false,\"fieldDistribution\":{},\"rawDocumentDbSize\":1024,\"avgDocumentSize\":102,\"numberOfEmbeddedDocuments\":0,\"numberOfEmbeddings\":0,\"indexSize\":2048,\"usedIndexSize\":1500}";
298+
299+
com.meilisearch.sdk.model.IndexStats indexStats =
300+
classToTest.decode(json, com.meilisearch.sdk.model.IndexStats.class);
301+
302+
assertThat(indexStats, is(notNullValue()));
303+
assertThat(indexStats.getNumberOfDocuments(), is(equalTo(10L)));
304+
assertThat(indexStats.getIndexSize(), is(equalTo(2048L)));
305+
assertThat(indexStats.getUsedIndexSize(), is(equalTo(1500L)));
306+
}
307+
294308
@Getter
295309
private static class Container {
296310
private Key key;

‎src/test/java/com/meilisearch/sdk/json/JacksonJsonHandlerTest.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,4 +178,18 @@ void settingsWithAdvancedGranularFilterableAttributesRoundTripWithCustomMapper()
178178
.getComparison(),
179179
is(false));
180180
}
181+
182+
@Test
183+
void decodeIndexStatsWithIndexSizeAndUsedIndexSize() throws Exception {
184+
String json =
185+
"{\"numberOfDocuments\":10,\"isIndexing\":false,\"fieldDistribution\":{},\"rawDocumentDbSize\":1024,\"avgDocumentSize\":102,\"numberOfEmbeddedDocuments\":0,\"numberOfEmbeddings\":0,\"indexSize\":2048,\"usedIndexSize\":1500}";
186+
187+
com.meilisearch.sdk.model.IndexStats indexStats =
188+
classToTest.decode(json, com.meilisearch.sdk.model.IndexStats.class);
189+
190+
assertThat(indexStats, is(notNullValue()));
191+
assertThat(indexStats.getNumberOfDocuments(), is(equalTo(10L)));
192+
assertThat(indexStats.getIndexSize(), is(equalTo(2048L)));
193+
assertThat(indexStats.getUsedIndexSize(), is(equalTo(1500L)));
194+
}
181195
}

0 commit comments

Comments
 (0)