Re: [ts] Need a little help

20 views
Skip to first unread message

Pat Allan

unread,
Nov 17, 2012, 11:37:21 PM11/17/12
to thinkin...@googlegroups.com
Hi Matt

Two things: firstly, your 'join' call is invalid - you don't need to refer to the model you're within (distributer_game), just associations *in* that model.

But also, given you're referring to the game association directly in your game_title field, the join call isn't even necessary.

All that said - Sphinx requires unique integer identifiers for each index, and thus Thinking Sphinx expects models to have primary keys (that are integers, not other data types). If DistributorModel doesn't have a primary key, I think the easiest way forward is to add one.

Cheers

--
Pat

On 18/11/2012, at 7:04 AM, Matt Bilbow wrote:

> Here's my set up.
>
> Game model
> title
> description
>
> Distributer
> title
> link
>
> DistributerGame associated model
> game_id
> distributer_id
> link
>
> I'm trying to add the define_index block to my DistributerGame model.
>
> define_index do
> join distributer_game.game
> # fields
> indexes game.title, :as => :game_title
>
> # attributes
> has game_id, :type => :integer, :as => :game_id
> has distributer_id, :type => :integer, :as => :distributer_id, :facet => true
> end
>
> when i try to index i get the following error:
>
> Cannot automatically map attribute sphinx_internal_id in DistributerGame to an
> equivalent Sphinx type (integer, float, boolean, datetime, string as ordinal).
> You could try to explicitly convert the column's value in your define_index
> block:
> has "CAST(column AS INT)", :type => :integer, :as => :column
>
> I'm guessing this has somethingt o do with having no primary key? but have no idea how to move forwards. Any help would be REALLy appreciated.
>
> Thanks,
> Matt
>
>
> --
> 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/-/rgsHtigTdAYJ.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.



Matt Bilbow

unread,
Nov 19, 2012, 8:39:41 AM11/19/12
to thinkin...@googlegroups.com
Thanks Pat, that's what I ended up doing :)

I do however have a new problem.

I'm passing multiple params from a faceted search back to my controller. Do you know of a way I can 'chain' these to filter my results?

Thanks again,

Matt

Matt Bilbow

unread,
Nov 19, 2012, 8:57:12 AM11/19/12
to thinkin...@googlegroups.com
This is what im trying to do (psuedo(ish) code)

basically just applying filters to the search if params exist.

I realise this is probably a dumb question.

DistributerGame.search :conditions => {:game_genre => genre *** IF PARAMS[GENRE] EXISTS ***}, :with => {:distributer_id => distributer *** if PARAMS[DISTRIBUTER] EXISTS ***, :price_in_gbp => gbp_price_low..gbp_price_high}  ***  if PARAMS[PRICE] EXISTS ***, :per_page => games_per_page

Thanks,
Matt

Pat Allan

unread,
Nov 19, 2012, 6:09:52 PM11/19/12
to thinkin...@googlegroups.com
Hi Matt

I would build :conditions and :with hashes using your logic before the search call, adding the necessary fields and attributes, then use them in your search call:

conditions = {}
with = {}
conditions[:game_genre] = params[:genre] if params[:genre].present?
with[:distributor_id] = params[:distributor] if params[:distributor].present?
# etc

DistributorGame.search :conditions => conditions,
:with => with,
:per_page => games_per_page

Cheers

--
Pat

> --
> 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/-/GxFMh87k9OwJ.

Reply all
Reply to author
Forward
0 new messages