hi, So I have a model with a lot of associated models. Indexing the model with
class Asset
define_index do
indexes [titles.title], :as => :title
# about a dozen other fields here
end
end
turned out to be really slow on account of the huge number of joins
required. So I created an sort of cache class, which stores the
concatenated field:
class Asset
after_save :update_terms
def update_terms
self.asset_terms ||= AssetTerms.new
asset_terms.title = titles.map(&:title).join(' ')
end
end
class AssetTerm
belongs_to :asset
define_index do
indexes :title
end
end
This prevents having to do any joins at indexing time, and so really
speeds things up a lot.
The details are at
http://github.com/mlc/wnetpbcore/commit/c5b5d0ffbd2d6e7f959c329e0910f9b26ac1d331
Full source for the application is available by clicking on the
appropriate github links from there.
But my client now wants me to add some faceting support.
Is there any sane (or, likely, only moderately insane) way to get
faceting support here? I can presumably define a crc32 method in ruby
and then do something like:
asset_terms.title_facet = titles.map{|t| t.title.crc32}.join(',')
to store the facets into the database for join-free indexing, but then
how do I easily convince Thinking Sphinx to treat this field as a
"precomputed" facet?
Any help would be much appreciated.
Thanks a lot!
mlc
signature.asc
Description: OpenPGP digital signature
