views:

37

answers:

1

I've been using Ferret as my full-text search engine in a small project I'm working on.

Through the documentation and a few examples online, i've been able to pull together a tag cloud generator using the full-text index to help with tag cloud generation using the IndexReader.terms method.

It's worked quite well up to now, when I want to get term data based on a search result.

For example, if the user searches for "cake", I want to show them a tag cloud of terms used in association with the term "cake".

I've been looking for examples of where the terms method can be used in association with a search result set or similar?

Currently I'm using the following method to generate my list of tags:

reader = Ferret::Index::IndexReader.new(Scrape.find_last_index_version)
terms = []
reader.terms(:all_quotes).each do |term, doc_freq|
    terms << [term, doc_freq]
end

Cheers.

A: 

It's more like a term frequency chart (like a wordle) than a tag cloud? Or are these in a tag field? Anyway, the index doesn't keep track of term frequency within each possible document subset (such as the results of a search), so that method wouldn't be fast, even if it existed. For a single document, you can get the TermFreqVector and provide suggested documents that are good matches for other frequent terms in that document. So, you could take some of the top results, grab the term vectors from each one, and just add them up, but those aggregate functions don't exist natively (they generally try not to put slow operations in there.)

MattMcKnight