On 10/15/06, Charlie Hubbard <[EMAIL PROTECTED]> wrote: > > I'm trying to add a way to query across associations for a model in > acts_as_ferret. Say I have a model A and it has a relationship with > model B. Like say a Book has many pages. I want to search across the > pages of the Book and produce a list of unique books who's pages match > the terms. So if I have a page that hits then I will add that book to > my list of results. Right now the multi_search returns all pages and > books that match the query. > > This sort of gets difficult with pagination because you can't just keep > track of it yourself. Also the total hits will include all hits on > pages and books. The way the pagination works today with ferret is you > hand it :offsets and :limit params. But, these are fixed width params. > I could end up with 100's of pages that all belong to the same book so I > have to skip all of those. > > This sort of seems like a different kind of search. Not a multi_search > or find_by_contents, but a find_by_association. Where the hit on the > association returns an object of the associated type.
If I manage to implement the Ferret object database[1] this will be simple. Currently though there are two ways to do this. You can index all of the Page data in the Book document, presumably in a :page field. Or you can store the Book ids in the Pages and create a Book id set by scanning through all matching pages. [1] http://www.ruby-forum.com/topic/82086#142613 > Is there something in ferret that allows me to scroll through the > results one by one and stop when I've reached my limit? Sure. Set :limit => :all and call search_each. Then break when you reach your limit. _______________________________________________ Ferret-talk mailing list [email protected] http://rubyforge.org/mailman/listinfo/ferret-talk

