Jump to content
thirty bees forum

Lathaneo

Members
  • Posts

    46
  • Joined

  • Last visited

Posts posted by Lathaneo

  1. Here a script a play with Levenshtein :

     

    <?php
    header('Content-type: text/html; charset=utf-8');
    
    include('../config/config.inc.php');
    include('../init.php');
    
    ini_set("display_errors", 1);
    ini_set("track_errors", 1);
    ini_set("html_errors", 1);
    ini_set("realpath_cache_size", '5M');
    ini_set('max_execution_time', 60000);
    error_reporting(E_ALL);
    
    $s = "chonney";
    
    $s1 = "niche";
    $s2 = "chien";
    
    $s3 = "nicha";
    $s4 = "niche";
    
    
    $timeStart = microtime_float();
    print("a. Distance : " . levenshtein_utf8($s1, $s2) . "\n");
    $timeEnd   = microtime_float();
    print($timeEnd - $timeStart . "\n\n");
    
    $timeStart = microtime_float();
    print("b. Distance : " . levenshtein($s1, $s2) . "\n");
    $timeEnd   = microtime_float();
    print($timeEnd - $timeStart . "\n\n");
    
    $timeStart = microtime_float();
    print("c. Distance : " . levenshtein_utf8($s3, $s4) . "\n");
    $timeEnd   = microtime_float();
    print($timeEnd - $timeStart . "\n\n");
    
    $timeStart = microtime_float();
    print("d. Distance : " . levenshtein($s3, $s4) . "\n");
    $timeEnd   = microtime_float();
    print($timeEnd - $timeStart . "\n\n");
    
    $timeStart = microtime_float();
    
    $words = getAllWords();
    
    foreach ( $words as &$item ) {
        $item['leven'] = levenshtein_utf8($item['word'], $s);
        echo $item['word'] ." :: ". $item['leven'] . "\n";
    }
    
    uasort($words, function ($a, $b) {
        return $a['leven'] > $b['leven'] ? 1 : -1;
    });
    
    foreach ( $words as &$item ) {
        $item['leven'] = levenshtein_utf8($item['word'], $s);
        echo $item['word'] ." :: ". $item['leven'] . "\n";
    }
    
    $timeEnd   = microtime_float();
    print($timeEnd - $timeStart);
    
    
    
    print(var_dump($words));
    
    print(array_shift($words)['word']);
    
    
    
    function utf8_to_extended_ascii($str, &$map)
    {
        // find all multibyte characters (cf. utf-8 encoding specs)
        $matches = array();
        if (!preg_match_all('/[\xC0-\xF7][\x80-\xBF]+/', $str, $matches))
            return $str; // plain ascii string
    
        // update the encoding map with the characters not already met
        foreach ($matches[0] as $mbc)
            if (!isset($map[$mbc]))
                $map[$mbc] = chr(128 + count($map));
    
        // finally remap non-ascii characters
        return strtr($str, $map);
    }
    
    
    function levenshtein_utf8($s1, $s2)
    {
        $charMap = array();
        $s1 = utf8_to_extended_ascii($s1, $charMap);
        $s2 = utf8_to_extended_ascii($s2, $charMap);
    
        return levenshtein($s1, $s2);
    }
    
    function microtime_float()
    {
        list($usec, $sec) = explode(" ", microtime());
        return ((float)$usec + (float)$sec);
    }
    
    
    function getAllWords()
    {
        $sql = "SELECT `word` FROM `tb_search_word` WHERE `id_lang` = 1;";
    
        $result = Db::getInstance()->executeS($sql);
    
        return $result;
    }

     

  2. Hi,
    I just ask a merge request from a implementation of the Levenshtein algorithm in the search controller.

    What is Levenshtein algorithm : https://en.wikipedia.org/wiki/Levenshtein_distance

    Levenshtein algorithm with PHP https://www.php.net/manual/en/function.levenshtein.php

    The merge request page : https://github.com/thirtybees/thirtybees/pull/970

     

    As I writed in comment of the merge request, the goal is to find some products with the search functionality. Even if you get some miss spelling in the search input.
    That works perfectly with the vanilla ThirtyBees shop with default product.

    For example, you search "chonney" instead of "honey", search controller will be able to find the close word, here honey, and will display honey product in the result.
    Tooltip_020

    Some precisions about the changes:

    a. In case there are many close words, we take the first of the list.
    b. The algorithm is really fast, only 0.005 - 0.010 second to check 2000 words
    b. The algorithm could find some words, really far for the original (schlzcolad -> chocolat).
    c. Later in a another commit, we could choose the better word following some requirements.

    How to try:

    1. Just copy/past the code in controllers/front/SearchController.php . Here the code  https://github.com/thirtybees/thirtybees/pull/970/files
    2. Test it.

    Regards,
    Lathanao

  3. Hi,

    Can you try to put in php file in the root dir with this code, and execute the file :

    ``` <?php

    include('config/config.inc.php'); include('init.php');

    $e = new Employee(1); $e->email = 'you@gmail.com'; $e->lastname = 'you'; $e->firstname = 'you'; $e->idprofile = '1'; $e->idlang = (Context::getContext())->language->id; $e->passwd = Tools::encrypt('12345678'); if (!$e->save()) echo 'Employee save: bad'; else echo 'Employee save: ok'; ```

  4. Hi,

    I don't know if it's working or not, I would like to said "probably yes".

    But for debuging, instead of having '500 error', where you want in your app (e.g. at the end of config\defines.inc.php), you can add : ini_set("display_errors", 1); ini_set("track_errors", 1); ini_set("html_errors", 1); That will show you clearly what's the error. For dev env. you can add some stuff more like : ini_set('post_max_size', '64M'); ini_set('upload_max_filesize', '64M'); ini_set("realpath_cache_size", '5M'); ini_set("max_execution_time", '180'); Regards.

  5. Hi,

    Clearly, you can keep exact URL.

    But short Url are better for Seo, and the number in a product URL is not really necessary.

    How many products you have ? Don't you want get clean URL and make redirection from the old URL. You can use module, or do it manually by adding 301 redirection in you htaccess file.

    Regards.

  6. Hi,

    Just to add a contribution, some months ago, I read that: https://medium.com/mockupless/amazon-checkout-redesign-exercise-part-iii-shipping-and-payment-c351d13bbe9d

    Just a nice demo "amazon flavor" one page checkout.

    Regards.

  7. Hi,

    A premiere vue, Il faudrait avoir un server un peu plus puissant. Sur la home, tu es déjà à + de 9 secondes: https://tools.pingdom.com/#!/cti6x5/dynamic-web-shop.craym.eu/thbees

    La page admin produit a pas mal d'ajax, et demande plus de resource.

    Tu peux essayer d'augmenter le timeout de ton navigateur: https://support.mozilla.org/en-US/questions/1042479

    Si t'es en local, tu peux activer opcache dans ton php.ini: opcache.enable=1

    D'autres paramtètres sont également modifiable pour de meilleurs performances mais faudrait plus d'info sur ta config.

    Et le mieux, serait d'avoir un server plus rapide.

    Cordialement.

  8. Hi,

    I didn't understand every thing, but your almost right. Your "srcset" tag has too short ranges.

    On a great Wordpress template ( e.g. Buildico - Theme - Forest ), you can get examples. For miniature, ranges are bigger like that :

    <img src="picture/p-3.jpg" class="" alt="" srcset="http://website.com/picture/image.jpg 1140w, // image size 1140 x 640 http://website.com/picture/image-300x168.jpg 300w, http://website.com/picture/image-768x431.jpg 768w, http://website.com/picture/image-1024x575.jpg 1024w" sizes="(max-width: 360px) 100vw, 360px" width="360" height="202">

  9. HI @mockob,

    Yes, put it in the header. Yes, the script look for @x2. As "@" doesn't works for image category name, we have to find a trick. So with the tag data-rjs, the script know that there is a second URL with hight-res image. And it's working.

    So, in my case, I use the script only on product-list image, cause most of the other image are already oversized and get a great rendering for mobile device screen.

    [...]shifted on @3x devices? Not with this method, there is only one hight-res image alternativ.

    You can test it on http://dathemebasic.lathanao.com

    0_1524632438091_script.png

    Regards, Lathanao

  10. @mockob

    Hi, You can use the library http://imulus.github.io/retinajs/.

    E.g. for your product list image just :

    • Load it where you want in you template the library
    • Make a category image called homedefault2X
    • put : data-rjs="{$product.cover.bySize.homedefault2x.url}" after the src attribut in img tag.

    So on http://imulus.github.io/retinajs/, they describe 2 method to load the script, I use the first (old) one. The script is really light, and easy to make working, so I recommande.

    Regards, Lathanao.

  11. Hi,

    I'll try to fix the name in ImageOptim-master. and looks for the integration in module store.

    @SLiCK_303, whouhaou, have 31208 results, it's really a lot, i will try a way for the ‘generation by lot’. I don't understand why you get so bad conversion rate, my test are only why default images but should be same with other images.

    @nickon, i'm not looking for a full compatibility with PS 1.6, but with only some few fixs, it's should working.

    Regards.

×
×
  • Create New...