Match a huge list of keywords against a string using ruby
<p>I have a lot of text documents on the one hand and a huge list of Keywords (Strings) on the other hand. Now I'm interested, which of these keywords are contained in the documents. </p>

<p>At the moment I'm using a monstrous auto generated regex:</p>

<pre><code>keywords = %w(Key1, Key2, Key3)
regx = Regexp.new('\b(' + keywords.join('|') + ')\b','i')
documents.each |d|
    d.scan(regx)
end
</code></pre>

<p>This worked great for a List of a few hundred keywords but now I'm using about 50000 keywords and it's slowing down too much.</p>

<p>Is there a better way doing such an operation using ruby?</p>

<p><strong>EDIT:</strong></p>

<ul>
<li>The Documents are typical news articles like news about recent sport events as you can find via google news for example. In my testset each article contains about 1000 Words</li>
<li>The Keywords can be single words but could also be phrases containing multiple words like 'Franz Beckenbauer' or 'Russel Wilson'.</li>
<li>I'm interested only in complete matches - so searching for 'diction' should only match 'diction', not 'dictionary'</li>
</ul>