Hi!
please see comments below.
On Mon, Apr 16, 2007 at 11:48:33AM +0200, Yaxm Yaxm wrote:
> Hi,
> I have a user model that has a couple of other models(like street
> address, tasks).
>
> suppose
> User has a name field
> Address has a state field.
>
> so I want to provide a detailed search form each field in the user and
> its related
> models can be specified.
>
>
> Suppose I have a user that has a name "california", and that user has a
> address with the state field being "california" as well.
>
>
> I use AAF's multi_search:
>
> User.multi_search('state:(california)', [Address, Task])
> returns the correct address instance
>
> User.multi_search('name:(california) ', [Address, Task])
> returns the correct user instance
>
> User.multi_search('name|state:(california) ', [Address, Task])
> return both the address and user instances where the address actually
> belongs to the user that's returned. how can I just get one result
> returned? Otherwise, I'd need to merge these two results because they
> really represent the same user. I understand that I can define a new
> method to return the state in the user model. But I have many other
> models that belong to a user. so it's going to be very tedious to add
> all the new accessor methods just for AAF.
Ferret has no way to specify or handle such relationships between
records. So if you always only want to find user instances in the end,
the logical decision would be to only index users, adding in the data
from other related objects like addresses and so on as needed.
As we're doing Ruby here, I'm sure there is a non-tedious way to
construct the accessor methods for the related record data ;-)
If you don't like that, what about indexing the user_id along with each
Address and Task?
Then you could run your search and just retrieve the user_ids directly
from the index by using the :lazy option:
result = User.multi_search('name|state:(california) ', [Address, Task], :lazy
=> [:user_id])
Now collect the user_ids from these results (due to the lazy option no
db calls will be made for this, just be sure to give the :store => :yes
option for the :user_id field).
> User.multi_search('name:(california) state:(california) ', [Address,
> Task])
> doesn't return any instance. why is this not returning anything?
because AAF uses an implicit AND between query terms - so this query is
looking for a record having both name:california and state:california.
multi_search('name:(california) OR state:(california) ', [Address, Task])
should find both records.
Jens
--
Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
[EMAIL PROTECTED] | www.webit.de
Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk