0

My internal website search engine, based on pg_search, sometimes returns so much text in its search results that Heroku cannot load the page.

The problem is, some search results are so long that I could only publish one of them per page, whereas others are so short I could easily publish 20 of them at once.

So I'd like to pagination my search results, but I'd like to limit the amount of content I publish on each page by word count, not by result count.

I've taken a look at the main pagination gems on Ruby Toolbox like will_paginate, but I can't find any that offer this function.

Does a suitable gem exist? Or is there any a straightforward way of doing this with a gem like will_paginate?

steven_noble
  • 4,133
  • 10
  • 44
  • 77
  • is there a need to display the found results in total or just a part of it, so the user can decide if it is relevant for him/her? You might slice the result text to a limit amount of chars like "#{result.slice(0,100)}..." and then provide a link to the detail page on which the whole result is rendered – jethroo Apr 04 '13 at 08:55
  • I thought of that but unfortunately it wouldn't be an option for this specific app – steven_noble Apr 04 '13 at 09:08

1 Answers1

0

Displaying Only the first x words of a string in rails

I modified this method to get

def get_n_words_with_offset(message, first_n_words=1, offset=0)
   string_arr = message.split(' ')
   string_arr.count > first_n_words ? "#{string_arr[offset..(offset+first_n_words-1)].join(' ')}..." : self
end

From there you can create a pseudomodel that will "paginate" or resplit the array of models returned by word count. Have one of that model encapsulate one page, and you can use a pagination gem where one of those models is on each page.

Community
  • 1
  • 1
illogikal
  • 158
  • 9