Datatables filter with both cyrillic and latin at once

Datatables filter with both cyrillic and latin at once

ferofero Posts: 6Questions: 1Answers: 0

Hi, new here, I know there is a need for the test case, but, my question is just theorhetical:

I have a large table with mixed cyrilic and latin characters, when I am searching "Maria" in latin, it's not showing the cyrillic results (which is my goal to show both).

So my goal is to search both latin and cyrillic results with a single query.

Example: Querying "Maria" , the table will show both "Maria" and "Мариа"

any help appreciated!

PS: I have my own javascript transliterate script which is OK, but I am not sure how to "implant" it to the databtables to work correctly:

var a = {"Њ":"NJ","Ж":"ZH","ж":"zh","Ш":"SH","ѓ":"gj","Ѓ":"GJ","ш":"sh","Џ":"GJ","ќ":"kj","Ќ":"KJ","Ј":"J","ј":"j","ч":"ch","ч":"ch","џ":"gj","И":"I","Ц":"C","У":"U","К":"K","Е":"E","Н":"N","Г":"G","З":"Z","Х":"H","Ч":"CH","ц":"c","у":"u","к":"k","е":"e","н":"n","г":"g","з":"z","х":"h","Ф":"F","В":"V","А":"A","П":"P","Р":"R","О":"O","Л":"L","Д":"D","е":"e","ф":"f","в":"v","а":"a","п":"p","р":"r","о":"o","л":"l","д":"d","С":"S","М":"M","И":"I","Т":"T","Б":"B","с":"s","м":"m","и":"i","т":"t","б":"b"};

var a2 = {"NJ":"Њ","ZH":"Ж","zh":"ж","SH":"Ш","gj":"ѓ","GJ":"Ѓ","sh":"ш","GJ":"Џ","kj":"ќ","KJ":"Ќ","J":"Ј","j":"ј","ch":"ч","ch":"ч","gj":"џ","I":"И","C":"Ц","U":"У","K":"К","E":"Е","N":"Н","G":"Г","Z":"З","H":"Х","CH":"Ч","c":"ц","u":"у","k":"к","e":"е","n":"н","g":"г","z":"з","h":"х","F":"Ф","V":"В","A":"А","P":"П","R":"Р","O":"О","L":"Л","D":"Д","e":"е","f":"ф","v":"в","a":"а","p":"п","r":"р","o":"о","l":"л","d":"д","S":"С","M":"М","I":"И","T":"Т","B":"Б","s":"с","m":"м","i":"и","t":"т","b":"б"};



function transliterate(word){
  return word.split('').map(function (char) { 
    return a[char] || char; 
  }).join("");
}

function transliterate2(word){
  return word.split('').map(function (char) { 
     return a2[char] || char; 
  }).join("");
}

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    It would be worth looking at the fuzzy search plugin discussed in this blog post - that may offer a solution,

    Colin

  • ferofero Posts: 6Questions: 1Answers: 0

    Hi @colin , sorry to disappoint you,but this is only a Levenshtein approach for typos, it's not including different characters being mapped as in my example.

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    You might need to create a Search Plugin to handle this. This plugin might get you started.

    Kevin

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Yes, no question - a search plug-in would be needed. That's how our own fuzzy search works as well.

    It might make a nice addition to the plug-in if you are willing to share what you implement?

    Allan

  • ferofero Posts: 6Questions: 1Answers: 0

    @kthorngren @allan
    Yes I will work on that later that week, and I will publish it (help may be needed for that). It will be mainly for Macedonian characters, but with slight modification it could be extended to other character sets as well.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Awesome - I look forward to seeing what you cook up :)

    Allan

  • ferofero Posts: 6Questions: 1Answers: 0

    So in the end, I just modified locally THIS plugin, changed the unicode values, added all possible letter combinations and got the result. It works, however, when I have some html formatted text (<b> tags usually) , it just ignores my search query. Also, can I somehow modify both input and search query fo uppercase the whole word/datatable values ? I mean case-insensitive search.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Can you create a test case on http://live.datatables.net for us to see what is going on please?

    Allan

  • ferofero Posts: 6Questions: 1Answers: 0

    http://live.datatables.net/yexofife/1/

    here is an example..

    added few cyrillic entries to the datatable, try first to search Cedric with latin letters

  • ferofero Posts: 6Questions: 1Answers: 0

    @allan - the code works, however, until now I am still stuck with the formatted <td> output. It being ignored by "my" script..

    I've changed the <td> to:
    <td><b>Цедриц Келли</b></td>

    so added bold formatting, and now it cannot be searched..
    Any ideas how to fix that? This is the only thing I need and it will be perfect!

Sign In or Register to comment.