# Acts\_as\_ferret: per city, per category, etc. indices

**URL:** <https://www.ruby-forum.com/t/acts-as-ferret-per-city-per-category-etc-indices/120319>\
**Category:** Ferret\
**Created:** [November 15, 2007, 7:47pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-per-city-per-category-etc-indices/120319 "2007-11-15T19:47:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![harmless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/2acd7d/32.png) [@harmless](https://www.ruby-forum.com/u/harmless)\
**Post date:** [November 15, 2007, 7:47pm UTC](https://www.ruby-forum.com/t/acts-as-ferret-per-city-per-category-etc-indices/120319/1 "2007-11-15T19:47:06Z")

</div>

i want to search only the model data for the current city—think stores  
and products, store has a city field, products belong to stores.

does acts\_as\_ferret or anything similar have a way to index a subset of  
a table or how would you handle this? best i can think of is using  
ferret manually to create an index for each city, but it seems like it’d  
come up often enough that someone has put together something slicker?

are there any examples you’ve seen anywhere of implementing this type of  
indexing in a rails app?

thanks!

---

<div class="post-metadata">

**Author:** ![harmless](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/2acd7d/32.png) [@harmless](https://www.ruby-forum.com/u/harmless)\
**Post date:** [November 23, 2007, 5:55am UTC](https://www.ruby-forum.com/t/acts-as-ferret-per-city-per-category-etc-indices/120319/2 "2007-11-23T05:55:20Z")

</div>

what i wound up doing is:

- creating a product\_cities method that runs a select distinct at the  
database and dumps a space-delimited list of the city ids where that  
product is found

- adding a +product\_cities: term to every query for a  
product in the context of a city

- reindexing the product object after any new association is made  
between it and a store as this may change the city list

still kinda ick, but serviceable.

Harm Less wrote:

> i want to search only the model data for the current city—think stores  
> and products, store has a city field, products belong to stores.
> 
> does acts\_as\_ferret or anything similar have a way to index a subset of  
> a table or how would you handle this? best i can think of is using  
> ferret manually to create an index for each city, but it seems like it’d  
> come up often enough that someone has put together something slicker?
> 
> are there any examples you’ve seen anywhere of implementing this type of  
> indexing in a rails app?
> 
> thanks!
