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

Simple Settings Question: Sorting by Date Descending! #45

Closed dwyn closed 4 years ago

dwyn commented 4 years ago

Hiya! I just have a really simple question on creating replicas and sorting by date - desc. I am following this documentation

In my gatstby-config.js Ive added:

const queries = [
  {
    query: siteQuery,
    transformer: ({ data }) => data.allMarkdownRemark.nodes,
    settings: {  
      replicas: [  // Is this the right place to add replica settings?
        'articles_date_desc'
      ]
    }
  }
];

Is settings the right place to add replicas? Follow up, where would I add

replicaIndex.setSettings({
  ranking: [
    "desc(date_tag)",
    "typo",
    "geo",
    "words",
    "filters",
    "proximity",
    "attribute",
    "exact",
    "custom"
  ]
});

Thanks in advance!

Haroenv commented 4 years ago

Do you want the replica's settings to stay in sync, or is that something you want to set once?

dwyn commented 4 years ago

Hey @Haroenv, Im not exactly sure how to answer. What are the differences between the two options?

Haroenv commented 4 years ago

I'm asking because I have not taken replicas in account yet for the code of this Gatsby plugin. Ideally we would set the settings to any replica indices here: https://github.com/algolia/gatsby-plugin-algolia/blob/master/gatsby-node.js#L60

Apart from that, you should be able to set up the replica index via the settings as you suggest, and change the settings on the replica index only once as well. It should keep the settings on the replica index as expected.

As I said, I haven't tried this flow with Gatsby yet, so if you can set up a project and explain what doesn't behave as you expect, that would be ideal.

dwyn commented 4 years ago

Okay will do! Thanks, @Haroenv