krisk / Fuse

Lightweight fuzzy-search, in JavaScript
https://fusejs.io/
Apache License 2.0
17.89k stars 759 forks source link

Performance advise and how to store multiple record types in the same index #512

Closed marceloverdijk closed 3 years ago

marceloverdijk commented 3 years ago

I would like to use Fuse for searching various "record" types on a website, so not trying to index pages itself.

Let's say we have Author, Publisher and Book records like:

Author:

Publisher

Book:

I want all of these in the same search index so I was thinking adding them like:

[
  {
    "type": "author",
    "id": "joanne-rowling",
    "attributes": {
      "author": {
        "firstName": "Joanne",
        "lastName": "Rowling",
        "nationality": {
          "alpha2Code": "GB",
          "name": "Great Britain"
        }
      }
    }
  },
  {
    "type": "publisher",
    "id": "bloomsbury",
    "attributes": {
      "publisher": {
        "name": "Bloomsbury",
        "country": {
          "alpha2Code": "GB",
          "name": "Great Britain"
        }
      }
    }
  },
  {
    "type": "book",
    "id": "0-7475-3269-9",
    "attributes": {
      "book": {
        "title": "Harry Potter and the Philosopher's Stone",
        "genre": ["Fantasy"]
      }
    }
  }
]

And when indexing set the keys like:

keys: [
  'attributes.author.firstName',
  'attributes.author.lastName',
  'attributes.author.nationality.alpha2Code',
  'attributes.author.nationality.name',
  'attributes.publisher.name',
  'attributes.publisher.country.alpha2Code',
  'attributes.publisher.country.name',
  'attributes.book.title',
  'attributes.book.genre'
]

I wonder if this is the best approach to set it up - in terms of performance - , or to make a more "unified" model ? My index will be ~3000 records.

Thanks for your help.

krisk commented 3 years ago

Can you clarify what you mean by a “unified model”?

marceloverdijk commented 3 years ago

Yes, what I mean is I have divided the model with attributes per type now.

As alternative I could use something like:

[
  {
    "type": "author",
    "id": "joanne-rowling",
    "name": "Joanne Rowling", // concat firstName + lastName
    "countryAlpha2Code": "GB",
    "countryName": "Great Britain"
  },
  {
    "type": "publisher",
    "id": "bloomsbury",
    "name": "Bloomsbury",
    "countryAlpha2Code": "GB",
    "countryName": "Great Britain"
  },
  {
    "type": "book",
    "id": "0-7475-3269-9",
    "name": "Harry Potter and the Philosopher's Stone",
     "tags": ["Fantasy"]
  }
]

and I could use:

keys: [
  'name',
  'countryAlpha2Code',
  'countryName',
  'tags'
]

which more-or-less unifies the different models in the index. And I wonder if that would make a difference in performance? PS: I have no performance issue now, but I'm looking for the best setup.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days