Autocomplete with spelling check and multiple check for text field

Hey. I use the default jQuery autocomplete function for Drupal 6 for one of my custom text fields.

Now I would like to add spellchecker as well as multiple validation .

for instance

Word: Potatos Spellchecker suggestions (including plural check): Potato, Potatoes 

Is there a way to implement this feature so that with a custom Potatos dash. First, a spell check will be performed on the script, which will suggest the correct alternatives, and as soon as the user selects the correct word, will the script auto-complete?

+4
source share
3 answers

what you need to do is first install the solution on the server side to perform your spellchecks , you can, for example, use PSpell . If you cannot install PSpell, you can use Googlespell (just remember to look at the terms of use). There are also some client-side implementation options (although not as reliable as server solutions).

There are many plugins to help you deal with spell checking, but for your Id task, go for something easier, like jQuery spellchecker .

Initiate your spelling case with the necessary parameters and create an event listener for your text field, a simple example would be:

 var spellchecker = new $.SpellChecker('textarea', { lang: 'en', parser: 'text', webservice: { path: '../../webservices/php/SpellChecker.php', driver: 'pspell' }, suggestBox: { position: 'above' } }); $('textarea').keyup(function() { //you would probably want to add a timer looking to see if user is finished typing spellchecker.check(); }); 

Then you want to add a listener for the Spellchecker replace.word :

 spellchecker.on('replace.word', function() { //ie: submit the form }); 

If you want to do something more advanced, you can also try overriding Drupal built into the autocomplete Drupal.jsAC event .keyup() and see if the check.success event was check.success (words are spelled incorrectly). If there are no misspelled words, you use the drupals autocomplete implementation for onkeyup events. If misspelled words do nothing for these events.

 var misspelledWord = false; spellchecker.on('check.success', function() { misspelledWord = false; }); spellchecker.on('check.fail', function() { misspelledWord = true; }); jQuery(document).ready(function(){ Drupal.jsAC.prototype.onkeyup = function (input, e) { if(misspelledWord) { if (!e) { e = window.event; } switch (e.keyCode) { case 16: // shift case 17: // ctrl case 18: // alt case 20: // caps lock case 33: // page up case 34: // page down case 35: // end case 36: // home case 37: // left arrow case 38: // up arrow case 39: // right arrow case 40: // down arrow return true; case 9: // tab case 13: // enter case 27: // esc this.hidePopup(e.keyCode); return true; default: // all other keys if (input.value.length > 0) this.populatePopup(); else this.hidePopup(e.keyCode); return true; } } }; }); 

However, it makes more sense for me to implement my own autocomplete using the jQuery AJAX function in spellcheckers replace.word event - you can also use / configure one of the jQuery autocomplete plugins.

0
source

I added the spell check feature to jQuery UI's default autocomplete using the Levenshein distance algorithm. Check out the code on github:

https://github.com/martintaleski/spellcheckAutocomplete

It is wrapped as a jquery plugin. All you have to do is:

 $('.your-selector').spellcheckAutocomplete(); 
0
source

I think the solution should be server side called ajax.

option 1 - soundex mysql

simple and fast

If you use mysql and the data language is English, SOUNDEX may be your option.

http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_soundex

Example:

 mysql> select SOUNDEX('potato'), SOUNDEX('potatos'), SOUNDEX('potatoes'); +-------------------+--------------------+---------------------+ | SOUNDEX('potato') | SOUNDEX('potatos') | SOUNDEX('potatoes') | +-------------------+--------------------+---------------------+ | P300 | P320 | P320 | +-------------------+--------------------+---------------------+ 

Now find in your database the words equal or with slight differences based on the soundex algorithm.

option 2 - sphinxsearch

It is more difficult to install, configure and learn, but support several languages, invoke algorithms, advanced queries (logical mode, etc.), improved performance ...

If you need a better system, a full-text search engine with support support will help you a lot. Take a look at http://sphinxsearch.com/docs/current.html#conf-morphology .

With the advent of potato, potato and potato searches, a search engine configured with morpohology = en will return the same results for you.

0
source

Source: https://habr.com/ru/post/1433520/


All Articles