-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
652: Add multi search client method r=curquiza a=jd2024 # Pull Request ## Related issue Fixes #591 ## What does this PR do? - Add multi search client method ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: Josue Valenzuela <[email protected]> Co-authored-by: jd2024 <[email protected]> Co-authored-by: Bruno Casali <[email protected]> Co-authored-by: Clémentine U. - curqui <[email protected]>
- Loading branch information
Showing
7 changed files
with
201 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.meilisearch.sdk; | ||
|
||
import com.meilisearch.sdk.model.MatchingStrategy; | ||
import lombok.*; | ||
import lombok.experimental.Accessors; | ||
import org.json.JSONObject; | ||
|
||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
@NoArgsConstructor(access = AccessLevel.PACKAGE) | ||
@Getter | ||
@Setter | ||
@Accessors(chain = true) | ||
public class IndexSearchRequest { | ||
private String indexUid; | ||
private String q; | ||
private Integer offset; | ||
private Integer limit; | ||
private String[] attributesToRetrieve; | ||
private String[] attributesToCrop; | ||
private Integer cropLength; | ||
private String cropMarker; | ||
private String highlightPreTag; | ||
private String highlightPostTag; | ||
private MatchingStrategy matchingStrategy; | ||
private String[] attributesToHighlight; | ||
private String[] filter; | ||
private String[][] filterArray; | ||
private Boolean showMatchesPosition; | ||
private String[] facets; | ||
private String[] sort; | ||
protected Integer page; | ||
protected Integer hitsPerPage; | ||
protected Boolean showRankingScore; | ||
|
||
/** | ||
* Constructor for MultiSearchRequest for building search queries with the default values: | ||
* offset: 0, limit: 20, attributesToRetrieve: ["*"], attributesToCrop: null, cropLength: 200, | ||
* attributesToHighlight: null, filter: null, showMatchesPosition: false, facets: null, sort: | ||
* null | ||
* | ||
* @param indexUid uid of the requested index String | ||
*/ | ||
public IndexSearchRequest(String indexUid) { | ||
this(); | ||
this.indexUid = indexUid; | ||
} | ||
|
||
/** | ||
* Method to set the Query String | ||
* | ||
* <p>This method is an alias of setQ() | ||
* | ||
* @param q Query String | ||
* @return SearchRequest | ||
*/ | ||
public IndexSearchRequest setQuery(String q) { | ||
return setQ(q); | ||
} | ||
|
||
/** | ||
* Method that returns the JSON String of the SearchRequest | ||
* | ||
* @return JSON String of the SearchRequest query | ||
*/ | ||
@Override | ||
public String toString() { | ||
JSONObject jsonObject = | ||
new JSONObject() | ||
.put("q", this.q) | ||
.put("offset", this.offset) | ||
.put("limit", this.limit) | ||
.put("attributesToRetrieve", this.attributesToRetrieve) | ||
.put("cropLength", this.cropLength) | ||
.put("cropMarker", this.cropMarker) | ||
.put("highlightPreTag", this.highlightPreTag) | ||
.put("highlightPostTag", this.highlightPostTag) | ||
.put( | ||
"matchingStrategy", | ||
this.matchingStrategy == null | ||
? null | ||
: this.matchingStrategy.toString()) | ||
.put("showMatchesPosition", this.showMatchesPosition) | ||
.put("facets", this.facets) | ||
.put("sort", this.sort) | ||
.put("page", this.page) | ||
.put("hitsPerPage", this.hitsPerPage) | ||
.putOpt("attributesToCrop", this.attributesToCrop) | ||
.putOpt("attributesToHighlight", this.attributesToHighlight) | ||
.putOpt("filter", this.filter) | ||
.putOpt("filter", this.filterArray) | ||
.putOpt("showRankingScore", this.showRankingScore); | ||
|
||
return jsonObject.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.meilisearch.sdk; | ||
|
||
import java.util.ArrayList; | ||
import lombok.*; | ||
|
||
public class MultiSearchRequest { | ||
private ArrayList<IndexSearchRequest> queries; | ||
|
||
public MultiSearchRequest() { | ||
this.queries = new ArrayList(); | ||
} | ||
|
||
/** | ||
* Method to add new Query | ||
* | ||
* @param search Query IndexSearchRequest | ||
* @return MultiSearchRequest | ||
*/ | ||
public MultiSearchRequest addQuery(IndexSearchRequest search) { | ||
this.queries.add(search); | ||
return this; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/meilisearch/sdk/model/MultiSearchResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.meilisearch.sdk.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
/** | ||
* Multi search response | ||
* | ||
* <p>https://www.meilisearch.com/docs/reference/api/multi_search#response | ||
*/ | ||
@Getter | ||
@ToString | ||
public class MultiSearchResult implements Searchable { | ||
String indexUid; | ||
ArrayList<HashMap<String, Object>> hits; | ||
Object facetDistribution; | ||
int processingTimeMs; | ||
String query; | ||
int offset; | ||
int limit; | ||
int estimatedTotalHits; | ||
|
||
public MultiSearchResult() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters