Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter rockitdizajn

    (@rockitdizajn)

    Hello Mikko,

    Everything is solved. Thank you very, very much.
    This is a great plugin and even better support.

    Best regards,
    Rockit

    Thread Starter rockitdizajn

    (@rockitdizajn)

    Hey Mikko, thanks for the straight and honest answer, appreciate that very much. ??

    I have tried literally everything, ended up with updating and removing plugins, updating and removing theme, optimizing and “cleaning” database, clearing browser, website and hosting cache, switching through different combinations of Relevanssi filters. Really, never-ending weekend.

    I really didn’t know what more to do, so i switched everything back manually. And now… it works :). How and why? Don’t have any clue. Don’t getting anymore nonsense results.

    Two days ago, when i searched for number “30” one of many false results (700+) was the product with SKU: F7247-3V without “30” in product id, sku, name, attributes, price, categories, cat. ids, image title or name, url, quantities, height, width, length. Anywhere.

    Now i have this in functions.php (just leaving this if anybody ever needs it):

    /** Search **/
    
    add_filter( 'woocommerce_redirect_single_search_result', '__return_false' ); /** Disables single search result redirect **/
    
    add_filter( 'relevanssi_index_content', '__return_false' ); /** Disables content indexing **/
    
    add_filter('relevanssi_block_one_letter_searches', '__return_false'); /** Allows single-letter search **/
    
    /** Removes space form SKU **/
    add_filter( 'relevanssi_content_to_index', 'rlv_spaceless_sku' );
    function rlv_spaceless_sku( $content, $post ) {
        $sku      = get_post_meta( $post->ID, '_sku', true );
        $content .= ' ' . str_replace( ' ', '', $sku );
        return $content;
    }
    /** Removes hyphens **/
    add_filter('relevanssi_remove_punctuation', 'remove_hyphens', 9);
    function remove_hyphens($a) {
        $a = str_replace('-', '', $a);
        return $a;
    }
    /** Allows inside words search **/
    add_filter( 'relevanssi_fuzzy_query', 'rlv_partial_inside_words' );
    function rlv_partial_inside_words( $query ) {
    	return "(term LIKE '%#term#%')";
    }

    Still one letter search doesn’t work, so if you can help me with that?

    I would also need to have results when i search for ex. “LP 3” or “L 30”.
    As soon as i type one character separately, search shows no results at all.
    You can probably see that i have added – “add_filter(‘relevanssi_block_one_letter_searches’, ‘__return_false’);” and number “1” is set for Minimum word length in advanced options.

    Thanks again and best regards,
    Rockit

    Thread Starter rockitdizajn

    (@rockitdizajn)

    Hello Mikko,

    Actually the default operator is “AND”, while “Disable the OR fallback” is also checked.

    That’s the main reason of my troubles ?? since, it should show exact results (containing all of the presented search terms) as i understand.

    Yes, “lp30” is showing the right results, but is showing only products that start with “lp-30x-xx.”, but if want to search for the product that starts with “lp” and contains “30” (ex. “lp-xxx-30”) as soon as i type “space” between the terms, the search shows unexpected results (or just showing the results that start with “lp”) – ex. “LPB-09-48R”.

    Like i said before, if this is something that could be solved through premium plugin, i’ll have no doubts to get it, since i really like your support efforts and the fact it would resolve the issue/question about this that i have.

    Best regards,
    Rockit

    Thread Starter rockitdizajn

    (@rockitdizajn)

    Hello Mikko once again,

    I’m sorry for changing the post status to unresolved, but i have experienced even more “funny” results in search for the last few days.

    SKU that i’m trying to find is (ex.): “lp-301-18”

    So if i type: “lp 30”
    I should be getting all products with these two parts of SKU – it should be 9 results exactly, but i’m getting 29 results. All of those have “lp” in it, while 20 of these results does not have “30” in any part of the SKU.

    I have also figured out that one letter search is not working, i have set “Minimum word length” to 1, added “add_filter(‘relevanssi_block_one_letter_searches’, ‘__return_false’);” and tried to rebuild the index several times.

    At the end, I’ve used this custom solution that is working (almost, since i still have issues with my theme – Woodmart). I am wondering could this code be implemented with Relevanssi (maybe with this one or Premium solution)?

    One more question: Can you delete/hide links form my previous posts?

    Sorry about my English and thanks in advance.
    Best regards

    product_search_join($join)
    {
        if (is_admin() || !is_search() || !is_woocommerce()) {
            return $join;
        }
    
        global $wpdb;
    
        $join .= " LEFT JOIN {$wpdb->postmeta} meta ON {$wpdb->posts}.ID = meta.post_id ";
    
        return $join;
    }
    
    add_filter('posts_join', 'x_product_search_join');
    
    function x_product_search_where($where)
    {
        if (is_admin() || !is_search() || !is_woocommerce()) {
            return $where;
        }
    
        global $wpdb;
    
        if($_GET['s']) {
            $searchString = stripslashes( trim($_GET['s']) );
            $s = explode(' ', $searchString);
            $newWhere = '';
    
            foreach ($s as $item) {
                if (reset($s) === $item) {
                    $newWhere .= "
                        ({$wpdb->posts}.post_title LIKE '%{$item}%'
                        OR {$wpdb->posts}.post_content LIKE '%{$item}%'
                        OR (meta.meta_key = '_sku' AND meta.meta_value LIKE '%{$item}%'))
                    ";
                } else {
                    $newWhere .= "
    					AND ({$wpdb->posts}.post_title LIKE '%{$item}%'
    					OR {$wpdb->posts}.post_content LIKE '%{$item}%'
    					OR (meta.meta_key = '_sku' AND meta.meta_value LIKE '%{$item}%'))
    				";
                }
            }
    
            $where = preg_replace(
                "/\(\s*{$wpdb->posts}.post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
                $newWhere, $where);
        }
    
        return $where;
    }
    
    add_filter('posts_where', 'x_product_search_where');
    Thread Starter rockitdizajn

    (@rockitdizajn)

    Hello once again,

    Code that you have send me solved the issue.
    Just wanted to thank you for your help and effort.

    Best regards,
    Rockit

    Thread Starter rockitdizajn

    (@rockitdizajn)

    Hello Mikko,

    Thanks for your quick reply.

    How to index products without spaces and hyphens, and how to do that separately for search terms? I have create custom field “search_field” that contains full product name and sku, (exact copy of terms separated by space) and added it next to “_sku” in Relevanssi.

    *** Advanced indexing settings are all set to “Remove”.

    And just a small addition to previews post, not sure that matters:
    If typed “LN” [space] “02” [space] “5” (without [space]”BK”), still getting no results
    https://staging1.rasveta.net/?s=LN+02+5&post_type=product

    Thanks again,
    Rockit

Viewing 6 replies - 1 through 6 (of 6 total)