Skip to content

Commit 40842d8

Browse files
authored
Merge pull request #505 from meilisearch/search-changes
Apply search changes
2 parents a713a6e + 49a2190 commit 40842d8

File tree

7 files changed

+76
-81
lines changed

7 files changed

+76
-81
lines changed

src/main/java/com/meilisearch/sdk/Search.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ String rawSearch(String uid, String q) throws MeilisearchException {
4848
* @param highlightPostTag String to customize highlight tag after every highlighted query terms
4949
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
5050
* @param filter Filter queries by an attribute value
51-
* @param matches Defines whether an object that contains information about the matches should
52-
* be returned or not
53-
* @param facetsDistribution Facets for which to retrieve the matching count
51+
* @param showMatchesPosition Defines whether an object that contains information about the
52+
* matches should be returned or not
53+
* @param facets Facets for which to retrieve the matching count
5454
* @param sort Sort queries by an attribute value
5555
* @return search results, as raw data
5656
* @throws MeilisearchException Search Exception or Client Error
@@ -68,8 +68,8 @@ String rawSearch(
6868
String highlightPostTag,
6969
String[] attributesToHighlight,
7070
String[] filter,
71-
boolean matches,
72-
String[] facetsDistribution,
71+
boolean showMatchesPosition,
72+
String[] facets,
7373
String[] sort)
7474
throws MeilisearchException {
7575
String requestQuery = "/indexes/" + uid + "/search";
@@ -86,8 +86,8 @@ String rawSearch(
8686
highlightPostTag,
8787
attributesToHighlight,
8888
filter,
89-
matches,
90-
facetsDistribution,
89+
showMatchesPosition,
90+
facets,
9191
sort);
9292
return httpClient.post(requestQuery, sr, String.class);
9393
}
@@ -131,9 +131,9 @@ SearchResult search(String uid, String q) throws MeilisearchException {
131131
* @param highlightPostTag String to customize highlight tag after every highlighted query terms
132132
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
133133
* @param filter Filter queries by an attribute value
134-
* @param matches Defines whether an object that contains information about the matches should
135-
* be returned or not
136-
* @param facetsDistribution Facets for which to retrieve the matching count
134+
* @param showMatchesPosition Defines whether an object that contains information about the
135+
* matches should be returned or not
136+
* @param facets Facets for which to retrieve the matching count
137137
* @param sort Sort queries by an attribute value
138138
* @return search results
139139
* @throws MeilisearchException Search Exception or Client Error
@@ -151,8 +151,8 @@ SearchResult search(
151151
String highlightPostTag,
152152
String[] attributesToHighlight,
153153
String[] filter,
154-
boolean matches,
155-
String[] facetsDistribution,
154+
boolean showMatchesPosition,
155+
String[] facets,
156156
String[] sort)
157157
throws MeilisearchException {
158158
return httpClient.jsonHandler.decode(
@@ -169,8 +169,8 @@ SearchResult search(
169169
highlightPostTag,
170170
attributesToHighlight,
171171
filter,
172-
matches,
173-
facetsDistribution,
172+
showMatchesPosition,
173+
facets,
174174
sort),
175175
SearchResult.class);
176176
}

src/main/java/com/meilisearch/sdk/SearchRequest.java

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class SearchRequest {
2222
private String[] attributesToHighlight;
2323
private String[] filter;
2424
private String[][] filterArray;
25-
private boolean matches;
26-
private String[] facetsDistribution;
25+
private boolean showMatchesPosition;
26+
private String[] facets;
2727
private String[] sort;
2828

2929
/** Empty SearchRequest constructor */
@@ -32,7 +32,7 @@ public SearchRequest() {}
3232
/**
3333
* Constructor for SearchRequest for building search queries with the default values: offset: 0,
3434
* limit: 20, attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200,
35-
* attributesToHighlight: null, filter: null, matches: false, facetsDistribution: null, sort:
35+
* attributesToHighlight: null, filter: null, showMatchesPosition: false, facets: null, sort:
3636
* null
3737
*
3838
* @param q Query String
@@ -44,7 +44,7 @@ public SearchRequest(String q) {
4444
/**
4545
* Constructor for SearchRequest for building search queries with the default values: limit: 20,
4646
* attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200, attributesToHighlight:
47-
* null, filter: null, matches: false, facetsDistribution: null, sort: null
47+
* null, filter: null, showMatchesPosition: false, facets: null, sort: null
4848
*
4949
* @param q Query String
5050
* @param offset Number of documents to skip
@@ -56,7 +56,7 @@ public SearchRequest(String q, int offset) {
5656
/**
5757
* Constructor for SearchRequest for building search queries with the default values:
5858
* attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200, attributesToHighlight:
59-
* null, filter: null, matches: false, facetsDistribution: null, sort: null
59+
* null, filter: null, showMatchesPosition: false, facets: null, sort: null
6060
*
6161
* @param q Query String
6262
* @param offset Number of documents to skip
@@ -68,8 +68,8 @@ public SearchRequest(String q, int offset, int limit) {
6868

6969
/**
7070
* Constructor for SearchRequest for building search queries with the default values:
71-
* attributesToCrop: null, cropLength: 200, attributesToHighlight: null, filter: null, matches:
72-
* false, facetsDistribution: null, sort: null
71+
* attributesToCrop: null, cropLength: 200, attributesToHighlight: null, filter: null,
72+
* showMatchesPosition: false, facets: null, sort: null
7373
*
7474
* @param q Query String
7575
* @param offset Number of documents to skip
@@ -105,9 +105,9 @@ public SearchRequest(String q, int offset, int limit, String[] attributesToRetri
105105
* @param cropLength Length used to crop field values
106106
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
107107
* @param filter Filter queries by an attribute value
108-
* @param matches Defines whether an object that contains information about the matches should
109-
* be returned or not
110-
* @param facetsDistribution Facets for which to retrieve the matching count
108+
* @param showMatchesPosition Defines whether an object that contains information about the
109+
* matches should be returned or not
110+
* @param facets Facets for which to retrieve the matching count
111111
* @param sort Sort queries by an attribute value
112112
*/
113113
public SearchRequest(
@@ -119,8 +119,8 @@ public SearchRequest(
119119
int cropLength,
120120
String[] attributesToHighlight,
121121
String[] filter,
122-
boolean matches,
123-
String[] facetsDistribution,
122+
boolean showMatchesPosition,
123+
String[] facets,
124124
String[] sort) {
125125
this(
126126
q,
@@ -135,8 +135,8 @@ public SearchRequest(
135135
attributesToHighlight,
136136
filter,
137137
null,
138-
matches,
139-
facetsDistribution,
138+
showMatchesPosition,
139+
facets,
140140
sort);
141141
}
142142

@@ -154,9 +154,9 @@ public SearchRequest(
154154
* @param highlightPostTag String to customize highlight tag after every highlighted query terms
155155
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
156156
* @param filter Filter queries by an attribute value
157-
* @param matches Defines whether an object that contains information about the matches should
158-
* be returned or not
159-
* @param facetsDistribution Facets for which to retrieve the matching count
157+
* @param showMatchesPosition Defines whether an object that contains information about the
158+
* matches should be returned or not
159+
* @param facets Facets for which to retrieve the matching count
160160
* @param sort Sort queries by an attribute value
161161
*/
162162
public SearchRequest(
@@ -171,8 +171,8 @@ public SearchRequest(
171171
String highlightPostTag,
172172
String[] attributesToHighlight,
173173
String[] filter,
174-
boolean matches,
175-
String[] facetsDistribution,
174+
boolean showMatchesPosition,
175+
String[] facets,
176176
String[] sort) {
177177
this(
178178
q,
@@ -187,8 +187,8 @@ public SearchRequest(
187187
attributesToHighlight,
188188
filter,
189189
null,
190-
matches,
191-
facetsDistribution,
190+
showMatchesPosition,
191+
facets,
192192
sort);
193193
}
194194

@@ -203,9 +203,9 @@ public SearchRequest(
203203
* @param cropLength Length used to crop field values
204204
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
205205
* @param filterArray String array that can take multiple nested filters
206-
* @param matches Defines whether an object that contains information about the matches should
207-
* be returned or not
208-
* @param facetsDistribution Facets for which to retrieve the matching count
206+
* @param showMatchesPosition Defines whether an object that contains information about the
207+
* matches should be returned or not
208+
* @param facets Facets for which to retrieve the matching count
209209
* @param sort Sort queries by an attribute value
210210
*/
211211
public SearchRequest(
@@ -217,8 +217,8 @@ public SearchRequest(
217217
int cropLength,
218218
String[] attributesToHighlight,
219219
String[][] filterArray,
220-
boolean matches,
221-
String[] facetsDistribution,
220+
boolean showMatchesPosition,
221+
String[] facets,
222222
String[] sort) {
223223
this(
224224
q,
@@ -233,8 +233,8 @@ public SearchRequest(
233233
attributesToHighlight,
234234
null,
235235
filterArray,
236-
matches,
237-
facetsDistribution,
236+
showMatchesPosition,
237+
facets,
238238
sort);
239239
}
240240

@@ -252,9 +252,9 @@ public SearchRequest(
252252
* @param highlightPostTag String to customize highlight tag after every highlighted query terms
253253
* @param attributesToHighlight Attributes whose values will contain highlighted matching terms
254254
* @param filterArray String array that can take multiple nested filters
255-
* @param matches Defines whether an object that contains information about the matches should
256-
* be returned or not
257-
* @param facetsDistribution Facets for which to retrieve the matching count
255+
* @param showMatchesPosition Defines whether an object that contains information about the
256+
* matches should be returned or not
257+
* @param facets Facets for which to retrieve the matching count
258258
* @param sort Sort queries by an attribute value
259259
*/
260260
public SearchRequest(
@@ -269,8 +269,8 @@ public SearchRequest(
269269
String highlightPostTag,
270270
String[] attributesToHighlight,
271271
String[][] filterArray,
272-
boolean matches,
273-
String[] facetsDistribution,
272+
boolean showMatchesPosition,
273+
String[] facets,
274274
String[] sort) {
275275
this(
276276
q,
@@ -285,8 +285,8 @@ public SearchRequest(
285285
attributesToHighlight,
286286
null,
287287
filterArray,
288-
matches,
289-
facetsDistribution,
288+
showMatchesPosition,
289+
facets,
290290
sort);
291291
}
292292

@@ -303,8 +303,8 @@ private SearchRequest(
303303
String[] attributesToHighlight,
304304
String[] filter,
305305
String[][] filterArray,
306-
boolean matches,
307-
String[] facetsDistribution,
306+
boolean showMatchesPosition,
307+
String[] facets,
308308
String[] sort) {
309309
this.q = q;
310310
this.offset = offset;
@@ -318,8 +318,8 @@ private SearchRequest(
318318
this.attributesToHighlight = attributesToHighlight;
319319
this.setFilter(filter);
320320
this.setFilterArray(filterArray);
321-
this.matches = matches;
322-
this.facetsDistribution = facetsDistribution;
321+
this.showMatchesPosition = showMatchesPosition;
322+
this.facets = facets;
323323
this.sort = sort;
324324
}
325325

@@ -352,8 +352,8 @@ public String toString() {
352352
.put("cropMarker", this.cropMarker)
353353
.put("highlightPreTag", this.highlightPreTag)
354354
.put("highlightPostTag", this.highlightPostTag)
355-
.put("matches", this.matches)
356-
.put("facetsDistribution", this.facetsDistribution)
355+
.put("showMatchesPosition", this.showMatchesPosition)
356+
.put("facets", this.facets)
357357
.put("sort", this.sort)
358358
.putOpt("attributesToCrop", this.attributesToCrop)
359359
.putOpt("attributesToHighlight", this.attributesToHighlight)

src/main/java/com/meilisearch/sdk/model/SearchResult.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ public class SearchResult implements Serializable {
1717
protected ArrayList<HashMap<String, Object>> hits;
1818
protected int offset;
1919
protected int limit;
20-
protected int nbHits;
21-
protected boolean exhaustiveNbHits;
22-
protected Object facetsDistribution;
23-
protected boolean exhaustiveFacetsCount;
20+
protected int estimatedTotalHits;
21+
protected Object facetDistribution;
2422
protected int processingTimeMs;
2523
protected String query;
2624

src/test/java/com/meilisearch/integration/SearchNestedTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ final class Results {
2424
int offset;
2525
int limit;
2626
int nbHits;
27-
boolean exhaustiveNbHits;
2827
int processingTimeMs;
2928
String query;
3029
}

src/test/java/com/meilisearch/integration/SearchTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ final class Results {
2727
Movie[] hits;
2828
int offset;
2929
int limit;
30-
int nbHits;
31-
boolean exhaustiveNbHits;
30+
int estimatedTotalHits;
3231
int processingTimeMs;
3332
String query;
3433
}
@@ -59,11 +58,11 @@ public void testBasicSearch() throws Exception {
5958

6059
SearchResult searchResult = index.search("batman");
6160

62-
assertNull(searchResult.getFacetsDistribution());
61+
assertNull(searchResult.getFacetDistribution());
6362
assertEquals(1, searchResult.getHits().size());
6463
assertEquals(0, searchResult.getOffset());
6564
assertEquals(20, searchResult.getLimit());
66-
assertEquals(1, searchResult.getNbHits());
65+
assertEquals(1, searchResult.getEstimatedTotalHits());
6766
}
6867

6968
/** Test search offset */
@@ -81,7 +80,7 @@ public void testSearchOffset() throws Exception {
8180
SearchResult searchResult = index.search(searchRequest);
8281

8382
assertEquals(10, searchResult.getHits().size());
84-
assertEquals(30, searchResult.getNbHits());
83+
assertEquals(30, searchResult.getEstimatedTotalHits());
8584
}
8685

8786
/** Test search limit */
@@ -99,7 +98,7 @@ public void testSearchLimit() throws Exception {
9998
SearchResult searchResult = index.search(searchRequest);
10099

101100
assertEquals(2, searchResult.getHits().size());
102-
assertEquals(30, searchResult.getNbHits());
101+
assertEquals(30, searchResult.getEstimatedTotalHits());
103102
}
104103

105104
/** Test search attributesToRetrieve */
@@ -316,13 +315,12 @@ public void testSearchFacetsDistribution() throws Exception {
316315
settings.setFilterableAttributes(new String[] {"title"});
317316
index.waitForTask(index.updateSettings(settings).getUid());
318317

319-
SearchRequest searchRequest =
320-
new SearchRequest("knight").setFacetsDistribution(new String[] {"*"});
318+
SearchRequest searchRequest = new SearchRequest("knight").setFacets(new String[] {"*"});
321319

322320
SearchResult searchResult = index.search(searchRequest);
323321

324322
assertEquals(1, searchResult.getHits().size());
325-
assertNotNull(searchResult.getFacetsDistribution());
323+
assertNotNull(searchResult.getFacetDistribution());
326324
}
327325

328326
/** Test search sort */
@@ -454,7 +452,7 @@ public void testSearchMatches() throws Exception {
454452

455453
index.waitForTask(task.getUid());
456454

457-
SearchRequest searchRequest = new SearchRequest("and").setMatches(true);
455+
SearchRequest searchRequest = new SearchRequest("and").setShowMatchesPosition(true);
458456
SearchResult searchResult = index.search(searchRequest);
459457

460458
assertEquals(20, searchResult.getHits().size());

0 commit comments

Comments
 (0)