I’ve Model Called Categories. Id and name column
and another model called contacts which has id, name, address, phone,
city, location, neighbourhood and lanmark.
i’ve implemeneted ferret. (it isnt a problem)
in model for categories and contacts
acts_as_ferret :remote => true
my question is
if i pass a value like this on controller
value = “%jewellary%” @categories = Category.find_by_contents(value) @contacts = Contact.find_by_contents(value)
I can get datas from categories. which i’ve already.
but if i pass value as
value = “%je%” @categories = Category.find_by_contents(value) @contacts = Contact.find_by_contents(value)
i dont get any datas displayed.
as far as i understood that ferret searches for whole string like
jewellary.
yes…you can do Contact.find_by_sql([‘SELECT * FROM contacts WHERE
contents LIKE ?’, ‘%’+je+‘%’])
I think I may be a little out on the syntax…you can check it here: http://api.rubyonrails.org/ look for “find_by_sql” under “Methods”
Actually I think those single quotes should be double quotes, not sure
if it makes a difference so that should be :
Contact.find_by_sql([“SELECT * FROM contacts WHERE
contents LIKE ?”, “%”+je+“%”])
Also if you want to search for multiple search terms you use question
marks in the SQL and declare all the variables at the end like this:
…[“SELECT * FROM tablname WHERE column 1 = ? AND column2 LIKE ? AND
column3 = ?”, @variable1, “%”+@variable2+“%”, @variable3]
Bala, depending on how big your ferret index is, destroy it and then
recreate it as it might be a problem in that. I ran into a similar
problem
about a month ago and I seem to recall that’s how I fixed it.