summaryrefslogtreecommitdiff
path: root/pieces/search.js
diff options
context:
space:
mode:
Diffstat (limited to 'pieces/search.js')
-rw-r--r--pieces/search.js87
1 files changed, 2 insertions, 85 deletions
diff --git a/pieces/search.js b/pieces/search.js
index 6606272..4bfb48c 100644
--- a/pieces/search.js
+++ b/pieces/search.js
@@ -1,3 +1,5 @@
+
+
/** Search Engine
* ---------------------------------------------------------------------------
*
@@ -81,92 +83,7 @@ function retrosearch_module(options) {
- /** 2.PURIFY STRING FUNCTIONS
- * -------------------------------------------------------------------------
- *//////////////////////////////////////////////////////////////////////////
-
-
- /** keyboardize
- * -------------------------------------------------------------------------
- * translates string to keyboard-latin keys
- * (the ones that used whan typing each letter of the word)
- *
- * @param str (string): original string (utf8 of latin or greek subgroups)
- * @return (string): latin/ascii equivalent string
- */
-
- // cache (keeo in global) any-character to keyboard-latin mapping
- // --- -- -- - - -
- var ORiGiNal = 'ςερτυθιοπασδφγηξκλζχψωβνμΕΡΤΥΘΙΟΠΑΣΔΦΓΗΞΚΛΖΧΨΩΒΝΜάέήίόύώϊΐϋΆΈΉΊΌΎΏΪΫQWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789- '.split('');
- var kbKeyZed = 'sertyuiopasdfghjklzxcvbnmertyuiopasdfghjklzxcvbnmaehioyviiyaehioyviyqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm0123456789- '.split('');
- const map = new Map();
- for (var i=0; i<ORiGiNal.length; i++) map.set(ORiGiNal[i], kbKeyZed[i]);
-
- // "keyboardize" function
- // --- -- -- - - -
- function keyboardize(str) {
- str = str.replace('\'','');
- var out = '';
- // [map]'s implementation is 40x faster than [for]'s
- for (var i=0 ; i< str.length; i++) out += map.get(str[i]);
- return out;
- }
-
- /** sanitize_GR
- * -------------------------------------------------------------------------
- * replaces greek accended vowels with non accended ones
- * takes care of sigma on the end of words
- *
- * @param {string} str
- * @return {string} sanitized
- */
-
- // first cache (=create a global array)
- // of accended to non-accended vowels mapping
- // --- -- -- - - -
- accented_vowels = [];
- [
- 'ά α', 'έ ε', 'ή η', 'ί ι', 'ϊ ι', 'ΐ ι', 'ό ο', 'ύ υ', 'ϋ υ', 'ώ ω',
- 'Ά Α', 'Έ Ε', 'Ή Η', 'Ί Ι', 'Ϊ Ι', 'Ό Ο', 'Ύ Υ', 'Ϋ Υ', 'Ώ Ω'
- ].forEach( pair => {
- ap = pair.split(' ');
- accented_vowels.push({
- a: ap[0], // accented
- p: ap[1] // pure = non accended
- });
- })
-
- // the actual `sanitize_GR` function code
- // --- -- -- - - -
- function sanitize_GR(str) {
-
- str = str.toLowerCase();
- // replace accended vowels with pure ones
- accented_vowels.forEach( v => {
- str = str.replaceAll(v.a, v.p);
- });
-
- // replace sigma on the end of words
- str = str + ' ';
- str = str.replaceAll('σ-', 'ς-');
- str = str.replaceAll('σ ', 'ς ');
-
- return str;
- }
-
-
- /** clean text
- * --- -- -- - - -
- * removes non keyword characters [+ . , !] and internal multiple-spaces
- * @param txt (string): product description
- */
- function clean_text(txt) {
- return txt.replace('+',' ').replace('.',' ').replace(',',' ') // change to space
- .replace('!','').replace('\"', '') // remove character
- .replace(' ',' ').replace(' ',' '); // remove multiple spaces
- }
-
/** 3. SUPPLEMENTARY FUNCTIONS