Witam, mam problem z filtrowaniem w thinking sphinx, a mianowicie mam modele Article oraz Author połączone relacją habtm ze sobą z tabelą łącząca articles_authors.
Chciałbym mieć możliwość znajdowania artykułów dla poszczególnych ich autorów. Thinking Sphinx działa ale tylko dla samego modelu Article bez filtrowania wg autorów.
W modelu Article mam:
[code]has_and_belongs_to_many :authors
define_index do
indexes title
indexes body
indexes synopsis
has authors(:id), :as => :author_ids
has created_at, updated_at
end[/code]
w modelu Authors:
class Author < ActiveRecord::Base
has_and_belongs_to_many :articles
end
W widoku dla wyszukiwania mam:
<% form_tag searches_path, :method => :get do %>
<fieldset>
<%= text_field_tag :q, h(params[:q]), :maxlength => 50 %>
<%= submit_tag "Szukaj" %>
</fieldset>
<fieldset>
<% @authors.each do |author| %>
<%= check_box_tag 'author_ids[]', author.id -%>
<%= h author.name -%><br />
<% end %>
</fieldset>
<% end %>
W kontrolerze searches_controller mam:
class SearchesController < ApplicationController
def index
@authors = Author.find(:all)
@results = Article.search params[:q], :with_all => {:author_ids => params[:author_ids]}
end
end
Niestety wyszukiwanie przez filtrowanie checkboxami nie działa. Nie działa również wyszukiwanie jak w kontrolerze dam:
@results = Article.search params[:q], :with => {:author_ids => 1}
Wyszukiwanie dla treści dotyczących pól title body synopsis działa. Jak mam filtrować za pomocą thinking_sphinx? Proszę o pomoc. Pozdrawiam