forked from meilisearch/meilisearch-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add client multi search method meilisearch#591
- Loading branch information
Showing
6 changed files
with
199 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
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; | ||
|
||
/** | ||
* 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); | ||
|
||
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,25 @@ | ||
package com.meilisearch.sdk; | ||
|
||
import lombok.*; | ||
|
||
import java.util.ArrayList; | ||
|
||
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; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
package com.meilisearch.sdk.model; | ||
|
||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
/** | ||
* 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