Skip to content

Commit 1ad142a

Browse files
Add preset to SearchParameters and MultiSearchParameters
1 parent f533d9d commit 1ad142a

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

src/main/java/org/typesense/model/MultiSearchParameters.java

+25
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ public class MultiSearchParameters {
200200
**/
201201
private Boolean preSegmentedQuery = null;
202202

203+
@Schema(description = "Search using a bunch of search parameters by setting this parameter to the name of the existing Preset. ")
204+
/**
205+
* Search using a bunch of search parameters by setting this parameter to the name of the existing Preset.
206+
**/
207+
private String preset = null;
208+
203209
@Schema(description = "If you have some overrides defined but want to disable all of them during query time, you can do that by setting this parameter to false ")
204210
/**
205211
* If you have some overrides defined but want to disable all of them during query time, you can do that by setting this parameter to false
@@ -793,6 +799,24 @@ public MultiSearchParameters preSegmentedQuery(Boolean preSegmentedQuery) {
793799
return this;
794800
}
795801

802+
/**
803+
* Search using a bunch of search parameters by setting this parameter to the name of the existing Preset.
804+
* @return preset
805+
**/
806+
@JsonProperty("preset")
807+
public String getPreset() {
808+
return preset;
809+
}
810+
811+
public void setPreset(String preset) {
812+
this.preset = preset;
813+
}
814+
815+
public MultiSearchParameters preset(String preset) {
816+
this.preset = preset;
817+
return this;
818+
}
819+
796820
/**
797821
* If you have some overrides defined but want to disable all of them during query time, you can do that by setting this parameter to false
798822
* @return enableOverrides
@@ -991,6 +1015,7 @@ public String toString() {
9911015
sb.append(" hiddenHits: ").append(toIndentedString(hiddenHits)).append("\n");
9921016
sb.append(" highlightFields: ").append(toIndentedString(highlightFields)).append("\n");
9931017
sb.append(" preSegmentedQuery: ").append(toIndentedString(preSegmentedQuery)).append("\n");
1018+
sb.append(" preset: ").append(toIndentedString(preset)).append("\n");
9941019
sb.append(" enableOverrides: ").append(toIndentedString(enableOverrides)).append("\n");
9951020
sb.append(" prioritizeExactMatch: ").append(toIndentedString(prioritizeExactMatch)).append("\n");
9961021
sb.append(" exhaustiveSearch: ").append(toIndentedString(exhaustiveSearch)).append("\n");

src/main/java/org/typesense/model/SearchParameters.java

+25
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ public class SearchParameters {
207207
**/
208208
private Boolean preSegmentedQuery = null;
209209

210+
@Schema(description = "Search using a bunch of search parameters by setting this parameter to the name of the existing Preset. ")
211+
/**
212+
* Search using a bunch of search parameters by setting this parameter to the name of the existing Preset.
213+
**/
214+
private String preset = null;
215+
210216
@Schema(description = "If you have some overrides defined but want to disable all of them during query time, you can do that by setting this parameter to false ")
211217
/**
212218
* If you have some overrides defined but want to disable all of them during query time, you can do that by setting this parameter to false
@@ -848,6 +854,24 @@ public SearchParameters preSegmentedQuery(Boolean preSegmentedQuery) {
848854
return this;
849855
}
850856

857+
/**
858+
* Search using a bunch of search parameters by setting this parameter to the name of the existing Preset.
859+
* @return preset
860+
**/
861+
@JsonProperty("preset")
862+
public String getPreset() {
863+
return preset;
864+
}
865+
866+
public void setPreset(String preset) {
867+
this.preset = preset;
868+
}
869+
870+
public SearchParameters preset(String preset) {
871+
this.preset = preset;
872+
return this;
873+
}
874+
851875
/**
852876
* If you have some overrides defined but want to disable all of them during query time, you can do that by setting this parameter to false
853877
* @return enableOverrides
@@ -1084,6 +1108,7 @@ public String toString() {
10841108
sb.append(" highlightFields: ").append(toIndentedString(highlightFields)).append("\n");
10851109
sb.append(" splitJoinTokens: ").append(toIndentedString(splitJoinTokens)).append("\n");
10861110
sb.append(" preSegmentedQuery: ").append(toIndentedString(preSegmentedQuery)).append("\n");
1111+
sb.append(" preset: ").append(toIndentedString(preset)).append("\n");
10871112
sb.append(" enableOverrides: ").append(toIndentedString(enableOverrides)).append("\n");
10881113
sb.append(" prioritizeExactMatch: ").append(toIndentedString(prioritizeExactMatch)).append("\n");
10891114
sb.append(" maxCandidates: ").append(toIndentedString(maxCandidates)).append("\n");

src/test/java/org/typesense/api/DocumentsTest.java

+16
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ void testCreateDocument() throws Exception {
6060
assertEquals("1", resp.get("id"));
6161
}
6262

63+
@Test
64+
void testUnknownPresetsDoNotFailSearches() throws Exception {
65+
helper.createTestDocument();
66+
Map<String, Object> resp = client.collections("books").documents("1").retrieve();
67+
assertEquals("Romeo and juliet", resp.get("title"));
68+
69+
SearchParameters params = new SearchParameters()
70+
.q("Romeo")
71+
.queryBy("title")
72+
.preset("non_existent_preset");
73+
74+
SearchResult searchResult = client.collections("books").documents().search(params);
75+
assertEquals(1, searchResult.getFound().intValue());
76+
assertEquals(1, searchResult.getHits().size());
77+
}
78+
6379
@Test
6480
void testUpsertDocument() throws Exception {
6581
helper.createTestDocument();

0 commit comments

Comments
 (0)