2014-07-16 19 views
5

Şöyle ki, aramak benim yöntemine sahip bu params hem arama, başarısız: kullanarak özellik filtresi için birden fazla koşul YA

2.0.0p353 :007 > Machine.filter_search(machine_ad_type_rent: 'rent', currency: 1) 
    Sphinx Retrying query "SELECT *, IF(ad_mask_attr = 1 OR ad_mask_attr = 3, 1, 0) as my_rent_ad_mask FROM `machine_core` WHERE `my_currency` = 1 AND `my_rent_ad_mask` = 1 AND `sphinx_deleted` = 0 ORDER BY `updated_at` desc LIMIT 0, 50000 OPTION max_matches=500000; SHOW META" after error: index machine_core: no such filter attribute 'my_currency' - SELECT *, IF(ad_mask_attr = 1 OR ad_mask_attr = 3, 1, 0) as my_rent_ad_mask FROM `machine_core` WHERE `my_currency` = 1 AND `my_rent_ad_mask` = 1 AND `sphinx_deleted` = 0 ORDER BY `updated_at` desc LIMIT 0, 50000 OPTION max_matches=500000; SHOW META 
    Sphinx Retrying query "SELECT *, IF(ad_mask_attr = 1 OR ad_mask_attr = 3, 1, 0) as my_rent_ad_mask FROM `machine_core` WHERE `my_currency` = 1 AND `my_rent_ad_mask` = 1 AND `sphinx_deleted` = 0 ORDER BY `updated_at` desc LIMIT 0, 50000 OPTION max_matches=500000; SHOW META" after error: index machine_core: no such filter attribute 'my_currency' - SELECT *, IF(ad_mask_attr = 1 OR ad_mask_attr = 3, 1, 0) as my_rent_ad_mask FROM `machine_core` WHERE `my_currency` = 1 AND `my_rent_ad_mask` = 1 AND `sphinx_deleted` = 0 ORDER BY `updated_at` desc LIMIT 0, 50000 OPTION max_matches=500000; SHOW META 
    Sphinx Query (16.5ms) SELECT *, IF(ad_mask_attr = 1 OR ad_mask_attr = 3, 1, 0) as my_rent_ad_mask FROM `machine_core` WHERE `my_currency` = 1 AND `my_rent_ad_mask` = 1 AND `sphinx_deleted` = 0 ORDER BY `updated_at` desc LIMIT 0, 50000 OPTION max_matches=500000 
ThinkingSphinx::SphinxError: index machine_core: no such filter attribute 'my_currency' - SELECT *, IF(ad_mask_attr = 1 OR ad_mask_attr = 3, 1, 0) as my_rent_ad_mask FROM `machine_core` WHERE `my_currency` = 1 AND `my_rent_ad_mask` = 1 AND `sphinx_deleted` = 0 ORDER BY `updated_at` desc LIMIT 0, 50000 OPTION max_matches=500000; SHOW META 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/connection.rb:91:in `rescue in query' 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/connection.rb:94:in `query' 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/connection.rb:75:in `query_all' 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/search/batch_inquirer.rb:17:in `block in results' 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/connection.rb:37:in `block in take' 
    from /Users/serj/.rvm/gems/[email protected]/gems/innertube-1.1.0/lib/innertube.rb:138:in `take' 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/connection.rb:35:in `take' 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/search/batch_inquirer.rb:16:in `results' 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/middlewares/inquirer.rb:9:in `block in call' 
    from /Users/serj/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in `block in instrument' 
    from /Users/serj/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
    from /Users/serj/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/notifications.rb:159:in `instrument' 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/logger.rb:3:in `log' 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/middlewares/inquirer.rb:8:in `call' 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/middlewares/geographer.rb:11:in `call' 
    from /Users/serj/.rvm/gems/[email protected]/gems/thinking-sphinx-3.1.1/lib/thinking_sphinx/middlewares/sphinxql.rb:14:in `call' 
... 16 levels... 
    from /Users/serj/.rvm/gems/[email protected]/gems/railties-4.1.1/lib/rails/commands/console.rb:9:in `start' 
    from /Users/serj/.rvm/gems/[email protected]/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:69:in `console' 
    from /Users/serj/.rvm/gems/[email protected]/gems/railties-4.1.1/lib/rails/commands/commands_tasks.rb:40:in `run_command!' 
    from /Users/serj/.rvm/gems/[email protected]/gems/railties-4.1.1/lib/rails/commands.rb:17:in `<top (required)>' 
    from /Users/serj/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require' 
    from /Users/serj/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require' 
    from /Users/serj/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency' 
    from /Users/serj/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require' 
    from /Users/serj/Projects/gearup/bin/rails:8:in `<top (required)>' 
    from /Users/serj/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load' 
    from /Users/serj/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `block in load' 
    from /Users/serj/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency' 
    from /Users/serj/.rvm/gems/[email protected]/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:241:in `load' 
    from /Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require' 
    from /Users/serj/.rvm/rubies/ruby-2.0.0-p353/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require' 

perfo hala birlikte kullanmak ve herhangi bir yolu var mı tek düşünen Sfenks sorgu aramak için?

cevap

4

İşin püf noktası burada parçalar halinde SELECT ibarenizi oluşturmak gerekir ki:

select = ['*'] 

if params[:currency].present? 
    select << "IF(currency_attr = #{params[:currency]} OR currency_attr = 0, 1, 0) as my_currency" 
    attribute_filters[:with][:my_currency] = 1 
end 

if params[:machine_ad_type_rent] == 'rent' && params[:machine_ad_type_sale].blank? 
    select << "IF(ad_mask_attr = 1 OR ad_mask_attr = 3, 1, 0) as my_rent_ad_mask" 
    attribute_filters[:with][:my_rent_ad_mask] = 1 
end 

attribute_filters[:select] = select.join(', ') 

ids = Machine.search_for_ids(Riddle::Query.escape(ts_query), attribute_filters)