algolia / gatsby-plugin-algolia

A plugin to push to Algolia based on graphQl queries
https://yarn.pm/gatsby-plugin-algolia
Apache License 2.0
177 stars 45 forks source link

matchFields duplicating #118

Closed good3n closed 3 years ago

good3n commented 3 years ago

This is likely a misconfiguration issue on my end, and not a bug. When I rebuild my site, I get duplicate entries in Algolia. I'm using a modified field for matchFields with enablePartialUpdates: true. I've posted my configurations below, if anyone could take a look.

GraphQL query:

{
    wpgraphql {
      therapists(first: 1000) {
        edges {
          node {
            id
            title
            content
            slug
            therapistsAcf {
              therapistPhoto
              therapistUpdated
            }
            therapistPreferences(first: 1000, where: {hideEmpty: true}) {
              edges {
                node {
                  name
                  id
                  slug
                }
              }
            }
            // ...
const queries = [
  {
    query: searchQuery,
    settings: {
      advancedSyntax: true,
    },
    transformer: ({ data }) =>
      data.wpgraphql.therapists.edges.map(({ node }) => ({
        id: node.id,
        name: node.title,
        content: node.content.replace(/(<([^>]+)>)/gi, ''),
        slug: node.slug,
        photo: node.therapistsAcf.therapistPhoto,
        updated: node.therapistsAcf.therapistUpdated,
        preferences: node.therapistPreferences.edges.map(
          ({ node: preference }) => ({
            id: preference.id,
            name: preference.name,
            slug: preference.slug,
          })
        ),
       // ...

Plugin configuration:

{
  resolve: 'gatsby-plugin-algolia',
  options: {
    appId: process.env.GATSBY_ALGOLIA_APP_ID,
    apiKey: process.env.GATSBY_ALGOLIA_ADMIN_KEY,
    indexName: process.env.GATSBY_ALGOLIA_INDEX_NAME,
    queries,
    chunkSize: 10000,
    enablePartialUpdates: true,
    matchFields: ['updated'],
  },
},

Is there something I am missing that is required for the partial updates to use the updated field?

Haroenv commented 3 years ago

is this something you can reproduce with a query returning static data in a GitHub repository I can try out? from the code you sent, it looks all right!

good3n commented 3 years ago

is this something you can reproduce with a query returning static data in a GitHub repository I can try out? from the code you sent, it looks all right!

I could see if I could set something like that up. I could clone the repo but not entirely sure how I'd return static data (so that it doesn't mess with Algolia if I'm not around to fix it since it's live data).

Haroenv commented 3 years ago

I mean that you could change the Wordpress result to instead return something static, so I can try it out too

good3n commented 3 years ago

Not entire sure how it was fixed but I recently updated the plugin from 0.0.4 to the latest 0.20.1 and this is not longer an issue.

Haroenv commented 3 years ago

matchFields didn't yet exist in 0.0.4, so that makes sense @good3n 👍