typesense / firestore-typesense-search

Firebase Extension to automatically push Firestore documents to Typesense for full-text search with typo tolerance, faceting, and more
https://extensions.dev/extensions/typesense/firestore-typesense-search
Apache License 2.0
159 stars 35 forks source link

Return unflattened objects from search #44

Closed alegzable closed 1 year ago

alegzable commented 1 year ago

Description

I'm trying to sync unflattened objects into my Typesense collection, however I get the following error:

importResults: [
    {
      code: 404,
      document: '{"title":"Title","address.postalCode":"10785","address.country":"Germany","address.addressLine1":"Neue Nationalgalerie","address.addressLine2":"Potsdamer Straße 50, 10785 Berlin, Germany","address.state":"","address.city":"Berlin"}',
      error: 'Field `address` not found.',
      success: false
    }]

Typesense config

{
  "name": "events",
  "fields": [
   {
      "name": "title",
      "type": "string"
    },
    {
      "name": "address",
      "type": "object"
    }
  ],
  "enable_nested_fields": true
}

If I change the type of the "address" to "auto", the sync works, but the "address" field is flattened:

address.addressLine1 Neue Nationalgalerie
address.addressLine2 Potsdamer Straße 50, 10785 Berlin, Germany
address.city Berlin
address.country Germany
address.postalCode 10785
address.state 

I would like to be able to search by all "address" properties, but have the search return it as an unflattened object. I don't mind it returning both types of results, but I don't want to have to parse flattened objects into JS objects. According to the docs, I can send both flattened and unflattened version of the object, but I haven't been able to achieve this.

To simplify traversing the data in the results, you might want to send both the flattened and unflattened version of the nested fields into Typesense, and only set the flattened keys as indexed in the collection's schema and use them for search/filtering/faceting. At display time when parsing the results, you can then use the nested version. (https://typesense.org/docs/0.24.0/api/collections.html#notes-on-indexing-common-types-of-data)

As a side note, I have been able to sync and search arrays of objects using this simple configuration:

    {
      "index": true,
      "name": "content",
      "optional": false,
      "type": "object[]"
    },

Expected Behavior

Return objects from search.

Actual Behavior

Objects in search results are flattened.

Metadata

Typesense Version: v0.24.0 (typesense-js v.1.5.2)

jasonbosco commented 1 year ago

Could you try with this version of the extension: https://github.com/typesense/firestore-typesense-search/issues/43#issuecomment-1459124822

alegzable commented 1 year ago

@jasonbosco, that works, thank you! When can we expect this to be included in the normal release?

jasonbosco commented 1 year ago

This is now available in the latest GA release.