• Resolved thewhirl

    (@thewhirl)


    Is there a way to include special characters for searching as part of the product name, short description, etc.?

    For example I have products where the titles and short descriptions contain dots and forward slashes like 55/10/20 but if I search for products based on description and type a forward slash in the search bar like 55/10 the keyword highlighting disappears so I don’t think the forward slash is included in the searching

    • This topic was modified 3 years, 3 months ago by thewhirl.
Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter thewhirl

    (@thewhirl)

    Edited search description

    Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    Yes, by default plugin removes all such special chars from the search query. But you can change this. Please use following code snippet:

    add_filter( 'aws_special_chars', 'my_aws_special_chars' );
        function my_aws_special_chars( $chars ) {
            unset( $chars[array_search( '/',$chars )] );
            unset( $chars[array_search( '/',$chars )] );
            return $chars;
        }

    You need to add it somewhere outside the plugins folder. For example, inside functions.php file of your theme or use some plugin for adding code snippets.
    Also, after adding this code, you need to re-index the plugin table.

    Regards

    Thread Starter thewhirl

    (@thewhirl)

    Hi,

    Thanks for that. I did as you suggested and it works for the dot character but not for the forward slash character. Where there are several products with titles and descriptions containing something like 55/10 and 55/20, when I type something like 55/ all the product titles turn to null and the short descriptions just get completely removed.

    Plugin Author ILLID

    (@mihail-barinov)

    Did you re-index after adding this code?

    Thread Starter thewhirl

    (@thewhirl)

    Yeah I did

    Plugin Author ILLID

    (@mihail-barinov)

    Please try to modify code above to

    add_filter( 'aws_special_chars', 'my_aws_special_chars' );
        function my_aws_special_chars( $chars ) {
            unset( $chars[array_search( '/',$chars )] );
            unset( $chars[array_search( '& #47;',$chars )] );
            return $chars;
        }

    Remove space inside & #47;

    Thread Starter thewhirl

    (@thewhirl)

    Still getting the same result. I tried it without removing the ‘/’ too and only removing the ‘& #47;’ without the space. When I only remove the ‘& #47;’ there’s no change to anything, just when I remove ‘/’ I get the null results. Also re-indexing table with every adjustment to the code.

    I tested further and it seems the search functionality works fine so if I type something like 55/10 appropriate results will show up but as soon as the ‘/’ is typed into the search bar all search highlighting disappears. Removing the dot ‘.’ has worked though and where the search highlighting disappeared before similar to the ‘/’ it now appears.

    Also if it helps, when I remove the ‘/’ character and get the null results in the search bar, if I press enter to go to the search results anyways an error message appears on the search results page:
    Warning: preg_replace(): Unknown modifier ‘)’ in /…../public_html/wp-content/plugins/advanced-woo-search/includes/class-aws-search.php on line 791

    Plugin Author ILLID

    (@mihail-barinov)

    Yes, you are right. I see the same error now.

    And looks like I understand why this happens. You can fix this issue in two ways:

    1. Disable ‘Highlight words’ option from the plugin settings page.

    2. Edit plugin source code. I will add the same changes to the next plugin release, so don’t worry about the updates.

    So please open advanced-woo-search/includes/class-aws-search.php file, find lines

    foreach( $this->data['search_terms'] as $search_in ) {

    and replace with

      foreach( $this->data['search_terms'] as $search_in ) {
    
                    $search_in = str_replace( '/', '\/', $search_in );
    Thread Starter thewhirl

    (@thewhirl)

    Awesome, works perfectly now. Thanks for the fix!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Products with special characters’ is closed to new replies.