Pat, you're a genius!

I defined my indexes now like this:

  has category.category_translations.name, :as
=> :category_name, :type => :string

and voila, it's working....:-)

Thanks a ton......

On Jun 4, 11:10 pm, Pat Allan <[email protected]> wrote:
> Indeed, we don't want an array, we want a number (much like  
> title_sort). And it clarifies the issue: You're trying to sort on what  
> could (possibly) be a collection of strings. Can you put your  
> development.sphinx.conf file (without database passwords) onto gist or  
> pastie, so I can check something?
>
> Also, something that may *possibly* fix it:
>
>    has category.category_translations.name,
>      :as => :category_name,
>      :type => :string
>
> Cheers
>
> --
> Pat
>
> On 04/06/2009, at 5:05 PM, j0llyr0g3r wrote:
>
>
>
> > Ah, ok, we're getting closer...:-)
>
> >>> Track.search('beat impelling', :order => 'category_name  
> >>> ASC').results[:matches]
>
> > gives me:
>
> > => [{:doc=>1, :attributes=>{"beat"=>1, "exact_speed"=>130,
> > "vocals"=>0, "category_name"=>[], "sphinx_deleted"=>0, "theme_name"=>
> > [], "subclass_crcs"=>[388159394], "is_loop"=>1, "title_sort"=>26,
> > "class_crc"=>388159394,
> > "sphinx_internal_id"=>1}, :weight=>20, :index=>0},
> > {:doc=>2, :attributes=>{"beat"=>1, "exact_speed"=>104, "vocals"=>0,
> > "category_name"=>[], "sphinx_deleted"=>0, "theme_name"=>[],
> > "subclass_crcs"=>[388159394], "is_loop"=>0, "title_sort"=>35,
> > "class_crc"=>388159394,
> > "sphinx_internal_id"=>2}, :weight=>20, :index=>1},
> > {:doc=>13, :attributes=>{"beat"=>1, "exact_speed"=>90, "vocals"=>0,
> > "category_name"=>[], "sphinx_deleted"=>0, "theme_name"=>[],
> > "subclass_crcs"=>[388159394], "is_loop"=>1, "title_sort"=>16,
> > "class_crc"=>388159394,
> > "sphinx_internal_id"=>13}, :weight=>20, :index=>2},
> > {:doc=>15, :attributes=>{"beat"=>1, "exact_speed"=>125, "vocals"=>0,
> > "category_name"=>[], "sphinx_deleted"=>0, "theme_name"=>[],
> > "subclass_crcs"=>[388159394], "is_loop"=>0, "title_sort"=>46,
> > "class_crc"=>388159394,
> > "sphinx_internal_id"=>15}, :weight=>20, :index=>3},
> > {:doc=>18, :attributes=>{"beat"=>1, "exact_speed"=>120, "vocals"=>0,
> > "category_name"=>[], "sphinx_deleted"=>0, "theme_name"=>[],
> > "subclass_crcs"=>[388159394], "is_loop"=>0, "title_sort"=>37,
> > "class_crc"=>388159394,
> > "sphinx_internal_id"=>18}, :weight=>20, :index=>4},
> > {:doc=>20, :attributes=>{"beat"=>1, "exact_speed"=>129, "vocals"=>0,
> > "category_name"=>[], "sphinx_deleted"=>0, "theme_name"=>[],
> > "subclass_crcs"=>[388159394], "is_loop"=>0, "title_sort"=>1,
> > "class_crc"=>388159394,
> > "sphinx_internal_id"=>20}, :weight=>20, :index=>5},
> > {:doc=>22, :attributes=>{"beat"=>1, "exact_speed"=>93, "vocals"=>0,
> > "category_name"=>[], "sphinx_deleted"=>0, "theme_name"=>[],
> > "subclass_crcs"=>[388159394], "is_loop"=>0, "title_sort"=>9,
> > "class_crc"=>388159394,
> > "sphinx_internal_id"=>22}, :weight=>20, :index=>6},
> > {:doc=>24, :attributes=>{"beat"=>1, "exact_speed"=>125, "vocals"=>0,
> > "category_name"=>[], "sphinx_deleted"=>0, "theme_name"=>[],
> > "subclass_crcs"=>[388159394], "is_loop"=>0, "title_sort"=>21,
> > "class_crc"=>388159394,
> > "sphinx_internal_id"=>24}, :weight=>20, :index=>7},
> > {:doc=>39, :attributes=>{"beat"=>1, "exact_speed"=>160, "vocals"=>0,
> > "category_name"=>[], "sphinx_deleted"=>0, "theme_name"=>[],
> > "subclass_crcs"=>[388159394], "is_loop"=>0, "title_sort"=>38,
> > "class_crc"=>388159394,
> > "sphinx_internal_id"=>39}, :weight=>20, :index=>8},
> > {:doc=>42, :attributes=>{"beat"=>1, "exact_speed"=>110, "vocals"=>0,
> > "category_name"=>[], "sphinx_deleted"=>0, "theme_name"=>[],
> > "subclass_crcs"=>[388159394], "is_loop"=>0, "title_sort"=>33,
> > "class_crc"=>388159394,
> > "sphinx_internal_id"=>42}, :weight=>20, :index=>9},
> > {:doc=>49, :attributes=>{"beat"=>1, "exact_speed"=>140, "vocals"=>1,
> > "category_name"=>[], "sphinx_deleted"=>0, "theme_name"=>[],
> > "subclass_crcs"=>[388159394], "is_loop"=>0, "title_sort"=>13,
> > "class_crc"=>388159394,
> > "sphinx_internal_id"=>49}, :weight=>20, :index=>10}]
>
> > But now i have to ask: What does this tell me?
>
> > I guess
>
> >  category_name"=>[]
>
> > in the resultset isn't good, so i probably did something wrong with my
> > index-definitions?
>
> > On Jun 4, 10:28 pm, Pat Allan <[email protected]> wrote:
> >> Argh, after all that, I got the syntax wrong. Sorry.
>
> >> Try Track.search(...).results[:matches]
>
> >> --  
> >> Pat
>
> >> On 04/06/2009, at 4:25 PM, j0llyr0g3r wrote:
>
> >>> Ah, ok...:-)
>
> >>> But are you sure this is correct?
>
> >>> Because:
>
> >>>  Track.search('beat impelling', :order => 'category_name ASC')
> >>> [:matches]
>
> >>> gives me:
>
> >>>  TypeError: Symbol as array index
> >>>        from (irb):1:in `[]'
> >>>        from (irb):1
>
> >>> On Jun 4, 4:15 pm, Pat Allan <[email protected]> wrote:
> >>>> Ah, that's just the email client wrapping my code - put it all on  
> >>>> one
> >>>> line. Here's another example without the search term (although you
> >>>> should keep that in):
> >>>>    Track.search(:order => 'category_name ASC')[:matches]
>
> >>>> --
> >>>> Pat
>
> >>>> On 04/06/2009, at 7:51 AM, j0llyr0g3r wrote:
>
> >>>>> Hey Pat,
>
> >>>>> sorry, I am not sure what you mean? Is this:
>
> >>>>>> What's the output of the following?
> >>>>>>   Track.search('beat impelling', :order => 'category_name ASC')
> >>>>>> [:matches]
>
> >>>>> a typo?
> >>>>> Because i read your peepcode and something like "[:matches]" is
> >>>>> nowhere mentioned.....
>
> >>>>> If not, here is the output in "script/console":
>
> >>>>>>> Track.search('beat impelling', :order => 'category_name ASC')
> >>>>> => [#<Track id: 1, artist: "foobar", title:
> >>>>> "House", ................
> >>>>>>> [:matches]
> >>>>> => [:matches]
>
> >>>>> On Jun 4, 12:09 am, Pat Allan <[email protected]> wrote:
> >>>>>> What's the output of the following?
> >>>>>>    Track.search('beat impelling', :order => 'category_name ASC')
> >>>>>> [:matches]
>
> >>>>>> --
> >>>>>> Pat
>
> >>>>>> On 03/06/2009, at 11:44 AM, j0llyr0g3r wrote:
>
> >>>>>>> Hi Pat,
>
> >>>>>>> and thanks for your insights on this issue. I had to tweak your
> >>>>>>> proposal since
>
> >>>>>>>  indexes category.category_translations , :as => :category
>
> >>>>>>> won't work as category_translations is a 'real' table.
>
> >>>>>>> I defined my indexes now like that:
>
> >>>>>>>    has category.category_translations.name, :as  
> >>>>>>> => :category_name
> >>>>>>>    has theme.theme_translations.name, :as => :theme_name
>
> >>>>>>> I reindexed and restarted sphinx.
>
> >>>>>>> Unfortunately, it still isn't working:
>
> >>>>>>>  Track.search 'beat', :order => 'category_name asc'
>
> >>>>>>> now yields a correct resultset, but the sorting still doesn't
> >>>>>>> work.
> >>>>>>> The following example illustrates this:
>
> >>>>>>>>> Track.search('beat impelling', :order => 'category_name
> >>>>>>>>> ASC').each
> >>>>>>>>> {|f| puts f.category.name}
> >>>>>>> Electro / House
> >>>>>>> Hip Hop
> >>>>>>> Funk
> >>>>>>> Techno / Trance
> >>>>>>> Rock
> >>>>>>> Pop
> >>>>>>> Hip Hop
> >>>>>>> Electro / House
> >>>>>>> Rock
> >>>>>>> Rock
> >>>>>>> Pop
>
> >>>>>>> "Tailing" my development.log at the same time shows this:
>
> >>>>>>> Sphinx: beat impelling
> >>>>>>> Sphinx Result: [1, 2, 13, 15, 18, 20, 22, 24, 39, 42, 49]
> >>>>>>>  Track Load (4.6ms)   SELECT * FROM `tracks` WHERE
> >>>>>>> (`tracks`.`id` IN
> >>>>>>> (1,2,13,15,18,20,22,24,39,42,49))
> >>>>>>>  Category Load (3.2ms)   SELECT * FROM `categories` WHERE
> >>>>>>> (`categories`.`id` = 4)
> >>>>>>>  CategoryTranslation Load (0.9ms)   SELECT * FROM
> >>>>>>> `category_translations` WHERE  
> >>>>>>> (`category_translations`.category_id
> >>>>>>> = 4
> >>>>>>> AND (`category_translations`.`locale` IN ('en','root')))
> >>>>>>>  Category Load (0.6ms)   SELECT * FROM `categories` WHERE
> >>>>>>> (`categories`.`id` = 7)
> >>>>>>>  CategoryTranslation Load (0.8ms)   SELECT * FROM
> >>>>>>> `category_translations` WHERE  
> >>>>>>> (`category_translations`.category_id
> >>>>>>> = 7
> >>>>>>> AND (`category_translations`.`locale` IN ('en','root')))
> >>>>>>>  Category Load (0.6ms)   SELECT * FROM `categories` WHERE
> >>>>>>> (`categories`.`id` = 6)
> >>>>>>>  CategoryTranslation Load (0.8ms)   SELECT * FROM
> >>>>>>> `category_translations` WHERE  
> >>>>>>> (`category_translations`.category_id
> >>>>>>> = 6
> >>>>>>> AND (`category_translations`.`locale` IN ('en','root')))
> >>>>>>>  Category Load (0.6ms)   SELECT * FROM `categories` WHERE
> >>>>>>> (`categories`.`id` = 16)
> >>>>>>>  CategoryTranslation Load (4.4ms)   SELECT * FROM
> >>>>>>> `category_translations` WHERE
> >>>>>>> (`category_translations`.category_id =
> >>>>>>> 16 AND (`category_translations`.`locale` IN ('en','root')))
> >>>>>>>  Category Load (2.7ms)   SELECT * FROM `categories` WHERE
> >>>>>>> (`categories`.`id` = 15)
> >>>>>>>  CategoryTranslation Load (0.8ms)   SELECT * FROM
> >>>>>>> `category_translations` WHERE
> >>>>>>> (`category_translations`.category_id =
> >>>>>>> 15 AND (`category_translations`.`locale` IN ('en','root')))
> >>>>>>>  Category Load (2.3ms)   SELECT * FROM `categories` WHERE
> >>>>>>> (`categories`.`id` = 13)
> >>>>>>>  CategoryTranslation Load (0.8ms)   SELECT * FROM
> >>>>>>> `category_translations` WHERE
> >>>>>>> (`category_translations`.category_id =
> >>>>>>> 13 AND (`category_translations`.`locale` IN ('en','root')))
> >>>>>>>  Category Load (0.5ms)   SELECT * FROM `categories` WHERE
> >>>>>>> (`categories`.`id` = 7)
> >>>>>>>  CategoryTranslation Load (0.8ms)   SELECT * FROM
> >>>>>>> `category_translations` WHERE  
> >>>>>>> (`category_translations`.category_id
> >>>>>>> = 7
> >>>>>>> AND (`category_translations`.`locale` IN ('en','root')))
> >>>>>>>  Category Load (0.5ms)   SELECT * FROM `categories` WHERE
> >>>>>>> (`categories`.`id` = 4)
> >>>>>>>  CategoryTranslation Load (0.8ms)   SELECT * FROM
> >>>>>>> `category_translations` WHERE  
> >>>>>>> (`category_translations`.category_id
> >>>>>>> = 4
> >>>>>>> AND (`category_translations`.`locale` IN ('en','root')))
> >>>>>>>  Category Load (0.5ms)   SELECT * FROM `categories` WHERE
> >>>>>>> (`categories`.`id` = 15)
> >>>>>>>  CategoryTranslation Load (6.6ms)   SELECT * FROM
> >>>>>>> `category_translations` WHERE
>
> ...
>
> read more »
--~--~---------~--~----~------------~-------~--~----~
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