title: Faster way to see if a huge list of strings is contained within another string
body: <p>I have a list of around 300k common words stored in an array. So, 1 element of the array = 1 word.</p>
  
  <p>On the other side, I have a huge list of strings that MAY contain one or more of these 300k words inside them. A sample string would be: <code>ifdxawesome453</code>.</p>
  
  <p>Now, I need to check each of these long strings against the common words. If a word is found within that string, immediately return. So, I need to check the 300k words again <code>ifdxawesome453</code> and see if any of them is contained within it.</p>
  
  <p>So what I do is:</p>
  
  <pre><code>huge_list_of_words.any? do |word|
    random_long_word.include?(word)
  end
  </code></pre>
  
  <p>While this is okay for small samples of random long words, if I have millions of them, suddenly it takes hours to finish the job.</p>
  
  <p>Is there a way to do this faster? The only way I thought of is if I sample out, say 10k most common words out of these 300k and compare against it first, and if no match is found, compare against the full list.</p>
  
  <p>Another way that drastically sped things up was to group the array of the 300k words by size. When I then compare the long random word against it, I first check if the word's size and filter out any longer words. I am then left with the indexes of the equal size or less words, and search against them, starting from the word with the smallest size.</p>