Forum: Ferret Problem with ferret :(

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.
17a97e09a1b23bc733ae22880a961b59?d=identicon&s=25 mix (Guest)
on 2007-03-03 15:09
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
17a97e09a1b23bc733ae22880a961b59?d=identicon&s=25 mix (Guest)
on 2007-03-03 18:06
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... :(
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 :(
thanks :(
E48d29dc8fedb2878fa518d41cc63d88?d=identicon&s=25 Jan Prill (Guest)
on 2007-03-03 23:52
(Received via mailing list)
http://ferret.davebalmain.com/api/classes/Ferret/Q...

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
17a97e09a1b23bc733ae22880a961b59?d=identicon&s=25 mix (Guest)
on 2007-03-04 15:49
Jan Prill wrote:
> http://ferret.davebalmain.com/api/classes/Ferret/Q...
>
> 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 :(
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 :)
17a97e09a1b23bc733ae22880a961b59?d=identicon&s=25 mix (Guest)
on 2007-03-04 16:24
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 ? :(
C9dd93aa135988cabf9183d3210665ca?d=identicon&s=25 Jens Kraemer (Guest)
on 2007-03-04 23:02
(Received via mailing list)
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 ? :(

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
kraemer@webit.de | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
17a97e09a1b23bc733ae22880a961b59?d=identicon&s=25 mix (Guest)
on 2007-03-04 23:48
Jens Kraemer 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 = :)

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

thanks :)

for now ferret is real cool, i've done the basic search :)
This topic is locked and can not be replied to.