Searching for a product even if code is misspelled
<p>Okay guys, I am at a stump here.</p>

<p>Basically the problem I have is that when people are searching for something they are mistyping the code as a lot of the time they involved multiple 0's, for example when searching for: <code>K00000WEFLZ</code> they are mistyping the 0's and then the product result is returning with nothing, I am basically looking to try and make it so that the search checks if the search contains a certain amount of 0's after the letter "K" (as K will always have say 10+ ID numbers and at least 4-5 0's) and if it does it replaces it with "*" during the searching operation and still allows you to find the product no matter how wrong they type the problem.</p>

<p>I am aware I will have to make a custom class and override the default for this (however a lot of this can not be accessed/is private) as the default search pattern can not be changed as this will change it for everyone and I only want it for this specific site.</p>

<p>I also can not use a wildcard at the start or the ending of this as it would match miles to many results as it has a huge catalog.</p>

<p>As far as I know this is the code that handles the search with the class for the default logic:</p>

<pre><code>protected virtual IList&lt;Product&gt; CreateCustomCollection()
{
        var list = new List&lt;Product&gt;();

        switch (mode)
        {
            case ProductRepeaterMode.Search:

                if (Page.Request.QueryString["search"] != null &amp;&amp; Page.Request.QueryString["search"].Length != 0)
                {
                    bool[] customString = new bool[5] { SearchCustomString1, SearchCustomString2, SearchCustomString3, SearchCustomString4, SearchCustomString5 };
                    IList&lt;Product&gt; results = Fabric.ObjectProvider.Get&lt;IProductSearchCommand&gt;().Search(Page.Request.QueryString["search"], out searchWords, IncludeSkus, IsPublicFacing, customString, CoreHttpModule.Session);

                    var retailOrder = WebStoreManager.CurrentOrder as IRetailOrder;
                    var accountOrder = WebStoreManager.CurrentOrder as IAccountOrder;

                    IList&lt;Product&gt; productsToRemove = new List&lt;Product&gt;();
                    IList&lt;Product&gt; productsToAdd = new List&lt;Product&gt;();

                    foreach (var product in results)
                    {
                        if (hideRestrictedProducts)
                        {
                            if (retailOrder != null)
                            {
                                if (!product.CanBePurchasedByRetailCustomer || product.AgentOnly)
                                    productsToRemove.Add(product);
                            }
                            else
                            {
                                if (accountOrder != null)
                                {
                                    var add = false;

                                    if (product.CanBePurchasedOnAccount)
                                        add = true;

                                    if (product.AgentOnly)
                                    {
                                        if (accountOrder.Agent != null)
                                            add = true;
                                        else
                                            add = false;
                                    }

                                    if (!add)
                                        productsToRemove.Add(product);
                                }
                            }
                        }

                        // Replace SKUs with lines
                        if (resolveSkusToLines)
                        {
                            var sku = product.Role as SkuProductRole;
                            if (sku != null)
                            {
                                productsToRemove.Add(product);
                                if (sku.Owner != null &amp;&amp; sku.Owner.Product != null)
                                {
                                    var line = sku.Owner.Product;
                                    if (!results.Contains(line) &amp;&amp; !productsToAdd.Contains(line))
                                        productsToAdd.Add(line);
                                }
                            }
                        }
                    }

                    foreach (Product product in productsToAdd)
                    {
                        results.Add(product);
                    }

                    foreach (Product product in productsToRemove)
                    {
                        results.Remove(product);
                    }

                    foreach (var result in results)
                        list.Add(result);
                }
                break;
        }
        return list;
    }
</code></pre>
