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

Support for nested objects #19

Open
amamenko opened this issue Sep 22, 2023 · 0 comments
Open

Support for nested objects #19

amamenko opened this issue Sep 22, 2023 · 0 comments

Comments

@amamenko
Copy link

Typesense supports indexing nested objects and arrays of objects since v0.24: https://typesense.org/docs/guide/tips-for-searching-common-types-of-data.html#nested-objects.

I'm not sure if gatsby-plugin-typesense has support for nested objects. For example, if I have a collection schema set up as:

options: {
  rootDir: `${__dirname}/public/something`,
  collectionSchema: {
    name: `something`,
    enable_nested_fields: true,
    fields: [
      {
        name: "id",
        type: "string",
        optional: true,
      },
      {
        name: "pages",
        type: "object[]",
      },
      {
        name: "pages.index",
        type: "int32[]",
      },
      {
        name: "pages.body",
        type: "string[]",
      },
    ],
  }

Then I should be able to index a nested object using:

<div data-typesense-field="pages">
  {pages.map((page, index) => {
    return (
      <React.Fragment key={index}>
        <div data-typesense-field="pages.index">
          {index}
        </div>
        <div data-typesense-field="pages.body">
          {page.body}
        </div>
      </React.Fragment>
    );
  })}
</div>

So that a returned object looks something like:

{
  "id": "anything",
  "pages": [
    {
      "index": 0,
      "body": "body0",
    },
    {
      "index": 1,
      "body": "body1",
    },
  ]
}

I believe the closest this plugin can get to a nested object is using object flattening, i.e. indexing pages.index and pages.body as separate fields on the document.

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

No branches or pull requests

1 participant