<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="https://stackoverflow.com/questions/307291/how-does-the-google-did-you-mean-algorithm-work">How does the Google “Did you mean?” Algorithm work?</a>  </p>
</blockquote>



<p>Suppose you have a search system already in your website. How can you implement the "Did you mean:<code>&lt;spell_checked_word&gt;</code>" like Google does in some <a href="http://www.google.com/search?hl=en&amp;q=spellling&amp;btnG=Search" rel="noreferrer">search queries</a>?</p>

[{'answer_id': 41431, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 3, 'selected': False, 'text': '<p>I would suggest looking at <a href="http://en.wikipedia.org/wiki/Soundex" rel="noreferrer">SOUNDEX</a> to find similar words in your database.</p>\n\n<p>You can also access google own dictionary by using the <a href="http://code.google.com/apis/soapsearch/reference.html#1_3" rel="noreferrer">Google API spelling suggestion request</a>.</p>\n'}, {'answer_id': 41433, 'author': 'Keith', 'author_id': 905, 'author_profile': 'https://Stackoverflow.com/users/905', 'pm_score': 0, 'selected': False, 'text': "<p>Soundex is good for phonetic matches, but works best with peoples' names (it was originally developed for census data)</p>\n\n<p>Also check out Full-Text-Indexing, the syntax is different from Google logic, but it's very quick and can deal with similar language elements.</p>\n"}, {'answer_id': 41438, 'author': 'Michael Neale', 'author_id': 699, 'author_profile': 'https://Stackoverflow.com/users/699', 'pm_score': 0, 'selected': False, 'text': '<p>Soundex and "Porter stemming" (soundex is trivial, not sure about porter stemming).</p>\n'}, {'answer_id': 41443, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>Check <a href="http://en.wikipedia.org/wiki/Levenshtein_distance" rel="noreferrer">this</a> article on wikipedia about the Levenshtein distance. Make sure you take a good look at Possible improvements.</p>\n'}, {'answer_id': 41448, 'author': 'Boris Terzic', 'author_id': 1996, 'author_profile': 'https://Stackoverflow.com/users/1996', 'pm_score': 7, 'selected': True, 'text': '<p>Actually what Google does is very much non-trivial and also at first counter-intuitive. They don\'t do anything like check against a dictionary, but rather they make use of statistics to identify "similar" queries that returned more results than your query, the exact algorithm is of course not known.</p>\n\n<p>There are different sub-problems to solve here, as a fundamental basis for all Natural Language Processing statistics related there is one must have book: <a href="https://rads.stackoverflow.com/amzn/click/com/0262133601" rel="noreferrer" rel="nofollow noreferrer">Foundation of Statistical Natural Language Processing</a>.</p>\n\n<p>Concretely to solve the problem of word/query similarity I have had good results with using <a href="http://en.wikipedia.org/wiki/Edit_distance" rel="noreferrer">Edit Distance</a>, a mathematical measure of string similarity that works surprisingly well. I used to use Levenshtein but the others may be worth looking into.</p>\n\n<p>Soundex - in my experience - is crap.</p>\n\n<p>Actually efficiently storing and searching a large dictionary of misspelled words and having sub second retrieval is again non-trivial, your best bet is to make use of existing  full text indexing and retrieval engines (i.e. not your database\'s one), of which <a href="http://lucene.apache.org/java/docs/" rel="noreferrer">Lucene</a> is currently one of the best and coincidentally ported to many many platforms.</p>\n'}, {'answer_id': 41455, 'author': 'robaker', 'author_id': 190, 'author_profile': 'https://Stackoverflow.com/users/190', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://en.wikipedia.org/wiki/N-gram#Google_use_of_N-gram" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/N-gram#Google_use_of_N-gram</a></p>\n'}, {'answer_id': 41613, 'author': 'oglester', 'author_id': 2017, 'author_profile': 'https://Stackoverflow.com/users/2017', 'pm_score': 2, 'selected': False, 'text': '<p>If you have industry specific translations, you will likely need a thesaurus. For example, I worked in the jewelry industry and there were abbreviate in our descriptions such as kt - karat, rd - round, cwt - carat weight... Endeca (the search engine at that job) has a thesaurus that will translate  from common misspellings, but it does require manual intervention.</p>\n'}, {'answer_id': 41625, 'author': 'GateKiller', 'author_id': 383, 'author_profile': 'https://Stackoverflow.com/users/383', 'pm_score': 2, 'selected': False, 'text': '<p>I think this depends on how big your website it. On our local Intranet which is used by about 500 member of staff, I simply look at the search phrases that returned zero results and enter that search phrase with the new suggested search phrase into a SQL table.</p>\n\n<p>I them call on that table if no search results has been returned, however, this only works if the site is relatively small and I only do it for search phrases which are the most common.</p>\n\n<p>You might also want to look at my answer to a similar question:</p>\n\n<ul>\n<li><a href="https://stackoverflow.com/questions/39240/similar-posts-like-functionality-using-ms-sql-server#39316">&quot;Similar Posts&quot; like functionality using MS SQL Server?</a></li>\n</ul>\n'}, {'answer_id': 255590, 'author': 'FA.', 'author_id': 33281, 'author_profile': 'https://Stackoverflow.com/users/33281', 'pm_score': 3, 'selected': False, 'text': '<p>You may want to look at Peter Norvig\'s "<a href="http://www.norvig.com/spell-correct.html" rel="noreferrer">How to Write a Spelling Corrector</a>" article.</p>\n'}, {'answer_id': 258222, 'author': 'Liam', 'author_id': 18333, 'author_profile': 'https://Stackoverflow.com/users/18333', 'pm_score': 3, 'selected': False, 'text': '<p>I believe Google logs all queries and identifies when someone makes a spelling correction. This correction may then be suggested when others supply the same first query. This will work for any language, in fact any string of any characters.</p>\n'}, {'answer_id': 258290, 'author': 'Will', 'author_id': 15721, 'author_profile': 'https://Stackoverflow.com/users/15721', 'pm_score': 5, 'selected': False, 'text': '<p>Google\'s Dr Norvig has outlined how it works; he even gives a 20ish line Python implementation:</p>\n\n<p><a href="http://googlesystem.blogspot.com/2007/04/simplified-version-of-googles-spell.html" rel="noreferrer">http://googlesystem.blogspot.com/2007/04/simplified-version-of-googles-spell.html</a></p>\n\n<p><a href="http://www.norvig.com/spell-correct.html" rel="noreferrer">http://www.norvig.com/spell-correct.html</a></p>\n\n<p>Dr Norvig also discusses the "did you mean" in <a href="http://videos.syntience.com/ai-meetups/peternorvig.html" rel="noreferrer">this excellent talk</a>.   Dr Norvig is <em>head of research</em> at Google - when asked how "did you mean" is implemented, his answer is <strong><em>authoritive</em></strong>.</p>\n\n<p>So its spell-checking, presumably with a dynamic dictionary build from other searches or even actual internet phrases and such.  But that\'s still <em>spell checking</em>.</p>\n\n<p>SOUNDEX and other guesses don\'t get a look in, people!</p>\n'}, {'answer_id': 302727, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>There\'s something called aspell that might help:\n<a href="http://blog.evanweaver.com/files/doc/fauna/raspell/classes/Aspell.html" rel="nofollow noreferrer">http://blog.evanweaver.com/files/doc/fauna/raspell/classes/Aspell.html</a></p>\n<p>There\'s a ruby gem for it, but I don\'t know how to talk to it from python\n<a href="http://blog.evanweaver.com/files/doc/fauna/raspell/files/README.html" rel="nofollow noreferrer">http://blog.evanweaver.com/files/doc/fauna/raspell/files/README.html</a></p>\n<p>Here\'s a quote from the ruby implementation</p>\n<blockquote>\n<p>Usage</p>\n<p>Aspell lets you check words and suggest corrections. For example:</p>\n<pre><code>  string = &quot;my haert wil go on&quot;\n\n  string.gsub(/[\\w\\\']+/) do |word|\n    if !speller.check(word)\n      # word is wrong\n      puts &quot;Possible correction for #{word}:&quot;\n      puts speller.suggest(word).first\n    end\n  end\n</code></pre>\n</blockquote>\n<p>This outputs:</p>\n<p>Possible correction for haert:\nheart\nPossible correction for wil:\nWill</p>\n'}, {'answer_id': 452264, 'author': 'Fabian Steeg', 'author_id': 18154, 'author_profile': 'https://Stackoverflow.com/users/18154', 'pm_score': 0, 'selected': False, 'text': '<p>Implementing spelling correction for search engines in an effective way is not trivial (you can\'t just compute the edit/levenshtein distance to every possible word). A solution based on k-gram indexes is described in <a href="http://nlp.stanford.edu/IR-book/html/htmledition/spelling-correction-1.html" rel="nofollow noreferrer">Introduction to Information Retrieval</a> (full text available online).</p>\n'}, {'answer_id': 823601, 'author': 'cherouvim', 'author_id': 72478, 'author_profile': 'https://Stackoverflow.com/users/72478', 'pm_score': 1, 'selected': False, 'text': '<p>I do it with <a href="http://lucene.apache.org/" rel="nofollow noreferrer">Lucene</a>\'s <a href="http://wiki.apache.org/jakarta-lucene/SpellChecker" rel="nofollow noreferrer">Spell Checker</a>.</p>\n'}, {'answer_id': 823694, 'author': 'Costas Boulis', 'author_id': 101355, 'author_profile': 'https://Stackoverflow.com/users/101355', 'pm_score': 4, 'selected': False, 'text': '<p>I was pleasantly surprised that someone has asked how to create a state-of-the-art spelling suggestion system for search engines. I have been working on this subject for more than a year for a search engine company and I can point to information on the public domain on the subject.</p>\n\n<p>As was mentioned in a previous post, Google (and Microsoft and Yahoo!) do not use any predefined dictionary nor do they employ hordes of linguists that ponder over the possible misspellings of queries. That would be impossible due to the scale of the problem but also because it is not clear that people could actually correctly identify when and if a query is misspelled.</p>\n\n<p>Instead there is a simple and rather effective principle that is also valid for all European languages. Get all the unique queries on your search logs, calculate the edit distance between all pairs of queries, assuming that the reference query is the one that has the highest count. </p>\n\n<p>This simple algorithm will work great for many types of queries. If you want to take it to the next level then I suggest you read the paper by Microsoft Research on that subject. You can find it <a href="http://acl.ldc.upenn.edu/acl2004/emnlp/pdf/Cucerzan.pdf" rel="noreferrer">here</a> </p>\n\n<p>The paper has a great introduction but after that you will need to be knowledgeable with concepts such as the Hidden Markov Model.</p>\n'}, {'answer_id': 3888537, 'author': 'hugo24', 'author_id': 252135, 'author_profile': 'https://Stackoverflow.com/users/252135', 'pm_score': 0, 'selected': False, 'text': '<p>U could use ngram for the comparisment: <a href="http://en.wikipedia.org/wiki/N-gram" rel="nofollow">http://en.wikipedia.org/wiki/N-gram</a></p>\n\n<p>Using python ngram module: <a href="http://packages.python.org/ngram/index.html" rel="nofollow">http://packages.python.org/ngram/index.html</a></p>\n\n<pre><code>import ngram\n\nG2 = ngram.NGram([  "iis7 configure ftp 7.5",\n                    "ubunto configre 8.5",\n                    "mac configure ftp"])\n\nprint "String", "\\t", "Similarity"\nfor i in G2.search("iis7 configurftp 7.5", threshold=0.1):\n    print i[1], "\\t", i[0]\n</code></pre>\n\n<p>U get:</p>\n\n<pre><code>&gt;&gt;&gt; \nString  Similarity\n0.76    "iis7 configure ftp 7.5"    \n0.24    "mac configure ftp"\n0.19    "ubunto configre 8.5"   \n</code></pre>\n'}, {'answer_id': 12037677, 'author': 'Narendra Rajput', 'author_id': 1089469, 'author_profile': 'https://Stackoverflow.com/users/1089469', 'pm_score': 0, 'selected': False, 'text': '<p>Why not use google\'s did you mean in your code.For how see here\n<a href="http://narenonit.blogspot.com/2012/08/trick-for-using-googles-did-you-mean.html" rel="nofollow">http://narenonit.blogspot.com/2012/08/trick-for-using-googles-did-you-mean.html</a></p>\n'}]
['https://Stackoverflow.com/questions/41424', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2644/']