0

我正在尝试使用 Solr 排除具有特定 ID 的结果。我所做的是在可搜索的“整数 id”中定义,然后在 Model.search 中使用“没有”我做“没有:id,id”

这是我的代码示例:

 searchable do
    text(:title, boost: 2.0) { t.title }
    text(:intro) { t.intro }
    text(:detail) { t.detail }

    text(:subjects) { tags.select{ |t| t.name[0,1] == "@" }.map{ |t| t.name }.join( ' ' ) }
    text(:context) { tags.select{ |t| t.name[0,1] == "#" }.map{ |t| t.name }.join( ' ' ) }
    text(:genres) { tags.select{ |t| t.name[0,1] == "_" }.map{ |t| t.name }.join( ' ' ) }

    string :status
    integer :id
    boolean(:has_times) { (dates.reject { |d| d.times.blank? }).any? }
    time(:start_date, multiple: true) { dates.map{ |d| d.start_date } }
    time(:end_date, multiple: true) { (dates.map { |d| d.end_date }).compact }

    boolean :featured
    boolean :top
  end




def Event::tags_search query, event_id = nil, page=1, per_page=3
    search = Event.search(include: [:texts, :dates => :times]) do
      fulltext query do
        minimum_match 1
        boost_fields subjects: 4.0
        boost_fields context: 2.0
        boost_fields genres: 1.5
      end

      without :id, event_id

      # visibility constraints
      with :status, 'published'
      with :has_times, true

      # Combine restrictions (start_date OR ( end_date && !end_date.nil? ) )
      any_of do
        with(:start_date).greater_than_or_equal_to Time.now.to_s :db
        all_of do
          without :end_date, nil
          with(:end_date).greater_than_or_equal_to Time.now.to_s :db
        end
      end

      paginate page: page, per_page: per_page
    end
    search.results
  end

有办法使这项工作吗?

谢谢

4

1 回答 1

1

奇怪,without应该可以...与数组一起使用:

search = Post.search do
  ...
  without(:id, [post_id])
  paginate page: page, per_page: per_page
end
于 2013-04-15T16:09:49.813 回答