itemsapi / itemsjs

Extremely fast faceted search engine in JavaScript - lightweight, flexible, and simple to use
Apache License 2.0
346 stars 41 forks source link

Filter seems to break pagination #76

Closed amwhalen closed 3 years ago

amwhalen commented 3 years ago

I've slightly modified the demo example code given in the documentation of the IMDB search with pagination to illustrate the problem. I added a simple filter to the options given to itemsjs.search, and the result is that clicking past page 1 does not show any results. This was the only change I made to the example code:

filter: (item) => { return item.year > 1994; }

Fiddle here: https://jsfiddle.net/awhalen/5wmL9jv2/

Perhaps I'm misusing or misunderstanding filter, or maybe I should use prefilter (which doesn't actually seem to do anything?). Thanks.

amwhalen commented 3 years ago

A little investigation reveals that when calling .search, making sure there is a sort options specified makes it work as intended. The demo did not specify a sort option. Here is updated code that appears to function correctly:

var result = itemsjs.search({
    query: this.query,
    page: this.page,
    per_page: 12,
    filters: this.filters,
    sort: 'name_asc',
    filter: (item) => {
      return item.year > 1994;
    }
})