From 7dc719cbe439f50a7c13fd16f588720b12d79aa8 Mon Sep 17 00:00:00 2001 From: Kai Welke Date: Mon, 18 Mar 2024 11:18:30 +0100 Subject: [PATCH] fix(specs): make languages an enum (#2865) --- specs/common/schemas/IndexSettings.yml | 100 +++++++++++++++--- .../paths/dictionaries/common/parameters.yml | 6 -- .../SearchDictionaryEntriesResponse.yml | 4 +- .../dictionaries/searchDictionaryEntries.yml | 2 +- templates/kotlin/oneof_interface.mustache | 2 +- templates/swift/tests/paramValue.mustache | 2 +- tests/CTS/requests/search/search.json | 4 +- tests/CTS/requests/search/setSettings.json | 16 +-- 8 files changed, 100 insertions(+), 36 deletions(-) diff --git a/specs/common/schemas/IndexSettings.yml b/specs/common/schemas/IndexSettings.yml index 4e50012d03..ba6356809a 100644 --- a/specs/common/schemas/IndexSettings.yml +++ b/specs/common/schemas/IndexSettings.yml @@ -132,7 +132,7 @@ baseIndexSettings: type: array items: type: string - example: ['description'] + example: [description] description: Attributes for which to split [camel case](https://wikipedia.org/wiki/Camel_case) words. default: [] x-categories: @@ -158,11 +158,11 @@ baseIndexSettings: indexLanguages: type: array items: - type: string + $ref: '#/supportedLanguage' example: - ja description: | - [ISO code](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) for a language for language-specific processing steps, such as word detection and dictionary settings. + Languages for language-specific processing steps, such as word detection and dictionary settings. **You should always specify an indexing language.** If you don't specify an indexing language, the search engine uses all [supported languages](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/supported-languages/), @@ -519,17 +519,16 @@ indexSettingsAsSearchParams: queryLanguages: type: array items: - type: string + $ref: '#/supportedLanguage' example: - es description: | - [ISO code](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) for language-specific settings such as plurals, stop words, and word-detection dictionaries. + Languages for language-specific query processing steps such as plurals, stop-word removal, and word-detection dictionaries. This setting sets a default list of languages used by the `removeStopWords` and `ignorePlurals` settings. This setting also sets a dictionary for word detection in the logogram-based [CJK](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/normalization/#normalization-for-logogram-based-languages-cjk) languages. To support this, you must place the CJK language **first**. - **You should always specify a query language.** If you don't specify an indexing language, the search engine uses all [supported languages](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/supported-languages/), or the languages you specified with the `ignorePlurals` or `removeStopWords` parameters. @@ -979,14 +978,14 @@ ignorePlurals: description: | Treat singular, plurals, and other forms of declensions as equivalent. You should only use this feature for the languages used in your index. - example: ['ca', 'es'] + example: [ca, es] oneOf: - type: array + description: | + ISO code for languages for which this feature should be active. + This overrides languages you set with `queryLanguages`. items: - type: string - description: | - ISO code for languages for which this feature should be active. - This overrides languages you set with `queryLanguages`. + $ref: '#/supportedLanguage' - type: boolean description: | If true, `ignorePlurals` is active for all languages included in `queryLanguages`, or for all supported languages, if `queryLanguges` is empty. @@ -1003,12 +1002,12 @@ removeStopWords: In English, "the", "a", or "and" are stop words. You should only use this feature for the languages used in your index. - example: ['ca', 'es'] + example: [ca, es] oneOf: - type: array + description: ISO code for languages for which stop words should be removed. This overrides languages you set in `queryLanguges`. items: - type: string - description: ISO code for languages for which stop words should be removed. This overrides languages you set in `queryLanguges`. + $ref: '#/supportedLanguage' - type: boolean default: false description: | @@ -1107,3 +1106,76 @@ semanticSearch: type: array items: type: string + +supportedLanguage: + type: string + description: ISO code for a supported language. + enum: + - af + - ar + - az + - bg + - bn + - ca + - cs + - cy + - da + - de + - el + - en + - eo + - es + - et + - eu + - fa + - fi + - fo + - fr + - ga + - gl + - he + - hi + - hu + - hy + - id + - is + - it + - ja + - ka + - kk + - ko + - ku + - ky + - lt + - lv + - mi + - mn + - mr + - ms + - mt + - nb + - nl + - no + - ns + - pl + - ps + - pt + - 'pt-br' + - qu + - ro + - ru + - sk + - sq + - sv + - sw + - ta + - te + - th + - tl + - tn + - tr + - tt + - uk + - ur + - uz + - zh diff --git a/specs/search/paths/dictionaries/common/parameters.yml b/specs/search/paths/dictionaries/common/parameters.yml index 5d55dafe1b..1f3671754d 100644 --- a/specs/search/paths/dictionaries/common/parameters.yml +++ b/specs/search/paths/dictionaries/common/parameters.yml @@ -11,12 +11,6 @@ dictionaryType: type: string enum: [plurals, stopwords, compounds] -# misc -language: - description: ISO code of a [supported language](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/supported-languages/). - example: en - type: string - standardEntries: description: | Key-value pairs of [supported language ISO codes](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/supported-languages/) and boolean values. diff --git a/specs/search/paths/dictionaries/common/schemas/SearchDictionaryEntriesResponse.yml b/specs/search/paths/dictionaries/common/schemas/SearchDictionaryEntriesResponse.yml index bb6992211a..1598517bbd 100644 --- a/specs/search/paths/dictionaries/common/schemas/SearchDictionaryEntriesResponse.yml +++ b/specs/search/paths/dictionaries/common/schemas/SearchDictionaryEntriesResponse.yml @@ -32,9 +32,7 @@ dictionaryEntry: description: Unique identifier for the dictionary entry. example: 828afd405e1f4fe950b6b98c2c43c032 language: - type: string - description: ISO code of a [supported language](https://www.algolia.com/doc/guides/managing-results/optimize-search-results/handling-natural-languages-nlp/in-depth/supported-languages/). - example: de + $ref: '../../../../../common/schemas/IndexSettings.yml#/supportedLanguage' word: type: string description: Matching dictionary word for `stopwords` and `compounds` dictionaries. diff --git a/specs/search/paths/dictionaries/searchDictionaryEntries.yml b/specs/search/paths/dictionaries/searchDictionaryEntries.yml index dde3123b98..97cce380db 100644 --- a/specs/search/paths/dictionaries/searchDictionaryEntries.yml +++ b/specs/search/paths/dictionaries/searchDictionaryEntries.yml @@ -29,7 +29,7 @@ post: hitsPerPage: $ref: '../../../common/schemas/IndexSettings.yml#/hitsPerPage' language: - $ref: 'common/parameters.yml#/language' + $ref: '../../../common/schemas/IndexSettings.yml#/supportedLanguage' responses: '200': description: OK diff --git a/templates/kotlin/oneof_interface.mustache b/templates/kotlin/oneof_interface.mustache index ab92196357..e45def7419 100644 --- a/templates/kotlin/oneof_interface.mustache +++ b/templates/kotlin/oneof_interface.mustache @@ -73,7 +73,7 @@ internal class {{classname}}Serializer : JsonContentPolymorphicSerializer<{{clas element is JsonObject -> {{classname}}.{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}Value.serializer() {{/isMap}} {{#isArray}} - element{{#items}}{{#isModel}}.isJsonArrayOfObjects{{/isModel}}{{#isPrimitiveType}}.isJsonArrayOfPrimitives{{/isPrimitiveType}}{{#isModel}}{{#isPrimitiveType}} is JsonArray{{/isPrimitiveType}}{{/isModel}}{{/items}} -> {{{classname}}}.{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}Value.serializer() + element{{#items}}{{#isModel}}.isJsonArrayOfObjects{{/isModel}}{{#isPrimitiveType}}.isJsonArrayOfPrimitives{{/isPrimitiveType}}{{^isModel}}{{^isPrimitiveType}} is JsonArray{{/isPrimitiveType}}{{/isModel}}{{/items}} -> {{{classname}}}.{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}Value.serializer() {{/isArray}} {{#isEnumRef}} element.isString -> {{{datatypeWithEnum}}}.serializer() diff --git a/templates/swift/tests/paramValue.mustache b/templates/swift/tests/paramValue.mustache index c2d28c541c..be7f67cdcb 100644 --- a/templates/swift/tests/paramValue.mustache +++ b/templates/swift/tests/paramValue.mustache @@ -1 +1 @@ -{{#isObject}}{{objectName}}({{^hasAdditionalProperties}}{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}{{/hasAdditionalProperties}}{{#hasAdditionalProperties}}from: [{{#value}}"{{key}}": {{> tests/paramValue }}{{^-last}}, {{/-last}}{{/value}}]{{/hasAdditionalProperties}}){{/isObject}}{{#isString}}{{#isAnyType}}AnyCodable({{/isAnyType}}"{{{value}}}"{{#isAnyType}}){{/isAnyType}}{{/isString}}{{#isNumber}}{{#isLong}}Int64({{/isLong}}{{{value}}}{{#isLong}}){{/isLong}}{{/isNumber}}{{#isBoolean}}{{{value}}}{{/isBoolean}}{{#isEnum}}{{objectName}}.{{#lambda.swiftIdentifier}}{{#lambda.camelcase}}{{valueEscaped}}{{/lambda.camelcase}}{{/lambda.swiftIdentifier}}{{/isEnum}}{{#isArray}}[{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isArray}}{{#isMap}}Map[{{{.}}}]{{/isMap}}{{#isFreeFormObject}}{{#isAnyType}}[{{#value}}{{#entrySet}}"{{key}}": "{{{value}}}"{{/entrySet}}{{/value}}]{{/isAnyType}}{{^isAnyType}}[{{^value}}:{{/value}}{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isAnyType}}{{/isFreeFormObject}}{{#isNull}}{{#inClientTest}}TestNull{{{objectName}}}(){{/inClientTest}}{{/isNull}} +{{#isObject}}{{objectName}}({{^hasAdditionalProperties}}{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}{{/hasAdditionalProperties}}{{#hasAdditionalProperties}}from: [{{#value}}"{{key}}": AnyCodable({{> tests/paramValue }}){{^-last}}, {{/-last}}{{/value}}]{{/hasAdditionalProperties}}){{/isObject}}{{#isString}}{{#isAnyType}}AnyCodable({{/isAnyType}}"{{{value}}}"{{#isAnyType}}){{/isAnyType}}{{/isString}}{{#isNumber}}{{#isLong}}Int64({{/isLong}}{{{value}}}{{#isLong}}){{/isLong}}{{/isNumber}}{{#isBoolean}}{{{value}}}{{/isBoolean}}{{#isEnum}}{{objectName}}.{{#lambda.swiftIdentifier}}{{#lambda.camelcase}}{{valueEscaped}}{{/lambda.camelcase}}{{/lambda.swiftIdentifier}}{{/isEnum}}{{#isArray}}[{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isArray}}{{#isMap}}Map[{{{.}}}]{{/isMap}}{{#isFreeFormObject}}{{#isAnyType}}[{{#value}}{{#entrySet}}"{{key}}": "{{{value}}}"{{/entrySet}}{{/value}}]{{/isAnyType}}{{^isAnyType}}[{{^value}}:{{/value}}{{#value}}{{> tests/generateParams}}{{^-last}}, {{/-last}}{{/value}}]{{/isAnyType}}{{/isFreeFormObject}}{{#isNull}}{{#inClientTest}}TestNull{{{objectName}}}(){{/inClientTest}}{{/isNull}} \ No newline at end of file diff --git a/tests/CTS/requests/search/search.json b/tests/CTS/requests/search/search.json index f15f4e143d..1cd86bf182 100644 --- a/tests/CTS/requests/search/search.json +++ b/tests/CTS/requests/search/search.json @@ -460,7 +460,7 @@ "personalizationImpact": 0, "query": "", "queryLanguages": [ - "" + "fr" ], "queryType": "prefixAll", "ranking": [ @@ -635,7 +635,7 @@ "personalizationImpact": 0, "query": "", "queryLanguages": [ - "" + "fr" ], "queryType": "prefixAll", "ranking": [ diff --git a/tests/CTS/requests/search/setSettings.json b/tests/CTS/requests/search/setSettings.json index 73d6e37b45..b8c519cc59 100644 --- a/tests/CTS/requests/search/setSettings.json +++ b/tests/CTS/requests/search/setSettings.json @@ -88,7 +88,7 @@ "indexName": "theIndexName", "indexSettings": { "ignorePlurals": [ - "algolia" + "fr" ] }, "forwardToReplicas": true @@ -98,7 +98,7 @@ "method": "PUT", "body": { "ignorePlurals": [ - "algolia" + "fr" ] }, "queryParameters": { @@ -132,7 +132,7 @@ "indexName": "theIndexName", "indexSettings": { "removeStopWords": [ - "algolia" + "fr" ] }, "forwardToReplicas": true @@ -142,7 +142,7 @@ "method": "PUT", "body": { "removeStopWords": [ - "algolia" + "fr" ] }, "queryParameters": { @@ -258,7 +258,7 @@ "hitsPerPage": 10, "ignorePlurals": false, "indexLanguages": [ - "algolia" + "fr" ], "keepDiacriticsOnCharacters": "abc", "maxFacetHits": 20, @@ -275,7 +275,7 @@ ], "paginationLimitedTo": 0, "queryLanguages": [ - "algolia" + "fr" ], "queryType": "prefixLast", "ranking": [ @@ -398,7 +398,7 @@ "hitsPerPage": 10, "ignorePlurals": false, "indexLanguages": [ - "algolia" + "fr" ], "keepDiacriticsOnCharacters": "abc", "maxFacetHits": 20, @@ -415,7 +415,7 @@ ], "paginationLimitedTo": 0, "queryLanguages": [ - "algolia" + "fr" ], "queryType": "prefixLast", "ranking": [