Site search can't use hyphenated keywords

Apparently Treepl’s site search doesn’t work with keywords with hyphen(s) in it. In order to get a proper search result, the user has to type the hyphenated word in separate words (which makes this workarround neccassary: Site Search with Multiple Keywords). This is not very intuitive. @vlad.z Can this be fixed?

1 Like

I hadn’t checked for hyphenated words Tim.

You can validate the search terms using js.

I have my search field in a snippet.

I added an id to the input, added an onclick to the button and a function to replace hyphens with spaces.

The hyphenated word is split and the liquid code processes the output.

<form class="search" action="/about/search-results">
    <input id="srchFld" class="form-control" type="text" name="SearchKeyword" value=""/>
    <button onclick="chkSrchFld()" class="fa fa-search" type="submit"></button>
</form>
<script>
    function chkSrchFld() {
      var inpObj = document.getElementById("srchFld").value;
      document.getElementById("srchFld").value = inpObj.split('-').join(' ');
    }
</script>

It works when search terms combine hyphnenated words with non-hyphenated words too.

1 Like

Hi @TimL and @peter.medbury
Old site search has no abilty to search by symbols. But new Advanced search is able. Just enable it in beta features and try:

1 Like

Works nicely now with the advanced search beta feature, thanks @vlad.z!

Thanks @vlad.z. I can retire some code.