Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Josip Pavlović 64 posts 249 karma points
    Jan 25, 2019 @ 18:10
    Josip Pavlović
    0

    search box error on uskinned theme

    I am using uskinned theme and i have problem with search box.

    If i enter this text in search box " Select * " (it can be any word with special character and space between, or 2 letters with 2 spaces betweeen) I am getting this error "Supplied string is null or empty" on this line of razor view:

    var terms = searchTerm.Split(' ').Select(x => x.MultipleCharacterWildcard()).ToArray();
    

    This is part of code where things going wrong:

    if (searchTerm.Contains(" "))
        {
    
            var terms = searchTerm.Split(' ').Select(x => x.MultipleCharacterWildcard()).ToArray();
            //Search limited to 4 terms: ref maxClauseCount is set to 1024
            if (terms.Length > 4)
            {
                searchError = true;
            }
            else
            {
                examineQuery.And().GroupedOr(new List<string> { "contents" }, terms);
            }
        }
        else
        {
            examineQuery.And().GroupedOr(new List<string> { "contents" }, searchTerm.MultipleCharacterWildcard());
        }
    

    I think its problem with .Split(' ') but i dont know hot to fix it.

  • David Challener 44 posts 215 karma points c-trib
    Jan 25, 2019 @ 21:35
    David Challener
    0

    Hi Josip,

    I usually do some pre-filtering of search terms to make sure the standard words that cause issues are excluded (double spaces, the word 'and' etc) in this instance perhaps you need to remove the asterisk as maybe it's making all terms wildcarded?

    It would be worth dropping uSkinned a line to see if is something with this code that they're aware of.

    The other place to check would be how the analyser is setup in examineIndex.config and examineSettings.config.

    Good luck,

    David

  • Josip Pavlović 64 posts 249 karma points
    Jan 25, 2019 @ 22:28
    Josip Pavlović
    1

    I have found solution, problem was little above in this part of the code:var regex = new System.Text.RegularExpressions.Regex(@"[^\w\s-]"); I replaced @"[^\w\s-]" with "[^a-z0-9]" and now it works great.

  • Josip Pavlović 64 posts 249 karma points
    Jan 25, 2019 @ 21:45
    Josip Pavlović
    0

    Hi David,

    Thanks for reply. I will try to make some pre-filtering like you said. I have allredy contacted uskinned yesterday but no reply yet and need it fast.

  • Marc Love 279 posts 688 karma points
    Jan 26, 2019 @ 15:07
    Marc Love
    0

    Hi Josip,

    Marc from uSkinned here. Can you confirm if the following change to the code solved your issue?

    @"[^\w\s-]" with "[^a-z0-9]"

    Kind regards,

    Marc

  • Marc Love 279 posts 688 karma points
    Jan 26, 2019 @ 17:18
    Marc Love
    101

    Hi Josip,

    Been playing about with this and the problem is that the * adds an extra space, which then is used in the split giving a null reference.

    I think this may be better:

    var regex1 = new System.Text.RegularExpressions.Regex(@"[^\w\s-]");
    var regex2 = new System.Text.RegularExpressions.Regex(@"[ ]{2,}");
    
    searchTerm = regex1.Replace(originalSearchTerm, "").Trim();
    searchTerm = regex2.Replace(searchTerm, " ");
    

    The first regex removes unsafe characters. The second regex removes multiple spaces.

    I am no expert on examine and regex however what we are trying to do is make the search query safe.

    Maybe someone else in the community has experience in this and can confirm if this code is okay.

    Cheers,

    Marc

  • Josip Pavlović 64 posts 249 karma points
    Jan 26, 2019 @ 17:55
    Josip Pavlović
    0

    Hello Marc,

    Thanks for reply.

    I have tried your solution and its better than mine, because my solution somehow skip loop for checking number of words which is limited on 4 words.

    BR

    Josip

Please Sign in or register to post replies

Write your reply to:

Draft