Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/com/meilisearch/sdk/MultiSearchFederation.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class MultiSearchFederation {
private Integer offset;
private MergeFacets mergeFacets;
private Map<String, String[]> facetsByIndex;
private Boolean showPerformanceDetails;

public MultiSearchFederation setLimit(Integer limit) {
this.limit = limit;
Expand All @@ -32,6 +33,11 @@ public MultiSearchFederation setFacetsByIndex(Map<String, String[]> facetsByInde
return this;
}

public MultiSearchFederation setShowPerformanceDetails(Boolean showPerformanceDetails) {
this.showPerformanceDetails = showPerformanceDetails;
return this;
}

/**
* Method that returns the JSON String of the MultiSearchFederation
*
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/meilisearch/sdk/SearchRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class SearchRequest {
protected Hybrid hybrid;
protected Double[] vector;
protected Boolean retrieveVectors;
protected Boolean showPerformanceDetails;
/**
* Constructor for SearchRequest for building search queries with the default values: offset: 0,
* limit: 20, attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200,
Expand Down Expand Up @@ -110,7 +111,8 @@ public String toString() {
.putOpt("locales", this.locales)
.putOpt("distinct", this.distinct)
.putOpt("vector", this.vector)
.putOpt("retrieveVectors", this.retrieveVectors);
.putOpt("retrieveVectors", this.retrieveVectors)
.putOpt("showPerformanceDetails", this.showPerformanceDetails);

if (this.hybrid != null) {
jsonObject.put("hybrid", this.hybrid.toJSONObject());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/meilisearch/sdk/SimilarDocumentRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SimilarDocumentRequest {
private Boolean showRankingScoreDetails;
private Double rankingScoreThreshold;
private Boolean retrieveVectors;
private Boolean showPerformanceDetails;

/** Constructor for SimilarDocumentsRequest for building search request for similar documents */
public SimilarDocumentRequest() {}
Expand All @@ -37,6 +38,7 @@ public String toString() {
jsonObject.putOpt("showRankingScoreDetails", this.showRankingScoreDetails);
jsonObject.putOpt("rankingScoreThreshold", this.rankingScoreThreshold);
jsonObject.putOpt("retrieveVectors", this.retrieveVectors);
jsonObject.putOpt("showPerformanceDetails", this.showPerformanceDetails);

return jsonObject.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class MultiSearchResult implements Searchable {
int limit;
int estimatedTotalHits;
HashMap<String, FacetsByIndexInfo> facetsByIndex;
HashMap<String, Object> performanceDetails;

public MultiSearchResult() {}
}
1 change: 1 addition & 0 deletions src/main/java/com/meilisearch/sdk/model/SearchResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class SearchResult implements Searchable {
int limit;
int estimatedTotalHits;
HashMap<String, Object> _vectors;
HashMap<String, Object> performanceDetails;

public SearchResult() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ public class SimilarDocumentsResults {
int offset;
int limit;
int estimatedTotalHits;
HashMap<String, Object> performanceDetails;
}
37 changes: 27 additions & 10 deletions src/test/java/com/meilisearch/integration/SearchTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
package com.meilisearch.integration;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.hasLength;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.*;

import com.meilisearch.integration.classes.AbstractIT;
import com.meilisearch.integration.classes.TestData;
Expand Down Expand Up @@ -842,6 +834,7 @@ public void testFederation() throws Exception {

MultiSearchFederation federation = new MultiSearchFederation();
federation.setLimit(2);
federation.setShowPerformanceDetails(true);
MultiSearchResult results = client.multiSearch(search, federation);

assertThat(results.getEstimatedTotalHits(), is(2));
Expand All @@ -851,6 +844,7 @@ public void testFederation() throws Exception {
for (HashMap<String, Object> record : hits) {
assertThat(record.containsKey("_federation"), is(true));
}
assertThat(results.getPerformanceDetails(), aMapWithSize(greaterThan(0)));
}

/** Test multisearch with ranking score threshold */
Expand Down Expand Up @@ -1106,14 +1100,18 @@ public void testSimilarDocuments() throws Exception {

SimilarDocumentsResults results =
index.searchSimilarDocuments(
new SimilarDocumentRequest().setId("143").setEmbedder("manual"));
new SimilarDocumentRequest()
.setId("143")
.setEmbedder("manual")
.setShowPerformanceDetails(true));

ArrayList<HashMap<String, Object>> hits = results.getHits();
assertThat(hits.size(), is(4));
assertThat(hits.get(0).get("title"), is("Escape Room"));
assertThat(hits.get(1).get("title"), is("Captain Marvel"));
assertThat(hits.get(2).get("title"), is("How to Train Your Dragon: The Hidden World"));
assertThat(hits.get(3).get("title"), is("Shazam!"));
assertThat(results.getPerformanceDetails(), aMapWithSize(greaterThan(0)));
}

/** Test vector search */
Expand Down Expand Up @@ -1307,4 +1305,23 @@ public void testSearchWithRetrieveVectors() throws Exception {
Map<String, Object> vectors = (Map<String, Object>) hitWith.get("_vectors");
assertThat(vectors.containsKey("manual"), is(true));
}

@Test
public void testSearchWithPerformanceDetails() throws Exception {
String indexUid = "testSearchWithPerformanceDetails";
Index index = client.index(indexUid);

TestData<Movie> testData = this.getTestData(MOVIES_INDEX, Movie.class);
TaskInfo task = index.addDocuments(testData.getRaw());

index.waitForTask(task.getTaskUid());

SearchRequest searchRequest =
SearchRequest.builder().q("a").showPerformanceDetails(true).build();
SearchResult searchResult = (SearchResult) index.search(searchRequest);

assertThat(searchResult.getHits(), hasSize(11));
assertThat(searchResult.getEstimatedTotalHits(), is(equalTo(31)));
assertThat(searchResult.getPerformanceDetails(), aMapWithSize(greaterThan(0)));
}
}