Hi Pat,
Here is my define block
define_index do
# fields
indexes name, :as => :book_name
indexes user.freetext, :as => :author_bio
indexes content, :as => :book_desc
indexes [user.firstname, user.lastname], :as => :author_name
indexes user.country, :as => :author_country
# attributes
has user.taggings.tag(:id), :as => :tag_ids
has created_at, :as => :book_created
has book_type_id, :as => :type
end
I actually solved the it with this somewhat ugly metod in my controller
params[:t] = [1,2] unless params[:t]
which then allowed me to use the following search call:
@books = Book.search params[:q],
:conditions => {
:author_country => params[:c],
:type => params[:t]
},
:field_weights => {
:book_name => 20,
:author_name => 15,
:book_desc => 15,
:author_bio => 10
}
:with => {
:tag_ids => params[:g]
},
:per_page => 20,
:page => (params[:page] || 1)
If I am doing something very wrong here I am happy to find out :D.. a bit of
a newbie regarding search so eager to learn
On Mon, Apr 20, 2009 at 1:17 PM, Pat Allan <[email protected]> wrote:
>
> Hi Peter
>
> What's your define_index block looking like? You'll probably need an
> attribute for book_type_id, and then use :with (although :conditions
> will work too, but I recommend keeping filters (for attributes
> -- :with) and query arguments (for fields -- :conditions) separate.
>
> Cheers
>
> --
> Pat
>
> On 20/04/2009, at 7:39 PM, peter_tellgren wrote:
>
> >
> > Dear all
> > I am struggling a bit here with my advance search form where I want my
> > users to be able to find books.
> > I have in my search a select with 3 options, All, Paperback and
> > Hardcover.
> >
> > What I got in my db is a column with book_type_id 1 = paperback, 2 =
> > Hardcover.
> >
> > The problem I am having is that my all option is returning no results
> > since there are no records with the id = 0.
> >
> > How do I solve this i my case?
> >
> > I have tried:
> > Book.search params[:q], :conditions => { :type => params[:t] }
> > Book.search params[:q], :with => { :type => params[:t] }
> >
> > with both I get no result when params[:t] is not passed (i.e. all
> > types interestin).
> >
> > grateful for any help.
> > >
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/thinking-sphinx?hl=en
-~----------~----~----~----~------~----~------~--~---