Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I wrote a pair of gems, <a href="https://github.com/mezis/fuzzily" rel="noreferrer">fuzzily</a> and <a href="https://github.com/mezis/blurrily" rel="noreferrer">blurrily</a> which do trigrams-based fuzzy matching. Given your (low) volume of data Fuzzily will be easier to integrate and about as fast, in with either you'd get answers within 5-10ms on modern hardware.</p> <p>Given both are trigrams-based (which is indexable), not edit-distance-based (which isn't), you'd probably have to do this in two passes:</p> <ul> <li>first ask either gem for a set of best matches trigrams-wise</li> <li>then compare results with your input string, using Levenstein</li> <li>and return the min for that measure.</li> </ul> <p>In Ruby (as you asked), using Fuzzily + the <a href="https://github.com/threedaymonk/text" rel="noreferrer">Text gem</a>, obtaining the records withing the edit distance threshold would look like:</p> <pre><code>MyRecords.find_by_fuzzy_name(input_string).select { |result| Text::Levenshtein.distance(input_string, result.name)] &lt; my_distance_threshold } </code></pre> <p>This performas a handful of well optimized database queries and a few</p> <p>Caveats:</p> <ul> <li>if the "minimal" edit distance you're looking for is high, you'll still be doing lots of Levenshteins.</li> <li>using trigrams assumes your input text is latin text or close to (european languages basically).</li> <li>there probably are edge cases since nothing garantees that "number of matching trigrams" is a great general approximation to "edit distance".</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload