How to search with limit by field

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.

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

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 S. 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