搜索条件sphinx问题

时间:2013-10-14 20:49:28

标签: ruby-on-rails ruby sphinx thinking-sphinx ruby-on-rails-2

我使用gem“thinking_sphinx”进行搜索,版本=> '1.4.14'。

我正在尝试在我的表策略中创建条件,其中policies.deleted = 0

这是我的控制器

 class PolicyController < ApplicationController

    def search
      @policies = Policy.search params[:search],:conditions=>[policies.deleted=0] :include => :client, :match_mode => :boolean
    end

 end

我的模特是:“政策”和“客户”

class Policy < ActiveRecord::Base
   belongs_to :client

   define_index 'policy_foo' do
      indexes mum_policy
      indexes [client.name, client.lastname1], :as => :client_name
      has client_id, created_at
   end
end

class Client < ActiveRecord::Base
  has_many  :policies
end

我试过

    def search
        @policies = Policy.search params[:query],:include => :client, :match_mode => :boolean   
        @search = Policy.find(:all,:conditions=>['deleted=0 and client_id IN (?)',@client])
    end

有人知道如何搜索和条件删除= 0?

我真的很感激帮助

1 个答案:

答案 0 :(得分:1)

您需要删除索引定义中可用的属性:

define_index 'policy_foo' do
  indexes mum_policy
  indexes [client.name, client.lastname1], :as => :client_name

  has client_id, created_at, deleted
end

然后以下内容将起作用:

Policy.search params[:query], :include => :client, :match_mode => :boolean,
  :with => {:deleted => 0, :client_id => @client.id}