Hi Alan

Nice to know things have mostly been working well. Here's a few tips for what 
you're trying to do.

First up - you've defined groups as an attribute, which makes sense - though I 
would probably call it group_ids, given it is a collection of ids. Next, to 
filter on attributes, you need to use :with, not :conditions (that's for fields 
only). You also need to pass through the actual id value, not a model.

So, with your first setup, the query should be as follows:

  Item.search searchstring, :page => page, :with => {:groups => group.id}

When it comes to testing, it depends how you want to do this… I recommend 
stubbing out calls in controller/model tests, and then with Cucumber and/or 
Capybara acceptance tests, have a look at ThinkingSphinx::Test and this blog 
post:
http://freelancing-god.github.com/ts/en/testing.html#functional
http://freelancing-gods.com/posts/using_thinking_sphinx_with_cucumber

If there's any more questions, just let me know.

Cheers

-- 
Pat

On 30/11/2011, at 11:55 AM, Alan McCann wrote:

> Hi;
> I am new to ThinkingSphinx (coming from IndexTank). Except for two issues, it 
> has been a smooth transition
> 
> Issue 1: HABTM
> 
> I have this model
> 
> class Item < ActiveRecord::Base
>   has_and_belongs_to_many :groups
>  define_index do
>     indexes title
>     indexes body
>     has groups(:id), :as => :groups
>  end
>  Item.search(searchstring, :page => page,:conditions => {:groups => group)
>  # I pass a group id into the search 
> end
> 
> I keep getting this error 
> ActionView::Template::Error (index item_core: query error: no field 'groups' 
> found in schema):
> 
> I have tried has groups(:id), :as => :group_ids.
> 
> Nothing fixes the issue.
> 
> My second issue is how to test locally. I am deploying to heroku with 
> flyingsphinx but I don't seem to be able to run tests with my local ts 
> instance and it seems strange to have to push code to production to rerun the 
> index to be able to test the changes.
> 
> Any advice is appreciated!
> 
> Alan
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/thinking-sphinx/-/xStJo722WZAJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to