Skip to content

Commit 1ae6302

Browse files
authored
Merge pull request #141 from algolia/feature/custom-normalization
Add custom normalization parameter in Settings
2 parents b2d1ac0 + b62f377 commit 1ae6302

File tree

6 files changed

+55
-3
lines changed

6 files changed

+55
-3
lines changed

src/commonMain/kotlin/com/algolia/search/model/settings/Settings.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,11 @@ public data class Settings(
363363
* Accepted value: [Language.Japanese]
364364
* Input data to index is treated as the given language(s) for segmentation.
365365
*/
366-
@SerialName(KeyIndexLanguages) var indexLanguages: List<Language>? = null
366+
@SerialName(KeyIndexLanguages) var indexLanguages: List<Language>? = null,
367+
/**
368+
* Override the custom normalization handled by the engine.
369+
*/
370+
@SerialName(KeyCustomNormalization) var customNormalization: Map<String, Map<String, String>>? = null
367371
) {
368372

369373
/**

src/commonMain/kotlin/com/algolia/search/serialize/Keys.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,5 +364,6 @@ public const val KeySimilarQuery = "similarQuery"
364364
public const val KeyEnableABTest = "enableABTest"
365365
public const val KeyAlternatives = "alternatives"
366366
public const val KeyIndexLanguages = "indexLanguages"
367+
public const val KeyCustomNormalization = "customNormalization"
367368
public const val KeyFilterPromotes = "filterPromotes"
368369
public const val KeyUsers = "users"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package documentation.parameters.advanced
2+
3+
import com.algolia.search.dsl.query
4+
import com.algolia.search.dsl.settings
5+
import documentation.index
6+
import runBlocking
7+
import kotlin.test.Ignore
8+
import kotlin.test.Test
9+
10+
11+
@Ignore
12+
class DocCustomNormalization {
13+
14+
// customNormalization: Map<String, Map<String, String>> = mapOf(
15+
// "default" to mapOf(
16+
// "ä" to "ae",
17+
// "ü" to "ue"
18+
// )
19+
// )
20+
21+
@Test
22+
fun snippet1() {
23+
runBlocking {
24+
val settings = settings {
25+
customNormalization = mapOf(
26+
"default" to mapOf(
27+
"ä" to "ae",
28+
"ü" to "ue"
29+
)
30+
)
31+
}
32+
33+
index.setSettings(settings)
34+
}
35+
}
36+
}

src/commonTest/kotlin/serialize/TestKeys.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ internal class TestKeys {
355355
KeyEnableABTest shouldEqual "enableABTest"
356356
KeyAlternatives shouldEqual "alternatives"
357357
KeyIndexLanguages shouldEqual "indexLanguages"
358+
KeyCustomNormalization shouldEqual "customNormalization"
358359
KeyFilterPromotes shouldEqual "filterPromotes"
359360
KeyUsers shouldEqual "users"
360361
}

src/commonTest/kotlin/serialize/settings/TestSettings.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ internal class TestSettings : TestSerializer<Settings>(Settings.serializer()) {
8585
version = int,
8686
advancedSyntaxFeatures = listOf(AdvancedSyntaxFeatures.ExcludeWords, AdvancedSyntaxFeatures.ExactPhrase),
8787
userData = json { unknown to unknown },
88-
indexLanguages = listOf(Language.Japanese)
88+
indexLanguages = listOf(Language.Japanese),
89+
customNormalization = mapOf(unknown to mapOf(unknown to unknown))
8990
) to json {
9091
// Attributes
9192
KeySearchableAttributes to attributesJson
@@ -156,6 +157,9 @@ internal class TestSettings : TestSerializer<Settings>(Settings.serializer()) {
156157
KeyUserData to json { unknown to unknown }
157158
KeyPrimary to JsonNull
158159
KeyIndexLanguages to jsonArray { +Language.Japanese.raw }
160+
KeyCustomNormalization to json {
161+
unknown to json { unknown to unknown }
162+
}
159163
}
160164
)
161165

src/commonTest/resources/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,11 @@
116116
"version": 1,
117117
"indexLanguages": [
118118
"ja"
119-
]
119+
],
120+
"customNormalization": {
121+
"default": {
122+
"ä": "ae",
123+
"ü": "ue"
124+
}
125+
}
120126
}

0 commit comments

Comments
 (0)