• Resolved Bogdan Gerasymenko

    (@kleindberg)


    It seems like search results in last version sorting by DESC.

    For example, if we type “cat” in search field, the first results will be something like “cats…” and the last is more relevant – products with single word “cat”.

    It would be great if the first results will be most relevant. Then something that looks similar.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Yes, I too have the same issue.

    In general, the latest version seems to have introduced more bugs than it fixed. I also wonder if the developer has ceased supporting this extension. There are outstanding requests over two weeks old. I understand that this is a free app but would be nice to have clarity if this is now time to move on.

    Plugin Author Damian Góra

    (@damian-gora)

    Hi,

    Apologies for the delayed response.

    I haven’t changed anything significant in the search engine for over a year.
    The plugin is at a early stage of development and it needs a lot of new features eg. fuzzy search, faster engine like inverted index, scoring and more.

    In the next plugin release I’m going to add new algorithms to improve results sorting. If you can’t wait, try to paste following code into your functions.php. It should solve your problem.

    
    add_filter('dgwt/wcas/search_results/output', 'dgwt_wcas_tmp_improve_relevance');
    
    function dgwt_wcas_tmp_improve_relevance($output){
    
        if(empty($_REQUEST[ 's' ])){
            return $output;
        }
    
        $keyword = strtolower(sanitize_text_field( $_REQUEST[ 's' ] ));
    
        if(!empty($output[ 'suggestions' ])){
            $i = 0;
            foreach ($output[ 'suggestions' ] as $suggestion){
    
                $pname = strtolower($suggestion['value']);
                similar_text($keyword, $pname, $percent);
    
                $score = $percent;
    
                $pos = strpos($pname, $keyword);
    
                // Add score based on substring position
                if ($pos !== false) {
                    $score += 50; // Bonus for contained substring
    
                    // Bonus for substring position
                    $posBonus = (100 - ($pos * 100) / strlen($pname)) / 2;
                    $score    += $posBonus;
                }
    
                $output[ 'suggestions' ][$i]['score'] = $score;
    
                $i++;
            }
        }
    
        usort($output[ 'suggestions' ], 'dgwt_wcas_tmp_cmp_similarity');
    
        return $output;
    }
    
    function dgwt_wcas_tmp_cmp_similarity($a, $b)
    {
        if ($a['score'] == $b['score']) {
            return 0;
        }
    
        return ($a['score'] < $b['score']) ? 1 : -1;
    }
    
    Thread Starter Bogdan Gerasymenko

    (@kleindberg)

    Thank You for a respond, this code really works fine.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Results sorting in last version’ is closed to new replies.