travis-r6s / gridsome-plugin-flexsearch

Add lightning fast search to Gridsome with FlexSearch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Only certain fields are successfully added to the Flexsearch Index, despite configuration

kcole93 opened this issue · comments

I'm experiencing an odd issue whereby only the id, path and slug fields of a collection are being added to each item in the flexsearch index, with all other fields being ignored.

{
      use: 'gridsome-plugin-flexsearch',
      options: {
        flexsearch: {
          profile: 'match'
        },
        searchFields: ['name', 'path'],
        collections: [
          {
            typeName: 'Document',
            indexName: 'Documents',
            fields: ['name', 'id', 'path', 'slug', 'type']
          }
          ]
      }
}

Upon running gridsome develop, I am notified that, as expected, all nodes in my collection were successfully added to the search index, but upon inspecting flexsearch.json, only the above three fields are included for each node in the index entry (name and type are not included):

image

Yet when querying in the GraphQL explorer, I have no issues retrieving these fields' values:

query {
  document (id: "recGDLb8jVCL8bYFf") {
    name
    type
    slug
    path
  }
}

Returns:

{
  "data": {
    "document": {
      "name": "The Bangladesh Citizenship (Temporary Provisions) Order, 1972",
      "type": [
        "Domestic Law and Policy"
      ],
      "slug": "the-bangladesh-citizenship-temporary-provisions-order-1972",
      "path": "/documents/the-bangladesh-citizenship-temporary-provisions-order-1972/"
    }
  }
}

Everything also seems okay when looking at the schema of the type Document:
image

For reference, my environment is:

  • gridsome v.0.7.21
  • gridsome-plugin-flexplugin v.1.0.5 (installed via npm)
  • node v.12.18.3

I don't think it should be relevant, but I am using the gridsome/source-airtable plugin to build the Document collection by fetching records from Airtable, but it appears that sources and the GraphQL schema are created before the Search Index, so this shouldn't be a problem.

@kcole93 That is odd - I don't suppose you have a public repo I could test this out on, or a codesandbox reproduction?

I've added you to a repo, but I think I've figured it out. There appears to be a _name_space issue with the word name. When I changed the field's name to documentName, everything works as expected 🤦‍♂️.

Edit: Spoke too soon...

It turns out that there's something going on with the way that naming conventions are handled either in the Gridsome Airtable Source plugin or across plugins. Although the GraphQL Explorer shows the collection's fields in camel case, flexsearch only seems to index them correctly if field names in the source Airtable base exactly match the fields entered in the searchFields and fields options. slug was being picked up correctly as that field's name in the Airtable base was also slug in all lowercase.