diff options
| author | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2024-04-10 13:29:01 +0300 |
|---|---|---|
| committer | Geo Halkiadakis <gchalkiadakis@sklavenitis.co.gr> | 2024-04-10 13:29:01 +0300 |
| commit | 2676484041e8771257bf99ed223bd9321fe72fa8 (patch) | |
| tree | ef2e71a6623eabe67bfb4c9732f5271ca945b509 /pieces | |
| parent | 0c65dee04506567ee50537ff2fbb83998b8fef0f (diff) | |
| download | oseine-2676484041e8771257bf99ed223bd9321fe72fa8.tar.gz oseine-2676484041e8771257bf99ed223bd9321fe72fa8.tar.bz2 oseine-2676484041e8771257bf99ed223bd9321fe72fa8.zip | |
working on a custom fs-cache system
Diffstat (limited to 'pieces')
| -rw-r--r-- | pieces/prepare-streams.js | 46 | ||||
| -rw-r--r-- | pieces/search.js | 87 | ||||
| -rw-r--r-- | pieces/suggest.js | 8 |
3 files changed, 46 insertions, 95 deletions
diff --git a/pieces/prepare-streams.js b/pieces/prepare-streams.js index 0e10e27..9a33604 100644 --- a/pieces/prepare-streams.js +++ b/pieces/prepare-streams.js @@ -1,7 +1,9 @@ -const fs = require("fs"); +// const fs = require("fs"); +const fs = require('node:fs'); // const https = require("https"); -var request = require('request-promise'); +// var request = require('request-promise'); +/* var calls = [ request({ url: 'https://storage.googleapis.com/pythia-files/uploads/json/emarket-keywords.json', @@ -20,17 +22,47 @@ Promise.all(calls).then(function(results) { // do something with results[1] // ... }); - +*/ // write files into local fs; use them cached +/* +let file = fs.createWriteStream('../data/emarket-products.json'); -let file = fs.createWriteStream("data.txt"); - -https.get("https://www.w3.org/TR/PNG/iso_8859-1.txt", response => { +https.get('https://storage.googleapis.com/pythia-files/uploads/json/emarket-products.json', response => { var stream = response.pipe(file); stream.on("finish", function() { console.log("done"); }); -});
\ No newline at end of file +}); + +var response = { + success: true, + products: 100, + ttl: + new Date() +} + +*/ + +function create() { + var data = []; + + for( let i = 0; i < (Math.floor(Math.random() * 100) +1) ; i++) { + data.push({ id: i, x5: i*5 }); + } + console.log(data); + + try { + fs.writeFileSync(__dirname + '/../data/j.json', JSON.stringify(data), 'utf-8'); + // file written successfully + } catch (err) { + console.error(err); + } +} + + + +module.exports = { + create +}
\ No newline at end of file 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 diff --git a/pieces/suggest.js b/pieces/suggest.js index ab62cfd..a420edd 100644 --- a/pieces/suggest.js +++ b/pieces/suggest.js @@ -1,7 +1,10 @@ const kb = require('./kb-util.js'); const match = require('./match-util.js'); -var n = 2; // Ngram base +var _allowFuzzy = true; // enable|disable fuzzy search +var n = 2; // Ngram base +var _fuzzyLimit = .5; // minimum bigram score for being considered a match + /** (Search) SUGGESTIONS ENGINE * --------------------------------------------------------------------------- @@ -75,8 +78,7 @@ function suggestions_module(options) { var _maxResults = 24; // limit suggestions var _blendProds = 4; // minimum final-produncts to blend with next-word suggestions var _timeout_ms = 100; // time (in ms) for the search engine to find matches (before rendering) - var _allowFuzzy = true; // enable|disable fuzzy search - var _fuzzyLimit = .5; // minimum bigram score for being considered a match + var _Ngram_base = 2; // number of N in Ngram spliting algorithm var _isReady = false; // whether the searchbox is ready to be used |
