• Resolved lateralus821

    (@lateralus821)


    I’ve got Relevanssi configured to use partial words for keyword matching and _sku as a custom field. When I use the search bar on my site (Flatsome theme) it only pulls up SKUs if I type in the full SKU rather than searching based off the first few letters, how can I fix this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Mikko Saari

    (@msaari)

    Does the Relevanssi admin search (Dashboard > Admin search) find products based on partial SKU? Are you talking about some kind of ajax live search here, or the search that happens when you press enter and get the search results page?

    Thread Starter lateralus821

    (@lateralus821)

    Hey Mikko,

    Thanks for getting back to me so quickly!

    I checked the admin search as well as my shop page and Relevanssi is working perfectly there – for example if I search for the first few letters of a SKU it pulls up all products that match.

    The issue I noticed is with the theme’s (Flatsome) built in ajax live search. Do you know of any way that I can link Relevanssi in with my theme’s search function?

    Plugin Author Mikko Saari

    (@msaari)

    The built-in ajax live searches often don’t work with Relevanssi. It depends on the theme if it can be fixed easily or not. If the theme is well-built, it’ll provide a filter hook so you can adjust the search parameters for the live search. If that’s the case, fixing this is easy.

    You can ask this question from the Flatsome support:

    “Does Flatsome provide a filter hook for adjusting the ajax live search parameters that are used for WP_Query or get_posts() when running the search? If it doesn’t, could one be added? It’s needed in order to make the live search compatible with the Relevanssi search plugin.”

    Thread Starter lateralus821

    (@lateralus821)

    Mikko,

    I checked with the dev team and they said yes there are a few filters available in the theme then provided this link that lists them: https://docs.uxthemes.com/article/385-hooks#flatsome_ajax_search_function

    Plugin Author Mikko Saari

    (@msaari)

    Unfortunately their documentation doesn’t really tell what those filters filter ?????♂? Fortunately someone has posted (4 years ago) the Flatsome code on GitHub. Based on that, this should work:

    function rlv_flatsome_search_function( $function, $query, $args, $defaults ) {
      $_wp_query = new WP_Query();
      $_wp_query->parse_query( $args );
      relevanssi_do_query( $_wp_query );
      return $_wp_query->posts;
    }
    
    add_filter( 'flatsome_ajax_search_function', 'rlv_flatsome_search_function', 10, 4 );

    If you add this to your child theme functions.php or in a code snippet, does the ajax search then work correctly?

    Thread Starter lateralus821

    (@lateralus821)

    Hey Mikko,

    Thanks for taking the time to help out and for getting back to me so quickly, I really appreciate it.

    I tried throwing that in my functions but it didn’t work, the search still functioned the same. I tried swapping out the ‘flatsome_ajax_search_function’ for ‘flatsome_ajax_search_query’ and ‘flatsome_ajax_search_products_by_sku_search_query’ to see if either of those might work but then it just gave a continuous loading icon.

    Plugin Author Mikko Saari

    (@msaari)

    Hmm, I noticed I still have Flatsome 3.6.2 on my computer and I tried the live search there – and it just works, it uses Relevanssi without any modifications required.

    You’re probably using the latest Flatsome, so things may be different there, but at least before the Flatsome ajax search didn’t do anything particularly funny and Relevanssi should be able to work without modifications.

    I also checked the filter function, and I had it a bit wrong. You can try if this works better:

    function rlv_flatsome_search_function( $query, $args, $defaults ) {
      $_wp_query = new WP_Query();
      $_wp_query->parse_query( $args );
      relevanssi_do_query( $_wp_query );
      return $_wp_query->posts;
    }
    
    add_filter( 'flatsome_ajax_search_function', function() { return 'rlv_flatsome_search_function'; } );
    Thread Starter lateralus821

    (@lateralus821)

    Mikko,

    That worked perfectly, thank you so much for the help!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Partial searches not working’ is closed to new replies.