Skip to content

Commit 36d583e

Browse files
authored
fix(specs): make the searchParams compatible with v4 [skip-bc] (#4108)
1 parent 1ed8dad commit 36d583e

File tree

13 files changed

+279
-259
lines changed

13 files changed

+279
-259
lines changed

clients/algoliasearch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/extensions/SearchForHits.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public fun SearchForHits.Companion.from(
8484
replaceSynonymsInHighlight = searchParamsObject.replaceSynonymsInHighlight,
8585
minProximity = searchParamsObject.minProximity,
8686
responseFields = searchParamsObject.responseFields,
87-
maxFacetHits = searchParamsObject.maxFacetHits,
8887
maxValuesPerFacet = searchParamsObject.maxValuesPerFacet,
8988
sortFacetValuesBy = searchParamsObject.sortFacetValuesBy,
9089
attributeCriteriaComputedByMinProximity = searchParamsObject.attributeCriteriaComputedByMinProximity,

clients/algoliasearch-client-swift/Sources/Search/Extra/SearchQueryExtension.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public extension SearchForHits {
8787
self.replaceSynonymsInHighlight = searchParamsObject.replaceSynonymsInHighlight
8888
self.minProximity = searchParamsObject.minProximity
8989
self.responseFields = searchParamsObject.responseFields
90-
self.maxFacetHits = searchParamsObject.maxFacetHits
9190
self.maxValuesPerFacet = searchParamsObject.maxValuesPerFacet
9291
self.sortFacetValuesBy = searchParamsObject.sortFacetValuesBy
9392
self.attributeCriteriaComputedByMinProximity = searchParamsObject.attributeCriteriaComputedByMinProximity
@@ -175,7 +174,6 @@ public extension SearchForFacets {
175174
self.replaceSynonymsInHighlight = searchParamsObject.replaceSynonymsInHighlight
176175
self.minProximity = searchParamsObject.minProximity
177176
self.responseFields = searchParamsObject.responseFields
178-
self.maxFacetHits = searchParamsObject.maxFacetHits
179177
self.maxValuesPerFacet = searchParamsObject.maxValuesPerFacet
180178
self.sortFacetValuesBy = searchParamsObject.sortFacetValuesBy
181179
self.attributeCriteriaComputedByMinProximity = searchParamsObject.attributeCriteriaComputedByMinProximity

generators/src/main/java/com/algolia/codegen/AlgoliaCSharpGenerator.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import com.algolia.codegen.exceptions.*;
44
import com.algolia.codegen.utils.*;
5+
import com.google.common.collect.ImmutableMap.Builder;
56
import com.samskivert.mustache.Mustache;
7+
import com.samskivert.mustache.Mustache.Lambda;
68
import io.swagger.v3.oas.models.OpenAPI;
79
import io.swagger.v3.oas.models.Operation;
810
import io.swagger.v3.oas.models.servers.Server;
@@ -156,4 +158,24 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
156158
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, List<Server> servers) {
157159
return Helpers.specifyCustomRequest(super.fromOperation(path, httpMethod, operation, servers));
158160
}
161+
162+
/** Convert a Seq type to a valid class name. */
163+
private String typeToName(String content) {
164+
// for dictionary, remove the key type
165+
String[] parts = content.replace("string, ", "").split("<");
166+
String name = "";
167+
for (int i = 0; i < parts.length; i++) {
168+
name += Helpers.capitalize(parts[i].replace(">", "").replace(",", "").replace(" ", ""));
169+
}
170+
return name;
171+
}
172+
173+
@Override
174+
protected Builder<String, Lambda> addMustacheLambdas() {
175+
Builder<String, Lambda> lambdas = super.addMustacheLambdas();
176+
177+
lambdas.put("type-to-name", (Mustache.Lambda) (fragment, writer) -> writer.write(typeToName(fragment.execute())));
178+
179+
return lambdas;
180+
}
159181
}

generators/src/main/java/com/algolia/codegen/AlgoliaSwiftGenerator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ public class AlgoliaSwiftGenerator extends Swift5ClientCodegen {
7373
"highlightresultoption",
7474
"ignoreplurals",
7575
"indexsettingsassearchparams",
76+
"insideboundingbox",
7677
"languages",
7778
"matchedgeolocation",
7879
"matchlevel",
7980
"mode",
8081
"numericfilters",
8182
"optionalfilters",
83+
"optionalwords",
8284
"params",
8385
"personalization",
8486
"promote",

playground/java/src/main/java/com/algolia/playground/Insights.java

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,31 @@
55
import com.algolia.config.LogLevel;
66
import com.algolia.model.insights.ClickEvent;
77
import com.algolia.model.insights.ClickedObjectIDs;
8-
import com.algolia.model.insights.EventsItems;
98
import com.algolia.model.insights.InsightsEvents;
109
import io.github.cdimascio.dotenv.Dotenv;
11-
1210
import java.util.List;
1311

1412
public class Insights {
1513

16-
public static void main(String[] args) throws Exception {
17-
var dotenv = Dotenv.configure().directory("../").load();
18-
var appId = dotenv.get("ALGOLIA_APPLICATION_ID");
19-
var apiKey = dotenv.get("ALGOLIA_SEARCH_KEY");
20-
var indexName = dotenv.get("SEARCH_INDEX");
14+
public static void main(String[] args) throws Exception {
15+
var dotenv = Dotenv.configure().directory("../").load();
16+
var appId = dotenv.get("ALGOLIA_APPLICATION_ID");
17+
var apiKey = dotenv.get("ALGOLIA_SEARCH_KEY");
18+
var indexName = dotenv.get("SEARCH_INDEX");
2119

22-
var options = new ClientOptions.Builder()
23-
.addAlgoliaAgentSegment("Playground")
24-
.setLogLevel(LogLevel.BODY)
25-
.build();
20+
var options = new ClientOptions.Builder().addAlgoliaAgentSegment("Playground").setLogLevel(LogLevel.BODY).build();
2621

27-
var client = new InsightsClient(appId, apiKey, options);
28-
var params = new InsightsEvents();
29-
var event = new ClickedObjectIDs()
30-
.setEventType(ClickEvent.CLICK)
31-
.setUserToken("user")
32-
.setIndex(indexName)
33-
.setObjectIDs(List.of("id123"))
34-
.setEventName("click");
35-
params.addEvents(event);
36-
var result = client.pushEvents(params);
37-
System.out.println(result);
38-
client.close();
39-
}
22+
var client = new InsightsClient(appId, apiKey, options);
23+
var params = new InsightsEvents();
24+
var event = new ClickedObjectIDs()
25+
.setEventType(ClickEvent.CLICK)
26+
.setUserToken("user")
27+
.setIndex(indexName)
28+
.setObjectIDs(List.of("id123"))
29+
.setEventName("click");
30+
params.addEvents(event);
31+
var result = client.pushEvents(params);
32+
System.out.println(result);
33+
client.close();
34+
}
4035
}

playground/java/src/main/java/com/algolia/playground/Search.java

Lines changed: 58 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,90 +2,85 @@
22

33
import com.algolia.api.SearchClient;
44
import com.algolia.config.ClientOptions;
5-
import com.algolia.config.LogLevel;
65
import com.algolia.model.search.*;
76
import io.github.cdimascio.dotenv.Dotenv;
8-
97
import java.util.Arrays;
108
import java.util.List;
119
import java.util.Map;
1210

1311
class Actor extends Hit {
1412

15-
public String name;
13+
public String name;
1614

17-
public Actor() {
18-
}
15+
public Actor() {}
1916

20-
public Actor(String name) {
21-
this.name = name;
22-
}
17+
public Actor(String name) {
18+
this.name = name;
19+
}
2320
}
2421

2522
public class Search {
2623

27-
public static void main(String[] args) throws Exception {
28-
var dotenv = Dotenv.configure().directory("../").load();
29-
var appId = dotenv.get("ALGOLIA_APPLICATION_ID");
30-
var apiKey = dotenv.get("ALGOLIA_ADMIN_KEY");
31-
var indexName = dotenv.get("SEARCH_INDEX");
32-
var query = dotenv.get("SEARCH_QUERY");
24+
public static void main(String[] args) throws Exception {
25+
var dotenv = Dotenv.configure().directory("../").load();
26+
var appId = dotenv.get("ALGOLIA_APPLICATION_ID");
27+
var apiKey = dotenv.get("ALGOLIA_ADMIN_KEY");
28+
var indexName = dotenv.get("SEARCH_INDEX");
29+
var query = dotenv.get("SEARCH_QUERY");
3330

34-
var options = new ClientOptions.Builder()
35-
.addAlgoliaAgentSegment("Playground", "1.0.0")
36-
//.setLogLevel(LogLevel.BODY)
37-
.build();
31+
var options = new ClientOptions.Builder()
32+
.addAlgoliaAgentSegment("Playground", "1.0.0")
33+
// .setLogLevel(LogLevel.BODY)
34+
.build();
3835

39-
var client = new SearchClient(appId, apiKey, options);
40-
var records = Arrays.asList(new Actor("Tom Cruise"), new Actor("Scarlett Johansson"));
41-
var batch = records.stream()
42-
.map(entry -> new BatchRequest().setAction(Action.ADD_OBJECT).setBody(entry))
43-
.toList();
44-
var response = client.batch(indexName, new BatchWriteParams().setRequests(batch));
45-
client.waitForTask(indexName, response.getTaskID());
36+
var client = new SearchClient(appId, apiKey, options);
37+
var records = Arrays.asList(new Actor("Tom Cruise"), new Actor("Scarlett Johansson"));
38+
var batch = records.stream().map(entry -> new BatchRequest().setAction(Action.ADD_OBJECT).setBody(entry)).toList();
39+
var response = client.batch(indexName, new BatchWriteParams().setRequests(batch));
40+
client.waitForTask(indexName, response.getTaskID());
4641

47-
var browse = client.browseObjects(indexName, new BrowseParamsObject().setQuery("tom"), Actor.class);
48-
System.out.println("-> Browse Objects:");
49-
for (var hit : browse) {
50-
System.out.println("> " + hit.name);
51-
}
52-
53-
singleSearch(client, indexName, query);
54-
multiSearch(indexName, query, client);
55-
client.close();
42+
var browse = client.browseObjects(indexName, new BrowseParamsObject().setQuery("tom"), Actor.class);
43+
System.out.println("-> Browse Objects:");
44+
for (var hit : browse) {
45+
System.out.println("> " + hit.name);
5646
}
5747

58-
private static void singleSearch(SearchClient client, String indexName, String query) {
59-
SearchParamsObject params = new SearchParamsObject()
60-
.setQuery(query)
61-
.setAroundPrecision(AroundPrecision.of(1000))
62-
.setAroundRadius(AroundRadiusAll.ALL);
63-
SearchResponse<Actor> actorSearchResponse = client.searchSingleIndex(indexName, params, Actor.class);
64-
System.out.println("-> Single Index Search:");
65-
for (var hit : actorSearchResponse.getHits()) {
66-
System.out.println("> " + hit.name);
67-
}
48+
singleSearch(client, indexName, query);
49+
multiSearch(indexName, query, client);
50+
client.close();
51+
}
52+
53+
private static void singleSearch(SearchClient client, String indexName, String query) {
54+
SearchParamsObject params = new SearchParamsObject()
55+
.setQuery(query)
56+
.setAroundPrecision(AroundPrecision.of(1000))
57+
.setAroundRadius(AroundRadiusAll.ALL);
58+
SearchResponse<Actor> actorSearchResponse = client.searchSingleIndex(indexName, params, Actor.class);
59+
System.out.println("-> Single Index Search:");
60+
for (var hit : actorSearchResponse.getHits()) {
61+
System.out.println("> " + hit.name);
6862
}
63+
}
6964

70-
private static void multiSearch(String indexName, String query, SearchClient client) {
71-
var searchMethodParams = new SearchMethodParams();
72-
var searchQuery = new SearchForHits()
73-
.setIndexName(indexName)
74-
.setQuery(query)
75-
.addAttributesToSnippet("title")
76-
.addAttributesToSnippet("alternative_titles");
77-
List<SearchQuery> requests = List.of(searchQuery);
78-
searchMethodParams.setRequests(requests);
65+
private static void multiSearch(String indexName, String query, SearchClient client) {
66+
var searchMethodParams = new SearchMethodParams();
67+
var searchQuery = new SearchForHits()
68+
.setIndexName(indexName)
69+
.setQuery(query)
70+
.addAttributesToSnippet("title")
71+
.addAttributesToSnippet("alternative_titles");
72+
List<SearchQuery> requests = List.of(searchQuery);
73+
searchMethodParams.setRequests(requests);
7974

80-
var responses = client.search(searchMethodParams, Actor.class);
81-
var results = responses.getResults();
82-
System.out.println("-> Multi Index Search:");
83-
for (var result : results) {
84-
var response = (SearchResponse) result;
85-
for (var hit : response.getHits()) {
86-
var record = (Map) hit;
87-
System.out.println("> " + record.get("name"));
88-
}
89-
}
75+
var responses = client.search(searchMethodParams, Actor.class);
76+
var results = responses.getResults();
77+
System.out.println("-> Multi Index Search:");
78+
for (var result : results) {
79+
var response = (SearchResponse) result;
80+
for (var hit : response.getHits()) {
81+
var record = (Map) hit;
82+
System.out.println("> " + record.get("name"));
83+
}
9084
}
85+
}
9186
}

specs/common/schemas/IndexSettings.yml

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ baseIndexSettings:
283283
This applies faceting _after_ deduplication, which will result in accurate facet counts.
284284
example: url
285285
type: string
286+
maxFacetHits:
287+
$ref: '#/maxFacetHits'
286288

287289
indexSettingsAsSearchParams:
288290
type: object
@@ -570,33 +572,7 @@ indexSettingsAsSearchParams:
570572
x-categories:
571573
- Query strategy
572574
optionalWords:
573-
type: array
574-
items:
575-
type: string
576-
example:
577-
- blue
578-
- iphone case
579-
description: |
580-
Words that should be considered optional when found in the query.
581-
582-
By default, records must match all words in the search query to be included in the search results.
583-
Adding optional words can help to increase the number of search results by running an additional search query that doesn't include the optional words.
584-
For example, if the search query is "action video" and "video" is an optional word,
585-
the search engine runs two queries. One for "action video" and one for "action".
586-
Records that match all words are ranked higher.
587-
588-
For a search query with 4 or more words **and** all its words are optional,
589-
the number of matched words required for a record to be included in the search results increases for every 1,000 records:
590-
591-
- If `optionalWords` has less than 10 words, the required number of matched words increases by 1:
592-
results 1 to 1,000 require 1 matched word, results 1,001 to 2000 need 2 matched words.
593-
- If `optionalWords` has 10 or more words, the number of required matched words increases by the number of optional words divided by 5 (rounded down).
594-
For example, with 18 optional words: results 1 to 1,000 require 1 matched word, results 1,001 to 2000 need 4 matched words.
595-
596-
For more information, see [Optional words](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/empty-or-insufficient-results/#creating-a-list-of-optional-words).
597-
default: []
598-
x-categories:
599-
- Query strategy
575+
$ref: '#/optionalWords'
600576
disableExactOnAttributes:
601577
type: array
602578
items:
@@ -708,8 +684,6 @@ indexSettingsAsSearchParams:
708684
default: ['*']
709685
x-categories:
710686
- Advanced
711-
maxFacetHits:
712-
$ref: '#/maxFacetHits'
713687
maxValuesPerFacet:
714688
type: integer
715689
description: Maximum number of facet values to return for each facet.
@@ -1238,3 +1212,38 @@ booleanString:
12381212
enum:
12391213
- 'true'
12401214
- 'false'
1215+
1216+
optionalWords:
1217+
oneOf:
1218+
- type: string
1219+
- type: 'null'
1220+
- $ref: '#/optionalWordsArray'
1221+
1222+
optionalWordsArray:
1223+
type: array
1224+
items:
1225+
type: string
1226+
example:
1227+
- blue
1228+
- iphone case
1229+
description: |
1230+
Words that should be considered optional when found in the query.
1231+
1232+
By default, records must match all words in the search query to be included in the search results.
1233+
Adding optional words can help to increase the number of search results by running an additional search query that doesn't include the optional words.
1234+
For example, if the search query is "action video" and "video" is an optional word,
1235+
the search engine runs two queries. One for "action video" and one for "action".
1236+
Records that match all words are ranked higher.
1237+
1238+
For a search query with 4 or more words **and** all its words are optional,
1239+
the number of matched words required for a record to be included in the search results increases for every 1,000 records:
1240+
1241+
- If `optionalWords` has less than 10 words, the required number of matched words increases by 1:
1242+
results 1 to 1,000 require 1 matched word, results 1,001 to 2000 need 2 matched words.
1243+
- If `optionalWords` has 10 or more words, the number of required matched words increases by the number of optional words divided by 5 (rounded down).
1244+
For example, with 18 optional words: results 1 to 1,000 require 1 matched word, results 1,001 to 2000 need 4 matched words.
1245+
1246+
For more information, see [Optional words](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/empty-or-insufficient-results/#creating-a-list-of-optional-words).
1247+
default: []
1248+
x-categories:
1249+
- Query strategy

specs/common/schemas/SearchParams.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,12 @@ aroundLatLngViaIP:
337337
- Geo-Search
338338

339339
insideBoundingBox:
340+
oneOf:
341+
- type: string
342+
- type: 'null'
343+
- $ref: '#/insideBoundingBoxArray'
344+
345+
insideBoundingBoxArray:
340346
type: array
341347
items:
342348
type: array

0 commit comments

Comments
 (0)