Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type for highlight field #41

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jackwilsdon
Copy link

@jackwilsdon jackwilsdon commented Sep 19, 2023

Change Summary

This PR introduces a new SearchHighlightV2 type which is used for the SearchResultHit#highlight field.

I've opened this as a draft as this version of the spec doesn't quite play nicely with the generator used by typesense-go (it creates some weirdly named structs). The generated Go version can be a bit nicer by making these changes:

--- openapi.yml
+++ openapi.yml
@@ -1465,9 +1465,7 @@
           additionalProperties:
             oneOf:
               - $ref: "#/components/schemas/SearchHighlightV2"
-              - type: array
-                items:
-                  $ref: "#/components/schemas/SearchHighlightV2"
+              - $ref: "#/components/schemas/SearchHighlightV2Array"
         document:
           type: object
           description: Can be any key-value pair
@@ -1560,6 +1558,10 @@
             type: string
           example:
             - Stark
+    SearchHighlightV2Array:
+      type: array
+      items:
+        $ref: "#/components/schemas/SearchHighlightV2"
     SearchOverrideSchema:
       type: object
       required:

Annoyingly, the Go version still doesn't offer a way to detect if the oneOf is an array or not, instead throwing an error if you call the wrong AsSearchHighlightV2* function.

But introducing an additional schema seems less than ideal. I'm open to any suggestions on how to improve this further.

PR Checklist

@jackwilsdon jackwilsdon marked this pull request as draft September 19, 2023 14:22
@jackwilsdon
Copy link
Author

Looks like this doesn't work for object fields, as they have two levels of nested objects:

{
  "highlight": {
    "my_object_field": {
      "my_matching_key_1": {
        "matched_tokens": [ "SEARCH TERM" ],
        "snippet": [ "<mark>SEARCH TERM</mark>" ]
      },
      "my_matching_key_2": {
        "matched_tokens": [ "SEARCH TERM" ],
        "snippet": [ "<mark>SEARCH TERM</mark>" ]
      }
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant