Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Does anyone know how to cleanse a search term so that special characters like colons (:), etc. do not break a site search?
I have:
// Cleanse the search term public string CleanseSearchTerm(string input) { return Umbraco.StripHtml(input).ToString(); }
Thanks.
Hi Bobi.
So you want the search to only be able to search for letters or digits? There is probably 100 ways of solving this, but one way is with Regex.
// Cleanse the search term public string CleanseSearchTerm(string input) { System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9 -]"); input = rgx.Replace(input, ""); return input.ToString(); }
This method would transform this string:
H|jbfsj08 s989w&/#&%#ยค802 95+43223gf:;:`!
Into:
Hjbfsj08 s989w802 9543223gf
Best of luck!
You're welcome! Glad to help!
Have a great day Bobi!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Cleansing search term for lucene so it doesn't break
Does anyone know how to cleanse a search term so that special characters like colons (:), etc. do not break a site search?
I have:
Thanks.
Hi Bobi.
So you want the search to only be able to search for letters or digits? There is probably 100 ways of solving this, but one way is with Regex.
This method would transform this string:
Into:
Best of luck!
Thanks.
You're welcome! Glad to help!
Have a great day Bobi!
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion