Forum: Ferret Act as Ferret supports Conditional search?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6809b1544c46cee8edeecdfd94197637?d=identicon&s=25 isha kakodkar (Guest)
on 2007-07-24 09:34
(Received via mailing list)
Hi all,
   Im a newbie to ferret.I have installed the act_as_ferret gem and i
actually want to search for some content in the model,but per user.
My model has data,user_id.So within the data column i have to serach for
a
word if it exists for a given user.
So can i achieve that ? presently i know that it just searches the
"data"
column irrespective of the user given.
Can someone help me with this?

Thanks
36feb4959db6ab8259a44962f0fa761f?d=identicon&s=25 Jens Kraemer (Guest)
on 2007-07-24 10:48
(Received via mailing list)
On Tue, Jul 24, 2007 at 12:33:47AM -0700, isha kakodkar wrote:
> Hi all,
>   Im a newbie to ferret.I have installed the act_as_ferret gem and i
> actually want to search for some content in the model,but per user.
> My model has data,user_id.So within the data column i have to serach for a
> word if it exists for a given user.
> So can i achieve that ? presently i know that it just searches the "data"
> column irrespective of the user given.
> Can someone help me with this?

Index the user_id field (as untokenized) and append "
user_id:#{user.id}"
to the query.

cheers,
Jens


--
Jens Krämer
http://www.jkraemer.net/ - Blog
http://www.omdb.org/     - The new free film database
6809b1544c46cee8edeecdfd94197637?d=identicon&s=25 isha kakodkar (Guest)
on 2007-07-25 08:40
(Received via mailing list)
thanx..i actually did it using the :conditions with find_by_contents.
But when i do find_id_by_contents,which searches from the filesystem,can
i
search within data based on this index value?and not just the full data
field?
36feb4959db6ab8259a44962f0fa761f?d=identicon&s=25 Jens Kraemer (Guest)
on 2007-07-26 08:37
(Received via mailing list)
On Tue, Jul 24, 2007 at 11:39:15PM -0700, isha kakodkar wrote:
> thanx..i actually did it using the :conditions with find_by_contents.
> But when i do find_id_by_contents,which searches from the filesystem,can i
> search within data based on this index value?and not just the full data
> field?

yes, every attribute you index is stored in it's own Ferret field, and
you can run queries (or parts of queries) against just one Ferret field
by specifying the field name like I did in the example below.

Jens

> >> So can i achieve that ? presently i know that it just searches the
> >
> >--
> >Jens Krämer
> >http://www.jkraemer.net/ - Blog
> >http://www.omdb.org/     - The new free film database
> >_______________________________________________
> >Ferret-talk mailing list
> >Ferret-talk@rubyforge.org
> >http://rubyforge.org/mailman/listinfo/ferret-talk
> >

> _______________________________________________
> Ferret-talk mailing list
> Ferret-talk@rubyforge.org
> http://rubyforge.org/mailman/listinfo/ferret-talk

--
Jens Krämer
http://www.jkraemer.net/ - Blog
http://www.omdb.org/     - The new free film database
6809b1544c46cee8edeecdfd94197637?d=identicon&s=25 isha kakodkar (Guest)
on 2007-07-27 13:14
(Received via mailing list)
Thats cool...I could get that working too.Thanks a lot..1 more problem i
have before getting it to completion...
I currently have 2 models,chat having a "Has_many" relationship with
messages model.
A chat has a name and messages have message content.So when i search a
keyword,i want 2 go against both these fields.
So if i want 2 do single index on chat module.but for both the
fields...how
do i go about doing it?
so i have chat.rb model and message.rb model.
In chat.rb
      acts_as_ferret :store_class_name => true, :fields => {
         :name , :msg
  }

def msg
  return "#{self.message.find(:all,:select=>'msg')}"
end

msg is supposed to be a array of messages for one chat...So can i index
on
all elements of the msg array within chat module?
And thereafter whenever a msg gets inserted in message model,will its
contents be automatically indexed?

I tried doing t vice-versa by putting index on messages.It works.But in
case
of row pagination doesnt come out well... if many messages have the
keyword,it sends me those many msgIds and they all belong to just 1
chat....total hits become more and actual records i would show are
less...So
extra page numbers gets displayed.

A better option for me would be the first approach..So can you help me
on
it?
This topic is locked and can not be replied to.