Skip to content

Commit

Permalink
Merge #204
Browse files Browse the repository at this point in the history
204: Changes related to the next MeiliSearch release (v0.22.0) r=alallema a=meili-bot

Related to this issue: meilisearch/integration-guides#139

This PR:
- gathers the changes related to the next MeiliSearch release (v0.22.0) so that this package is ready when the official release is out.
- should pass the tests against the [latest pre-release of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases).
- might eventually contain test failures until the MeiliSearch v0.22.0 is out.

⚠️ This PR should NOT be merged until the next release of MeiliSearch (v0.22.0) is out.

_This PR is auto-generated for the [pre-release week](https://github.com/meilisearch/integration-guides/blob/master/guides/pre-release-week.md) purpose._

- [x] New settings: sortableAttributes + Tests
- [x] New search parameter: sort + Tests
- [x] New sort ranking rules

Co-authored-by: meili-bot <[email protected]>
Co-authored-by: alallema <[email protected]>
Co-authored-by: Amélie <[email protected]>
  • Loading branch information
4 people authored Sep 13, 2021
2 parents 892c967 + badc65e commit 1e6b92c
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ System.out.println(results.getHits());

## 🤖 Compatibility with MeiliSearch

This package only guarantees the compatibility with the [version v0.21.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.21.0).
This package only guarantees the compatibility with the [version v0.22.0 of MeiliSearch](https://github.com/meilisearch/MeiliSearch/releases/tag/v0.22.0).

## 💡 Learn More

Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/meilisearch/sdk/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ String rawSearch(String uid, String q) throws Exception {
* @param matches Defines whether an object that contains information about the matches should
* be returned or not
* @param facetsDistribution Facets for which to retrieve the matching count
* @param sort Sort queries by an attribute value
* @return search results, as raw data
* @throws Exception Search Exception or Client Error
*/
Expand All @@ -59,7 +60,8 @@ String rawSearch(
String[] attributesToHighlight,
String filter,
boolean matches,
String[] facetsDistribution)
String[] facetsDistribution,
String[] sort)
throws Exception {
String requestQuery = "/indexes/" + uid + "/search";
SearchRequest sr =
Expand All @@ -73,7 +75,8 @@ String rawSearch(
attributesToHighlight,
filter,
matches,
facetsDistribution);
facetsDistribution,
sort);
return meilisearchHttpRequest.post(requestQuery, sr.getQuery());
}

Expand Down Expand Up @@ -116,6 +119,7 @@ SearchResult search(String uid, String q) throws Exception {
* @param matches Defines whether an object that contains information about the matches should
* be returned or not
* @param facetsDistribution Facets for which to retrieve the matching count
* @param sort Sort queries by an attribute value
* @return search results
* @throws Exception Search Exception or Client Error
*/
Expand All @@ -130,7 +134,8 @@ SearchResult search(
String[] attributesToHighlight,
String filter,
boolean matches,
String[] facetsDistribution)
String[] facetsDistribution,
String[] sort)
throws Exception {
return jsonGson.decode(
rawSearch(
Expand All @@ -144,7 +149,8 @@ SearchResult search(
attributesToHighlight,
filter,
matches,
facetsDistribution),
facetsDistribution,
sort),
SearchResult.class);
}

Expand Down
42 changes: 34 additions & 8 deletions src/main/java/com/meilisearch/sdk/SearchRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ public class SearchRequest {
private String filter;
private boolean matches;
private String[] facetsDistribution;
private String[] sort;

/** Empty SearchRequest constructor */
public SearchRequest() {}

/**
* Constructor for SearchRequest for building search queries with the default values: offset: 0,
* limit: 20, attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200,
* attributesToHighlight: null, filter: null, matches: false, facetsDistribution: null
* attributesToHighlight: null, filter: null, matches: false, facetsDistribution: null, sort:
* null
*
* @param q Query String
*/
Expand All @@ -32,7 +34,7 @@ public SearchRequest(String q) {
/**
* Constructor for SearchRequest for building search queries with the default values: limit: 20,
* attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200, attributesToHighlight:
* null, filter: null, matches: false, facetsDistribution: null
* null, filter: null, matches: false, facetsDistribution: null, sort: null
*
* @param q Query String
* @param offset Number of documents to skip
Expand All @@ -44,7 +46,7 @@ public SearchRequest(String q, int offset) {
/**
* Constructor for SearchRequest for building search queries with the default values:
* attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200, attributesToHighlight:
* null, filter: null, matches: false, facetsDistribution: null
* null, filter: null, matches: false, facetsDistribution: null, sort: null
*
* @param q Query String
* @param offset Number of documents to skip
Expand All @@ -57,15 +59,15 @@ public SearchRequest(String q, int offset, int limit) {
/**
* Constructor for SearchRequest for building search queries with the default values:
* attributesToCrop: null, cropLength: 200, attributesToHighlight: null, filter: null, matches:
* false, facetsDistribution: null
* false, facetsDistribution: null, sort: null
*
* @param q Query String
* @param offset Number of documents to skip
* @param limit Maximum number of documents returned
* @param attributesToRetrieve Attributes to display in the returned documents
*/
public SearchRequest(String q, int offset, int limit, String[] attributesToRetrieve) {
this(q, offset, limit, attributesToRetrieve, null, 200, null, null, false, null);
this(q, offset, limit, attributesToRetrieve, null, 200, null, null, false, null, null);
}

/**
Expand All @@ -82,6 +84,7 @@ public SearchRequest(String q, int offset, int limit, String[] attributesToRetri
* @param matches Defines whether an object that contains information about the matches should
* be returned or not
* @param facetsDistribution Facets for which to retrieve the matching count
* @param sort Sort queries by an attribute value
*/
public SearchRequest(
String q,
Expand All @@ -93,7 +96,8 @@ public SearchRequest(
String[] attributesToHighlight,
String filter,
boolean matches,
String[] facetsDistribution) {
String[] facetsDistribution,
String[] sort) {
this.q = q;
this.offset = offset;
this.limit = limit;
Expand All @@ -104,6 +108,7 @@ public SearchRequest(
this.setFilter(filter);
this.matches = matches;
this.facetsDistribution = facetsDistribution;
this.sort = sort;
}

/**
Expand Down Expand Up @@ -181,7 +186,7 @@ public String getFilter() {
/**
* Method to return the matches
*
* @return Defines whether an object that contains information about the matches should be
* @return defines whether an object that contains information about the matches should be
* returned or not
*/
public boolean getMatches() {
Expand All @@ -197,6 +202,15 @@ public String[] getFacetsDistribution() {
return facetsDistribution;
}

/**
* Method for returning the sort
*
* @return Sort queries by an attribute value
*/
public String[] getSort() {
return sort;
}

/**
* Method to set the Query String
*
Expand Down Expand Up @@ -310,6 +324,17 @@ public SearchRequest setFacetsDistribution(String[] facetsDistribution) {
return this;
}

/**
* Method to set the sort
*
* @param sort Sort queries by an attribute value
* @return altered SearchRequest
*/
public SearchRequest setSort(String[] sort) {
this.sort = sort;
return this;
}

/**
* Method that returns the JSON String of the SearchRequest
*
Expand All @@ -325,7 +350,8 @@ String getQuery() {
.put("attributesToRetrieve", this.attributesToRetrieve)
.put("cropLength", this.cropLength)
.put("matches", this.matches)
.put("facetsDistribution", this.facetsDistribution);
.put("facetsDistribution", this.facetsDistribution)
.put("sort", this.sort);
if (this.attributesToCrop != null) {
jsonObject.put("attributesToCrop", this.attributesToCrop);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/meilisearch/sdk/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Settings {
@Getter @Setter private String distinctAttribute;
@Getter @Setter private String[] searchableAttributes;
@Getter @Setter private String[] displayedAttributes;
@Getter @Setter private String[] sortableAttributes;

/** Empty SettingsRequest constructor */
public Settings() {}
Expand Down Expand Up @@ -50,6 +51,9 @@ String getUpdateQuery() {
if (this.getDisplayedAttributes() != null) {
jsonObject.put("displayedAttributes", this.getDisplayedAttributes());
}
if (this.getSortableAttributes() != null) {
jsonObject.put("sortableAttributes", this.getSortableAttributes());
}
return jsonObject.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SearchRequest {
private final int cropLength;
private final List<String> attributesToHighlight;
private final boolean matches;
private final List<String> sort;

public SearchRequest(String q) {
this(q, 0);
Expand All @@ -27,7 +28,7 @@ public SearchRequest(String q, int offset, int limit) {
}

public SearchRequest(String q, int offset, int limit, List<String> attributesToRetrieve) {
this(q, offset, limit, attributesToRetrieve, null, 200, null, null, false);
this(q, offset, limit, attributesToRetrieve, null, 200, null, null, false, null);
}

public SearchRequest(
Expand All @@ -39,7 +40,8 @@ public SearchRequest(
int cropLength,
List<String> attributesToHighlight,
String filter,
boolean matches) {
boolean matches,
List<String> sort) {
this.q = q;
this.offset = offset;
this.limit = limit;
Expand All @@ -49,6 +51,7 @@ public SearchRequest(
this.attributesToHighlight = attributesToHighlight;
this.filter = filter;
this.matches = matches;
this.sort = sort;
}

public String getQ() {
Expand Down Expand Up @@ -83,6 +86,10 @@ public String getFilter() {
return filter;
}

public List<String> getSort() {
return sort;
}

public boolean isMatches() {
return matches;
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/meilisearch/sdk/api/index/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Settings {
private String distinctAttribute;
private String[] searchableAttributes;
private String[] displayedAttributes;
private String[] sortableAttributes;

/** Empty SettingsRequest constructor */
public Settings() {}
Expand Down Expand Up @@ -76,4 +77,12 @@ public String[] getDisplayedAttributes() {
public void setDisplayedAttributes(String[] displayedAttributes) {
this.displayedAttributes = displayedAttributes;
}

public String[] getSortableAttributes() {
return sortableAttributes;
}

public void setSortableAttributes(String[] sortableAttributes) {
this.sortableAttributes = sortableAttributes;
}
}
Loading

0 comments on commit 1e6b92c

Please sign in to comment.