From: Axel Etzold Date: 2007-11-25T07:54:37+09:00 Subject: Re: string matching algorithm -------- Original-Nachricht -------- > Datum: Sun, 25 Nov 2007 07:40:50 +0900 > Von: David Weldon > An: ruby-talk@ruby-lang.org > Betreff: string matching algorithm > Problem: 1 million+ strings (Set A) need to be matched with 1 million+ > substrings (Set B). For example: > > Set A = > iliketotraveltohawaii > travelmagazine > > Set B = > travel > hawaii > > A(1,2) match "travel" > A(1) matches "hawaii" > > What is the best approach to take with this problem? I have tried using > ferret: > > http://www.ruby-forum.com/topic/132772 > > Indexing is fast, but search is very slow. I think ferret could be a > good choice if I had the substrings split out so iliketotraveltohawaii > -> "i like to travel to hawaii". I have a solution to this problem but > it can't be trusted with misspellings (that's an entirely different > forum topic). Is there something obvious that I'm missing here? > -- > Posted via http://www.ruby-forum.com/. Dear David, just curious: how fast is Array#grep ? a=%w[liketotraveltohawaii travelmagazine] b=%w[travel hawaii] b.each_with_index{|x,i| if a.grep(x) puts 'entry ' + i.to_s + ' in Array a matches ' + x end } Best regards, Axel -- GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS. Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail