Querying returned results

Hi I’m using the acts_as_ferret to index one table in my database. The
table contains formation about listed items and each of these items
belongs to a section and a category. On the results page I want to have
two drop down boxes whose contents are populated depeneding on the
returned results. So for example the section drop down should only show
sections that exist in the result set, also i would like to display a
count of the number of results returned in that section in the drop down
e.g. sections[cars:5]. Does anyone know the best way to go about this?
I’m a total ferret/lucene beginner…
thanks for any help
cheers
caspar

On 7/6/06, Caspar [email protected] wrote:

cheers
caspar

Hi Caspar,

I’ll try and answer this from a Ferret point of view (I don’t know
acts_as_ferret well enough yet). I think the best way to do this is to
do the search for all documents and do a running count. So something
like this;

sections = {}
models = {}
index.search_each(query_str) do |doc_id, score|
doc = index[doc_id]
(sections[doc[:section]]||=0) += 1
(models[doc[:model]]||=0) += 1
end

You might run into performance problems doing this if your queries are
returning a large number of documents or if the documents are quite
large. The biggest performance hit will come from loading so many
documents from the index. You’ll be able to make this quite fast by
caching the fields that you want to count. Let me know if you do run
into performance problems and I’ll show you how to build a cache of
the field values.

Cheers,
Dave

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs