1

since lunr already build the index,

I want get first 10 record (page 1) base on whatever search result (search what can I get the whole dataset as result?)

second, I want get page 2, 10 record, offset=10, (starting from 11, next 10 record)

and so on.

So far, look like lunr only can search keywords. No pagination build in.

hoogw
  • 4,982
  • 1
  • 37
  • 33

1 Answers1

0

I have a way to work around it.

      idx.search('')  

             or 

             idx.search(' ')

             or 

              idx.search('  ')

search empty, or space, or 2 space, you will get all dataset as result.

For page 1: you search idx.search('') to get all dataset as result. Now you use for loop through, only get 1 to 10 records,then break for loop.

For page 2: you perform same idx.search('') search again, you should get the same result set as last time, but you this time you use for loop, from 11 to 20. Because offset is 10(you skip first 10).

and so on

For page x: you perform same idx.search('') search again, you should get the same result set as last time, but this time you use for loop, from (x * 10+1) to ((x * 10+1) +10). Because offset is x * 10 (you skip first x * 10).

hoogw
  • 4,982
  • 1
  • 37
  • 33