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 similar documents query to index meilisearch#755
- Loading branch information
1 parent
67e3467
commit 11c539d
Showing
10 changed files
with
193 additions
and
27 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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/meilisearch/sdk/SimilarDocumentRequest.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,52 @@ | ||
package com.meilisearch.sdk; | ||
|
||
import lombok.*; | ||
import lombok.experimental.Accessors; | ||
import org.json.JSONObject; | ||
|
||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
@Getter | ||
@Setter | ||
@Accessors(chain = true) | ||
public class SimilarDocumentRequest { | ||
private String id; | ||
private String embedder; | ||
private String[] attributesToRetrieve; | ||
private Integer offset; | ||
private Integer limit; | ||
private String filter; | ||
private Boolean showRankingScore; | ||
private Boolean showRankingScoreDetails; | ||
private Double rankingScoreThreshold; | ||
private Boolean retrieveVectors; | ||
|
||
|
||
/** | ||
* Constructor for SimilarDocumentsRequest for building search request for similar documents | ||
* with the default values: | ||
* id null, embedder "default", attributesToRetrieve ["*"], offset 0, limit 20, | ||
* filter null, showRankingScore false, showRankingScoreDetails false, rankingScoreThreshold null, | ||
* retrieveVectors false | ||
* | ||
*/ | ||
public SimilarDocumentRequest() {} | ||
|
||
@Override | ||
public String toString() { | ||
JSONObject jsonObject = | ||
new JSONObject() | ||
.put("id", this.id) | ||
.put("embedder", this.embedder) | ||
.put("attributesToRetrieve", this.attributesToRetrieve) | ||
.put("offset", this.offset) | ||
.put("limit", this.limit) | ||
.put("filter", this.filter) | ||
.put("showRankingScore", this.showRankingScore) | ||
.put("showRankingScoreDetails", this.showRankingScoreDetails) | ||
.put("rankingScoreThreshold", this.rankingScoreThreshold) | ||
.put("retrieveVectors", this.retrieveVectors); | ||
|
||
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,18 @@ | ||
package com.meilisearch.sdk.model; | ||
|
||
import lombok.*; | ||
import lombok.experimental.Accessors; | ||
|
||
@Builder | ||
@AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
@Getter | ||
@Setter | ||
@Accessors(chain = true) | ||
public class Embedders { | ||
protected String source; | ||
protected String model; | ||
protected String documentTemplate; | ||
protected Integer dimensions; | ||
|
||
public Embedders() {} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/meilisearch/sdk/model/SimilarDocumentsResults.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,25 @@ | ||
package com.meilisearch.sdk.model; | ||
|
||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
/** | ||
* Meilisearch similar documents results data structure | ||
* | ||
* @see <a href="https://www.meilisearch.com/docs/reference/api/similar#response-200-ok">API | ||
* specification</a> | ||
*/ | ||
@Getter | ||
@ToString | ||
public class SimilarDocumentsResults { | ||
ArrayList<HashMap<String, Object>> hits; | ||
String id; | ||
int processingTimeMs; | ||
int offset; | ||
int limit; | ||
int estimatedTotalHits; | ||
} | ||
|
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,32 @@ | ||
[ | ||
{ | ||
"title": "Shazam!", | ||
"release_year": 2019, | ||
"id": "287947", | ||
"_vectors": { "manual": [0.8, 0.4, -0.5]} | ||
}, | ||
{ | ||
"title": "Captain Marvel", | ||
"release_year": 2019, | ||
"id": "299537", | ||
"_vectors": { "manual": [0.6, 0.8, -0.2] } | ||
}, | ||
{ | ||
"title": "Escape Room", | ||
"release_year": 2019, | ||
"id": "522681", | ||
"_vectors": { "manual": [0.1, 0.6, 0.8] } | ||
}, | ||
{ | ||
"title": "How to Train Your Dragon: The Hidden World", | ||
"release_year": 2019, | ||
"id": "166428", | ||
"_vectors": { "manual": [0.7, 0.7, -0.4] } | ||
}, | ||
{ | ||
"title": "All Quiet on the Western Front", | ||
"release_year": 1930, | ||
"id": "143", | ||
"_vectors": { "manual": [-0.5, 0.3, 0.85] } | ||
} | ||
] |