title: Ecto fuzzy match on multiple words
body: <p>In my DB (PostgreSQL) I added the <code>fuzzystrmatch</code> extension and have been trying to use the <code>levenshtein</code> function to match items. It does not work how I would like it to when the columns are strings of multiple words.</p>
  
  <p>The code:</p>
  
  <pre><code>  def fuzzy_search(query_string, threshold \\ 4) do
      query_string = query_string |&gt; String.downcase()
  
      query =
        from item in MyApp.Item,
          where:
            levenshtein(item.name, ^query_string, ^threshold) or
            levenshtein(item.quote, ^query_string, ^threshold),
          order_by:
            fragment(
              "LEAST (?, ?)",
              levenshtein(item.name, ^query_string),
              levenshtein(item.quote, ^query_string)
            )
  
      MyApp.Repo.all(query)
    end
  </code></pre>
  
  <p>The code works (levenshtein is just a macro for a quoted query) but my problem lies with the <code>name</code> column of these items. Item names such as "Lodestone Ammolet" don't match a search for "lodestone" as the second word makes too much of a difference.</p>
  
  <p>If I increase the threshold it just provides too many matches that aren't as relevant. What's the best approach to solve this? I could only think of trying to <code>split</code> the name on spaces and levenshtein match on the result, but I'm unsure of how to do that.</p>