Forum: Ferret How to search with limit by field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
933c6cebf0dd04d2395d413e30b76d87?d=identicon&s=25 Ramon (Guest)
on 2007-05-30 16:33
Hello,

I have a ferret index with 2 fields:

Acts_as_ferret :fields => [:client, :content]

If I do model.find_by_contents(query) I obtain all results by the query
but I would like to obtain 3 results for each client.

Any ideas?

Thanks for all.
0b437712d774b52475c8d265d72ae4b1?d=identicon&s=25 Doug Smith (Guest)
on 2007-05-30 18:45
(Received via mailing list)
Hi Ramon,

I think you'd have to do three different queries:

query = params[:query]
@results1 = model.find_by_contents("client:1 content:#{query}", {:limit
=>
3})
@results2 = model.find_by_contents("client:2 content:#{query}", {:limit
=>
3})
@results3 = model.find_by_contents("client:3 content:#{query}", {:limit
=>
3})

Ferret is fast enough that this shouldn't be a performance problem.

Thanks,

Doug
0761b1a89c2a14c3866e8eea7c6871b6?d=identicon&s=25 Ramon (Guest)
on 2007-06-06 12:12
Thanks Doug,

I thought that ferret could do this query. I don't know to priory the
total of clients i have. If i have 100 clients, i can't do it. Too, I
would like to use the pagination.

Ramón.

Doug Smith wrote:
> Hi Ramon,
>
> I think you'd have to do three different queries:
>
> query = params[:query]
> @results1 = model.find_by_contents("client:1 content:#{query}", {:limit
> =>
> 3})
> @results2 = model.find_by_contents("client:2 content:#{query}", {:limit
> =>
> 3})
> @results3 = model.find_by_contents("client:3 content:#{query}", {:limit
> =>
> 3})
>
> Ferret is fast enough that this shouldn't be a performance problem.
>
> Thanks,
>
> Doug
This topic is locked and can not be replied to.