forked from meilisearch/meilisearch-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchRequest.java
More file actions
122 lines (115 loc) · 4.51 KB
/
SearchRequest.java
File metadata and controls
122 lines (115 loc) · 4.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.meilisearch.sdk;
import com.meilisearch.sdk.model.Hybrid;
import com.meilisearch.sdk.model.MatchingStrategy;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.json.JSONObject;
/** Search request query string builder */
@Builder
@AllArgsConstructor(access = AccessLevel.PACKAGE)
@NoArgsConstructor(access = AccessLevel.PACKAGE)
@Getter
@Setter
@Accessors(chain = true)
public class SearchRequest {
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[] attributesToSearchOn;
private String[] filter;
private String[][] filterArray;
private Boolean showMatchesPosition;
private String[] facets;
private String[] sort;
protected Integer page;
protected Integer hitsPerPage;
protected Boolean showRankingScore;
protected Boolean showRankingScoreDetails;
protected Double rankingScoreThreshold;
protected String[] locales;
protected String distinct;
protected Hybrid hybrid;
protected Double[] vector;
protected Boolean retrieveVectors;
/**
* Constructor for SearchRequest 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, showRankingScore: false, showRankingScoreDetails: false, rankingScoreThreshold: null,
* retrieveVectors: false
*
* @param q Query String
*/
public SearchRequest(String q) {
this();
this.q = q;
}
/**
* Method to set the Query String
*
* <p>This method is an alias of setQ()
*
* @param q Query String
* @return SearchRequest
*/
public SearchRequest 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("attributesToSearchOn", this.attributesToSearchOn)
.putOpt("filter", this.filter)
.putOpt("filter", this.filterArray)
.putOpt("showRankingScore", this.showRankingScore)
.putOpt("showRankingScoreDetails", this.showRankingScoreDetails)
.putOpt("rankingScoreThreshold", this.rankingScoreThreshold)
.putOpt("locales", this.locales)
.putOpt("distinct", this.distinct)
.putOpt("vector", this.vector)
.putOpt("retrieveVectors", this.retrieveVectors);
if (this.hybrid != null) {
jsonObject.put("hybrid", this.hybrid.toJSONObject());
}
return jsonObject.toString();
}
}