0

我使用 gem "thinking_sphinx", version => '1.4.14' 进行了搜索。

我正在尝试在我的表策略中创建条件 policy.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?

我将非常感谢帮助

4

1 回答 1

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}
于 2013-10-15T04:32:50.757 回答