Problem with ferret :(


#1

hi, i’m trying ferret and acts_as_ferret, it’s good, but i’ve a little
problem. i’ve a model book which has a title and a quantity, how can i
search using act_as_ferret all books which quantity is > 0 ? and howand
with a search like “book”, how can i found also title like “books” ? and
the last, if i search “bok”, is it possible to find anyway titles with
“book”? (i saw that in ferret is it possible, but with acts_as_ferret?)
thanks


#2

mix wrote:

hi, i’m trying ferret and acts_as_ferret, it’s good, but i’ve a little
problem. i’ve a model book which has a title and a quantity, how can i
search using act_as_ferret all books which quantity is > 0 ? and howand
with a search like “book”, how can i found also title like “books” ? and
the last, if i search “bok”, is it possible to find anyway titles with
“book”? (i saw that in ferret is it possible, but with acts_as_ferret?)
thanks

i’ve another problem… :frowning:
how can i find only records which has “datetime < Time.now?” datetime is
like
updated_at, after this i’ve to sort the records by this datetime…
i’ve tryed for 3 hours but nothing :frowning:
thanks :frowning:


#3

Jan P. wrote:

http://ferret.davebalmain.com/api/classes/Ferret/QueryParser.html

Have you had a look at the api? Here’s an excerpt from the above uri
regarding range queries. Sorting of date-fields has been subject of
discussion as well: http://www.ruby-forum.com/topic/84502
Cheers,
Jan

yep, yesterday i looked it but it didn’t work…anyway today i tried
another time and now works, maybe the problem was another, btw, about
date is ok, but there still are another problem, i’ve a string field
which is empty or with a comment, how can i select all which has this
comment null? i’ve tryed “comment:”, “comment:’’”, "comment: "
“comment:null”, “comment:nil”, “comment:=null”, “comment:=nil”, but
nothing :frowning:
i’ve found a workaround like this:

acts_as_ferret :fields => [:com

def com
self.comment == ‘’ ? ‘0’ : self.comment
end

def self.full_text_search(query)
return nil if query.nil? or (query == ‘’)
query = “com:0”
Model.find_by_contents(query, {:limit => :all})
end

what do you think?

just the last question… i’ve a model which has a has_many
relationship, and i saw that when ferret retrieve the results does a
query like this:

SELECT * FROM something WHERE (something.id in
(‘33’,‘22’,‘6’,‘11’,‘23’,‘12’,‘24’,‘13’,‘8’,‘25’,‘14’,‘9’,‘26’,‘15’,‘27’,‘16’,‘28’,‘17’,‘29’,‘31’,‘20’,‘19’,‘21’,‘32’,‘10’))

is it possible to do a join with another table to get also the
information of the relationship? because in the result list i’ve to show
also that informations, and with a join i’d have n query less :slight_smile:


#4

i solved the first with this:

acts_as_ferret :fields => [:com

def com
self.comment == ‘’ ? ‘null’ : ‘comment’
end

def self.full_text_search(query)
return nil if query.nil? or (query == ‘’)
query = “com:null”
Model.find_by_contents(query, {:limit => :all})
end

because i don’t need to have the comment, so a simple ‘comment’ is ok…

about the join how can i do ? :frowning:


#5

http://ferret.davebalmain.com/api/classes/Ferret/QueryParser.html

Have you had a look at the api? Here’s an excerpt from the above uri
regarding range queries. Sorting of date-fields has been subject of
discussion as well: http://www.ruby-forum.com/topic/84502
Cheers,
Jan

RangeQuery

A range query finds all documents with terms between the two query
terms.
This can be very useful in particular for dates. eg;

‘date:[20050725 20050905]’ # all dates >= 20050725 and <= 20050905
‘date:[20050725 20050905}’ # all dates >= 20050725 and < 20050905
‘date:{20050725 20050905]’ # all dates > 20050725 and <= 20050905
‘date:{20050725 20050905}’ # all dates > 20050725 and < 20050905

You can also do open ended queries like this;

‘date:[20050725>’ # all dates >= 20050725
‘date:{20050725>’ # all dates > 20050725
‘date:<20050905]’ # all dates <= 20050905
‘date:<20050905}’ # all dates < 20050905

Or like this;

‘date: >= 20050725’
‘date: > 20050725’
‘date: <= 20050905’
‘date: < 20050905’

If you prefer the above style you could use a boolean query but like
this;

‘date:( >= 20050725 AND <= 20050905)’

But rangequery only solution shown first will be faster


#6

On Sun, Mar 04, 2007 at 04:24:07PM +0100, mix wrote:

 query = "com:null"
 Model.find_by_contents(query, {:limit => :all})

end

because i don’t need to have the comment, so a simple ‘comment’ is ok…

that shoukd work. however your above method completeley ignores the
original query, which probably is not what you want.
query << " com:null"
is what you probably wanted to do…

about the join how can i do ? :frowning:

Model.find_by_contents(query, { :limit => :all }, { :include => [
:relationship ] }

the third argument to find_by_contents is a hash of options as you would
use if you selected your records with Model.find .

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
removed_email_address@domain.invalid | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa


#7

Jens K. wrote:

that shoukd work. however your above method completeley ignores the
original query, which probably is not what you want.
query << " com:null"
is what you probably wanted to do…

ehm, yes… confused with = :slight_smile:

Model.find_by_contents(query, { :limit => :all }, { :include => [
:relationship ] }

thanks :slight_smile:

for now ferret is real cool, i’ve done the basic search :slight_smile: