Skip to content

Commit

Permalink
fix(specs): highlight result map definition (#2312)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Dec 4, 2023
1 parent 1ee6846 commit 205519c
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 94 deletions.
2 changes: 1 addition & 1 deletion .github/.cache_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.103
0.0.104
2 changes: 1 addition & 1 deletion config/clients.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"folder": "clients/algoliasearch-client-scala",
"gitRepoId": "algoliasearch-client-scala",
"packageVersion": "2.0.0-alpha.1",
"modelFolder": "src/main/scala/algoliasearch/model",
"modelFolder": "src/main/scala/algoliasearch",
"apiFolder": "src/main/scala/algoliasearch/api",
"customGenerator": "algolia-scala",
"tests": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ public String toEnumVarName(String value, String datatype) {

/** Convert a Seq type to a valid class name. */
private String typeToName(String content) {
return content.trim().replace("<", "Of").replace(">", "");
return content.trim().replace("<", "Of").replace(">", "").replace(",", "").replace(" ", "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void processOpts() {

/** Convert a Seq type to a valid class name. */
private String typeToName(String content) {
return content.trim().replace("<", "Of").replace(">", "");
return content.trim().replace("<", "Of").replace(">", "").replace(", ", "").replace(".", "");
}

private void hostForKotlin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void processOpts() {

/** Convert a Seq type to a valid class name. */
private String typeToName(String content) {
return content.trim().replace("[", "Of").replace("]", "");
return content.trim().replace("[", "Of").replace("]", "").replace(".", "").replace(", ", "");
}

@Override
Expand Down
53 changes: 53 additions & 0 deletions specs/common/schemas/HighlightResult.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
highlightResultOption:
type: object
description: Show highlighted section and words matched on a query.
additionalProperties: false
x-discriminator-fields:
- matchLevel
- value
- matchedWords
properties:
value:
$ref: '#/highlightedValue'
matchLevel:
$ref: '#/matchLevel'
matchedWords:
type: array
description: List of words from the query that matched the object.
example: ['action']
items:
type: string
fullyHighlighted:
type: boolean
description: Whether the entire attribute value is highlighted.
required:
- value
- matchLevel
- matchedWords

highlightedValue:
type: string
description: Markup text with `facetQuery` matches highlighted.
example: '<em>George</em> <em>Clo</em>oney'

matchLevel:
type: string
description: Indicates how well the attribute matched the search query.
enum: [none, partial, full]

highlightResultOptionMap:
type: object
description: Show highlighted section and words matched on a query.
additionalProperties:
$ref: '#/highlightResultOption'

highlightResult:
oneOf:
- $ref: '#/highlightResultOption'
- $ref: '#/highlightResultOptionMap'

highlightResultMap:
type: object
description: Show highlighted section and words matched on a query.
additionalProperties:
$ref: '#/highlightResult'
29 changes: 29 additions & 0 deletions specs/common/schemas/SnippetResult.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
snippetResultOption:
type: object
description: Snippeted attributes show parts of the matched attributes. Only returned when attributesToSnippet is non-empty.
additionalProperties: false
properties:
value:
$ref: './HighlightResult.yml#/highlightedValue'
matchLevel:
$ref: './HighlightResult.yml#/matchLevel'
required:
- value
- matchLevel

snippetResultOptionMap:
type: object
description: Snippeted attributes show parts of the matched attributes. Only returned when attributesToSnippet is non-empty.
additionalProperties:
$ref: '#/snippetResultOption'

snippetResult:
oneOf:
- $ref: '#/snippetResultOption'
- $ref: '#/snippetResultOptionMap'

snippetResultMap:
type: object
description: Snippeted attributes show parts of the matched attributes. Only returned when attributesToSnippet is non-empty.
additionalProperties:
$ref: '#/snippetResult'
4 changes: 2 additions & 2 deletions specs/recommend/common/schemas/RecommendationsResponse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ recommendHit:
objectID:
$ref: '../../../common/parameters.yml#/objectID'
_highlightResult:
$ref: '../../../search/common/schemas/Hit.yml#/highlightResultMap'
$ref: '../../../common/schemas/HighlightResult.yml#/highlightResultMap'
_snippetResult:
$ref: '../../../search/common/schemas/Hit.yml#/snippetResultMap'
$ref: '../../../common/schemas/SnippetResult.yml#/snippetResultMap'
_rankingInfo:
$ref: '../../../search/common/schemas/Hit.yml#/rankingInfo'
_distinctSeqID:
Expand Down
76 changes: 2 additions & 74 deletions specs/search/common/schemas/Hit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ hit:
objectID:
$ref: '../../../common/parameters.yml#/objectID'
_highlightResult:
$ref: '#/highlightResultMap'
$ref: '../../../common/schemas/HighlightResult.yml#/highlightResultMap'
_snippetResult:
$ref: '#/snippetResultMap'
$ref: '../../../common/schemas/SnippetResult.yml#/snippetResultMap'
_rankingInfo:
$ref: '#/rankingInfo'
_distinctSeqID:
Expand All @@ -21,68 +21,6 @@ hit:
_distinctSeqID:
type: integer

highlightResultOption:
type: object
description: Show highlighted section and words matched on a query.
additionalProperties: false
properties:
value:
$ref: '#/highlightedValue'
matchLevel:
$ref: '#/matchLevel'
matchedWords:
type: array
description: List of words from the query that matched the object.
example: ['action']
items:
type: string
fullyHighlighted:
type: boolean
description: Whether the entire attribute value is highlighted.
required:
- value
- matchLevel
- matchedWords

highlightResult:
oneOf:
- $ref: '#/highlightResultOption'
- type: array
items:
$ref: '#/highlightResultOption'

highlightResultMap:
type: object
description: Show highlighted section and words matched on a query.
additionalProperties:
$ref: '#/highlightResult'

snippetResultOption:
type: object
description: Snippeted attributes show parts of the matched attributes. Only returned when attributesToSnippet is non-empty.
additionalProperties: false
properties:
value:
$ref: '#/highlightedValue'
matchLevel:
$ref: '#/matchLevel'
required:
- value
- matchLevel

snippetResult:
oneOf:
- $ref: '#/snippetResultOption'
- type: array
items:
$ref: '#/snippetResultOption'

snippetResultMap:
type: object
description: Snippeted attributes show parts of the matched attributes. Only returned when attributesToSnippet is non-empty.
additionalProperties:
$ref: '#/snippetResult'

rankingInfo:
type: object
additionalProperties: false
Expand Down Expand Up @@ -134,16 +72,6 @@ rankingInfo:
- filters
- userScore

highlightedValue:
type: string
description: Markup text with `facetQuery` matches highlighted.
example: '<em>George</em> <em>Clo</em>oney'

matchLevel:
type: string
description: Indicates how well the attribute matched the search query.
enum: [none, partial, full]

matchedGeoLocation:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ searchForFacetValuesResponse:
example: 'Mobile phone'
type: string
highlighted:
$ref: '../../common/schemas/Hit.yml#/highlightedValue'
$ref: '../../../common/schemas/HighlightResult.yml#/highlightedValue'
count:
description: Number of records containing this facet value. This takes into account the extra search parameters specified in the query. Like for a regular search query, the [counts may not be exhaustive](https://support.algolia.com/hc/en-us/articles/4406975248145-Why-are-my-facet-and-hit-counts-not-accurate-).
type: integer
4 changes: 2 additions & 2 deletions specs/search/paths/multiclusters/searchUserIds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ post:
type: object
properties:
userID:
$ref: '../../common/schemas/Hit.yml#/highlightResultMap'
$ref: '../../../common/schemas/HighlightResult.yml#/highlightResult'
clusterName:
$ref: '../../common/schemas/Hit.yml#/highlightResultMap'
$ref: '../../../common/schemas/HighlightResult.yml#/highlightResult'
required:
- userID
- clusterName
Expand Down
14 changes: 9 additions & 5 deletions templates/java/oneof_interface.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.algolia.utils.CompoundType;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -82,7 +83,7 @@ public interface {{classname}} {
JsonNode tree = jp.readValueAsTree();
{{#composedSchemas.oneOf}}
// deserialize {{{datatypeWithEnum}}}
if (tree.{{#isModel}}isObject(){{#vendorExtensions.x-discriminator-fields}} && tree.has("{{{.}}}"){{/vendorExtensions.x-discriminator-fields}}{{/isModel}}{{#isEnumRef}}isTextual(){{/isEnumRef}}{{#isArray}}isArray(){{/isArray}}{{#isInteger}}isInt(){{/isInteger}}{{#isLong}}isLong(){{/isLong}}{{#isDouble}}isDouble(){{/isDouble}}{{#isBoolean}}isBoolean(){{/isBoolean}}{{#isString}}isTextual(){{/isString}}){
if (tree.{{#isMap}}isObject(){{/isMap}}{{#isModel}}isObject(){{#vendorExtensions.x-discriminator-fields}} && tree.has("{{{.}}}"){{/vendorExtensions.x-discriminator-fields}}{{/isModel}}{{#isEnumRef}}isTextual(){{/isEnumRef}}{{#isArray}}isArray(){{/isArray}}{{#isInteger}}isInt(){{/isInteger}}{{#isLong}}isLong(){{/isLong}}{{#isDouble}}isDouble(){{/isDouble}}{{#isBoolean}}isBoolean(){{/isBoolean}}{{#isString}}isTextual(){{/isString}}){
try(JsonParser parser = tree.traverse(jp.getCodec())) {
{{#isModel}}
return parser.readValueAs({{{datatypeWithEnum}}}.class);
Expand All @@ -94,10 +95,14 @@ public interface {{classname}} {
{{{datatypeWithEnum}}} value = parser.readValueAs(new TypeReference<{{{datatypeWithEnum}}}>(){});
return new {{classname}}.{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}Wrapper(value);
{{/isArray}}
{{^isModel}}{{^isEnumRef}}{{^isArray}}
{{^isModel}}{{^isEnumRef}}{{^isArray}}{{^isMap}}
{{{datatypeWithEnum}}} value = parser.readValueAs({{{datatypeWithEnum}}}.class);
return new {{classname}}.{{{datatypeWithEnum}}}Wrapper(value);
{{/isArray}}{{/isEnumRef}}{{/isModel}}
{{/isMap}}{{/isArray}}{{/isEnumRef}}{{/isModel}}
{{#isMap}}
{{{datatypeWithEnum}}} value = parser.readValueAs(new TypeReference<{{{datatypeWithEnum}}}>(){});
return new {{classname}}.{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}Wrapper(value);
{{/isMap}}
} catch (Exception e) {
// deserialization failed, continue
LOGGER.finest("Failed to deserialize oneOf {{{datatypeWithEnum}}} (error: " + e.getMessage() + ") (type: {{{datatypeWithEnum}}})");
Expand All @@ -120,5 +125,4 @@ public interface {{classname}} {
{{/isNullable}}
}
}
}

}
5 changes: 4 additions & 1 deletion templates/kotlin/oneof_interface.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ internal class {{classname}}Serializer : JsonContentPolymorphicSerializer<{{clas
{{#isModel}}
element is JsonObject{{#vendorExtensions.x-discriminator-fields}} && element.containsKey("{{{.}}}"){{/vendorExtensions.x-discriminator-fields}} -> {{{datatypeWithEnum}}}.serializer()
{{/isModel}}
{{#isMap}}
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()
{{/isArray}}
Expand All @@ -94,4 +97,4 @@ internal class {{classname}}Serializer : JsonContentPolymorphicSerializer<{{clas
else -> throw AlgoliaClientException("Failed to deserialize json element: $element")
}
}
}
}
11 changes: 7 additions & 4 deletions templates/scala/oneof_trait.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object {{classname}} {
{{#composedSchemas.oneOf}}
{{^isModel}}
{{^isEnumRef}}
case class {{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}(value: {{{datatypeWithEnum}}}) extends {{classname}}
case class {{#isMap}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isMap}}{{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isMap}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}{{/isMap}}(value: {{{datatypeWithEnum}}}) extends {{classname}}
{{/isEnumRef}}
{{/isModel}}
{{/composedSchemas.oneOf}}
Expand All @@ -38,7 +38,7 @@ object {{classname}} {
{{^isModel}}
{{^isEnumRef}}
def apply(value: {{{datatypeWithEnum}}}){{#isArray}}(implicit ev: {{classname}}Evidence.{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}Evidence.type){{/isArray}}: {{classname}} = {
{{classname}}.{{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}(value)
{{classname}}.{{#isMap}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isMap}}{{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isMap}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}{{/isMap}}(value)
}
{{/isEnumRef}}
{{/isModel}}
Expand All @@ -50,7 +50,7 @@ object {{classname}} {
{{^isModel}}
{{^isEnumRef}}
def apply(value: {{{datatypeWithEnum}}}): {{classname}} = {
{{classname}}.{{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}(value)
{{classname}}.{{#isMap}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isMap}}{{#isArray}}{{#lambda.type-to-name}}{{{datatypeWithEnum}}}{{/lambda.type-to-name}}{{/isArray}}{{^isMap}}{{^isArray}}{{{datatypeWithEnum}}}Value{{/isArray}}{{/isMap}}(value)
}
{{/isEnumRef}}
{{/isModel}}
Expand All @@ -67,6 +67,9 @@ object {{classname}}Serializer extends Serializer[{{classname}}] {
{{#isModel}}
case value: JObject {{#vendorExtensions.x-discriminator-fields}}{{#-first}}if{{/-first}}{{^-first}}&&{{/-first}} value.obj.contains("{{{.}}}"){{/vendorExtensions.x-discriminator-fields}} => Extraction.extract[{{{datatypeWithEnum}}}](value)
{{/isModel}}
{{#isMap}}
case value: JObject => {{classname}}.apply(Extraction.extract[{{{datatypeWithEnum}}}](value))
{{/isMap}}
{{#isEnumRef}}
case value: JString => Extraction.extract[{{{datatypeWithEnum}}}](value)
{{/isEnumRef}}
Expand Down Expand Up @@ -96,4 +99,4 @@ object {{classname}}Serializer extends Serializer[{{classname}}] {
override def serialize(implicit format: Formats): PartialFunction[Any, JValue] = {
case value => Extraction.decompose(value)(format - this)
}
}
}

0 comments on commit 205519c

Please sign in to comment.