Pre Filter and sort data

Hey guys, i am new to algolia and stuck in a task.

instantsearch.widgets.configure({

    facetFilters: ['type:free'],

     hitsPerPage: maxHits,

     //filters: "asc(name)"

    // sortBy: ["name:asc"]

  })

I want to sort the data (asc) and pre-filter data on the basis of date like the last 7 days newly added items.

I am using umd build instantsearch.js, is there any way I can configure the pre-filter for the data and sorting of the data in configure method?
or any other method in window.instantsearch i can use?

Hi,

regarding sorting

By design, Algolia provides one ranking formula per index: when you want to provide different rankings for the same data you need to use different indices for each ranking . These additional indices are called replicas.
You can find more information here in our documentation.
Once you’re created your replica, you can use the correct index/replica directly when initializing instantsearch.

regarding filtering by date

You can find an article just about that in our documentation, but in short:

  • in your indexed data, sort your date as a timestamp rather than a date:
{
  "date": "2018-10-17",
  "date_timestamp": 1539734400,
}
  • use that timestamp to create a numeric filter, for your example:
filters: `date_timestamp > ${Math.floor(d.setDate(d.getDate() - 7) / 1000)}`

Best,

1 Like

thanks, buddy, found it very useful.