• AJ

    (@ajisimplifymecom)


    I would like to alter the front end search so that the search recognizes that searching with or without a dash should be synonymous.
    For example, searching for eco5 or eco-5 should return a result of eco5, or a search for bam-8000 or bam8000 should return bam-8000.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,

    You need to change your search query, the most easy way that it won’t work for all cases it is replace – to % in the term, the best way to do it, it is first replace the – for % and after that, separate all the chars from numbers, make a new string like:
    $newTerm = $chars .’%’.$numbers;

    Changing this you will get the right results

    Thread Starter AJ

    (@ajisimplifymecom)

    Can you offer a little more guidance as to where to do this? separating the letters and numbers seems like more work than needed. What I’d like to do is remove dashes from the query and remove/ignore dashes from the content being searched (such as the title) when performing the search…

    Then if you only need to remove the slashes it is more easy:

    $newSearch = str_replace(‘-‘, ”, $term)

    on $term it is your initial search like eco-5 or eco5

    regards

    Thread Starter AJ

    (@ajisimplifymecom)

    I’m sorry. Where/how do I implement this? I would like to do something where the search query is altered like this… FIND str_replace(‘-‘,”,$term) IN str_replace(‘-‘,”,$search_data), so it removes the dashes not only in the term, but from the searchable data as well.

    In php code in your plugin..
    After the user adds in the search box eco-5 and click the button search
    You will get this data in the server side, then you will take the data in php code, if you are using the get method, you will do:

    $term = $_GET[‘your_search_field_name’];

    $newSearch = str_replace(‘-‘,”,$term) IN str_replace(‘-‘,”,$search_data);

    and you will add the $newSearch to your query that will look into the database for the results.

    regards

    Thread Starter AJ

    (@ajisimplifymecom)

    ok, i know youre trying to help me, but youre being very vague. the entire site is PHP, where/how do i hook into the search to hijack the query and edit it?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Alter front end search to include or ignore dashes’ is closed to new replies.