Stripping Special Characters from Simple Search

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
RichWendrock
Commander (CMDR)
Commander (CMDR)
Posts: 134
Joined: Sat Apr 05, 2008 12:55 am
Location: Austin Texas
Contact:

Stripping Special Characters from Simple Search

Post by RichWendrock » Thu Aug 15, 2013 5:36 pm

For a long time we have had a problem with no search results being displayed when the visitor enters a " or / in the search field. We use the simple search in the left column. Here is the code for the modifications I made to strip all special characters from the search keyword.

The original code in the file SearchPage.asc.cs looks like this

_Keywords = StringHelper.StripHtml(Request.QueryString["k"]);
if (Store.GetCachedSettings().FullTextSearch) _FilteredKeywords = new StopWordsParser().Filter(_Keywords);
else _FilteredKeywords = _Keywords;

I modified the code to look like this.

_Keywords = StringHelper.StripHtml(Request.QueryString["k"]);
string cleanSearchPhrase ="";
for (int i = 0; i < _Keywords.Length; i++)
{
if (_Keywords >= '0' && _Keywords <= '9' || _Keywords >= 'A' && _Keywords <= 'Z' || _Keywords >= 'a' && _Keywords <= 'z')
{
cleanSearchPhrase=cleanSearchPhrase+_Keywords;
}
else
{
cleanSearchPhrase=cleanSearchPhrase+" ";
}
}
_Keywords=cleanSearchPhrase;
if (Store.GetCachedSettings().FullTextSearch) _FilteredKeywords = new StopWordsParser().Filter(_Keywords);
else _FilteredKeywords = _Keywords;

That code will take a search phrase that looks like this.
1 1/4" handlebars w/ 1 1/4" dia. clamping area
and change it to look like this.
1 1 4 handlebars w 1 1 4 dia clamping area

Search results match the products that have the keywords handlebars and clamping area. Which are the products the visitor wants to see.

There are two files named
SimpleSearch.aspx and SimpleSearch.aspx.cs
I wasted a lot of time trying to make this work using the button click routines. It appears those two modules do not get control when the search button is clicked.
Regards,
Richard

http://www.TheHomePageStore.com

AbleCommerce
VERSION: 7.0.7.14588
MSSQL v2005
AC SCHEMA v2005
.NET CLR v2.0.50727.3634

Post Reply