Extending lovd search

0 views
Skip to first unread message

AssimovT

unread,
Jul 18, 2008, 6:45:44 AM7/18/08
to Lovd by Less
HI!

Does anyone know how to extend the search fields in lovd?

For instance I would like to define extra conditions in
find_by_contents in profile model, however seems they dont work.

I tried it like this for test purposes and havent seen any SQL queries
in logs:

Profile.find_by_contents q, :limit=>all, :conditions => ['user_id =
1']


Thanks for all help,

Tair.

Steven A Bristol

unread,
Jul 21, 2008, 10:11:32 AM7/21/08
to lovdb...@googlegroups.com

Hi Tair,

Try http://projects.jkraemer.net/acts_as_ferret/ for the ferret docs.

steve

Sazima

unread,
Jul 24, 2008, 12:30:34 PM7/24/08
to Lovd by Less
Hey Tair,

I managed to do something similar. In profile.rb:

def self.search query = '', options = {}
query ||= ''
q = '*' + query.gsub(/[^\w\s-]/, '').gsub(' ', '* *') + '*'
options.each {|key, value| q += " #{key}:#{value}"}
# arr = find_by_contents q, :limit=>:all
arr = find_by_contents q, {}, {:conditions => "profiles.is_active
= 1"}
logger.debug arr.inspect
arr
end


Cheers, Sazima

AssimovT

unread,
Jul 28, 2008, 8:09:41 AM7/28/08
to Lovd by Less
Sazima, thanks for reply!

I am trying with the following lines:

#options.each {|key, value| q += " #{key}:#{value}"}
arr = Profile.find_by_contents q, {}, {:conditions=>[where.join(" AND
"), options]}

Basically I feed the options from the form and make a query together
with "q" parameter.

However I get the following error:

wrong number of bind variables (2 for 1) in: profiles.id in (?) and
user_id != 2

Any ideas?


Thanks,

Tair





wrong number of bind variables (2 for 1) in: profiles.id in (?) and
user_id != 2

Sazima

unread,
Jul 29, 2008, 10:30:37 AM7/29/08
to Lovd by Less
Hi Tair,

I couldn't really check your code working, but from what I understand
about the use of :conditions, you don't need to include the " AND ".
Just pass your SQL conditions and they will be added to the current
query. Sure, if there is more than 1 condition, use must use AND
between them.

Anyway, find_by_contents (alias for find_with_ferret) does some
manipulation with the conditions. I only managed to get it to work
using a textual condition...

Cheers, SAzima
Reply all
Reply to author
Forward
0 new messages