Forum: Ferret Url searching ?

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.
Ad89fb3fe6706facc6b4d17b7c131845?d=identicon&s=25 ahFeel (Guest)
on 2007-03-22 11:09
Hi all :)

I have many objects with a url field, of course containing standards
urls...
I'm trying to match them but i actually got problems with that.

Here's a little code of what i would like to achieve:
require 'rubygems'
require 'ferret'
require 'ftools'

class TestAnalyzer
  def token_stream(field, str)
    ts = Ferret::Analysis::AsciiStandardTokenizer.new(str)
    ts = Ferret::Analysis::AsciiLowerCaseFilter.new(ts)
  end
end

system 'rm -rf /tmp/ferret_test' if File.exists?('/tmp/ferret_test')
File.mkpath('/tmp/ferret_test')
INDEX = Ferret::I.new(:path => '/tmp/ferret_test', :analyzer =>
TestAnalyzer.new)
INDEX << {:type => :url, :url => 'http://google.fr'}
INDEX << {:type => :url, :url => 'http://ferret.davebalmain.com'}
INDEX << {:type => :url, :url => 'http://www.unixaumonde.com'}
INDEX << {:type => :url, :url => 'http://www.rift.fr'}

['type:url AND url:*google*',
 'type:url AND url:*"://foobar"*',
 'type:url AND url:"http://goo"*',
 'type:url AND url:"http://goo*"'].each do |q|
  puts "\nSearching #{q}"
  INDEX.search(q).hits.each { |x| p INDEX[x.doc].load }
  puts "\n"
end

Thanks by advance !
Regards,
Jeremie 'ahFeel' BORDIER
Rift Technologies
This topic is locked and can not be replied to.