Thinking Sphinx v3.0.0 ordering

268 views
Skip to first unread message

Daly

unread,
Jan 16, 2013, 10:38:05 AM1/16/13
to thinkin...@googlegroups.com
Good morning,

This used to work fine:
options = {:retry_stale => true, :sort_mode => :extended, :order => '@rank DESC', :per_page => 1000000, :sql_order => 'vintage_year DESC'}
options.merge!(:per_page => 10, :page => page) if use_pagination
results = Wine.search(string, options)

After the upgrade, it complains with:
Mysql2::Error: sphinxql: syntax error, unexpected USERVAR, expecting IDENT (or 5 other tokens) near '@rank DESC LIMIT 0, 10; SHOW META'

I tried this:
      options = {
        :retry_stale => true,
        :sort_mode => :extended,
        :select => '*, @rank as custom_rank',
        :order => :custom_rank,
        :per_page => 1000000,
        :sql_order => 'vintage_year DESC'
      }

and that produces:
Mysql2::Error: index wine_core: parse error: Sphinx expr: syntax error, unexpected TOK_USERVAR near '@rank'

What's the proper way of specifying this in the new version?

Thanks.

Pat Allan

unread,
Jan 17, 2013, 9:05:48 AM1/17/13
to thinkin...@googlegroups.com
That error doesn't seem to quite match the query - are you sorting by @rank or custom_rank? Or does the error occur either way? Perhaps SphinxQL doesn't understand @rank - but it should be fine with @weight, which is the same thing.

That said - you're also sorting with the SQL statement - why bother with the Sphinx sort order at all?

(And that SQL ordering should be done like so in v3: :sql => {:order => 'vintage_year DESC'} )

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/-/8rDDG7z8mP0J.
> 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.



Ahmed El-Daly

unread,
Jan 17, 2013, 10:17:44 AM1/17/13
to thinkin...@googlegroups.com
The error occurs either way. I modified it so that it's @weight and that works. Thanks for your help.

---------------------------------------------------------
Ahmed El-Daly
 Chief Guru 
DeveloperGurus Inc.  on budget, on time
T: 416-566-4945  |  developergurus.com

Ahmed El-Daly

unread,
Jan 17, 2013, 10:20:06 AM1/17/13
to thinkin...@googlegroups.com
Oh, and I'm searching by sql, because this doesn't seem to work:

order: '@weight DESC, @vintage_year DESC',

It gives me: Mysql2::Error: sphinxql: syntax error, unexpected USERVAR, expecting IDENT (or 4 other tokens) near '@vintage_year DESC LIMIT 0, 10; SHOW META'

in my wine_index.rb, I have:
indexes vintage_year

Is the syntax correct for what I want to do?

Thanks again.

---------------------------------------------------------
Ahmed El-Daly
 Chief Guru 
DeveloperGurus Inc.  on budget, on time
T: 416-566-4945  |  developergurus.com

On 2013-01-17, at 9:05 AM, "Pat Allan" <p...@freelancing-gods.com> wrote:

Pat Allan

unread,
Jan 17, 2013, 6:50:17 PM1/17/13
to thinkin...@googlegroups.com
When you're referring to an internal Sphinx attribute, you use the @ - but any of your own, you don't. So, try the following:

:order => "@weight DESC, vintage_year DESC"

Ahmed El-Daly

unread,
Jan 17, 2013, 10:11:28 PM1/17/13
to thinkin...@googlegroups.com
Thanks, Pat, but I have already tried that. I should have mentioned that in my post. Doing that produces this error:

Mysql2::Error: index wine_core: sort-by attribute 'vintage_year' not found

#wine_index.rb
ThinkingSphinx::Index.define :wine, with: :active_record, delta:false do
  indexes vintage_year
end

Thanks,
Ahmed

---------------------------------------------------------
Ahmed El-Daly
 Chief Guru 
DeveloperGurus Inc.  on budget, on time
T: 416-566-4945  |  developergurus.com

Pat Allan

unread,
Jan 17, 2013, 10:16:54 PM1/17/13
to thinkin...@googlegroups.com
Hi Ahmed

It'll need to be an attribute, not a field:

has vintage_year

If you've not been sure what the difference is between fields and attributes, have a read of the sections here:
http://pat.github.com/ts/en/sphinx_basics.html

Cheers

--
Pat

Reply all
Reply to author
Forward
0 new messages