Skip to content
jdar edited this page Sep 13, 2010 · 8 revisions

OVERVIEW
from the documentation

“a category named ‘Fruit’ with
values of ‘Banana’, ‘Apple’, ‘Orange’, and ‘Grape’. On the search
results page, ‘Fruit’ should be displayed as a facet category with
counts for matches for ‘Banana’, ‘Apple’, ‘Orange’, and ‘Grape’ on any
text field of the document. "

@
class MyClass
searchable do
dynamic_integer :custom_category_ids, :multiple => true do
custom_categories.inject(Hash.new { |h, k| h[k] = [] }) do |map,
custom_category|
map[custom_category.id] << custom_category_values_for(custom_category)
end
end
end
end
search = MyClass.search do
dynamic(:custom_categories) do
facet(some_custom_category.id)
end
end
facet = search.facet(:custom_categories, some_custom_category.id)
@

excerpted from this conversation

==

Sunspot modifies field names in a regular way while indexing and searching from ruby hash-parameters.

Were you to query a Sunspot-indexed record using a lower-level library like RSolr, you might see:
@rsolr.select(:q=>"*:*")[‘response’][‘docs’].first.keys
=> [“updated_at_ds”, “highest_score_is”, “title_texts”, “id”]

NOTES:
- id is magic… solr needs
- do not change primary key field

HOW TO:
- allowing OPTION of non-dynamic indexing by indexing through request_handlers in solrconfig.xml