Copied to clipboard

Flag this post as spam?

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


  • David Gregory 82 posts 208 karma points
    Dec 14, 2017 @ 16:45
    David Gregory
    0

    ParseException and how to ensure at least 3 characters

    Hi everyone

    I have a search on my site but if I just put a " in the search box it throws a ParseException. Any ideas how I stop that?

    Also, if I put a single character like 'a' it searches and brings back the entire site. Can I restrict the search length? Search can be seen here: http://www.ceredigion.gov.uk/resident/

    Here is the ParseException

    enter image description here

    Thanks David

  • Kevin Jump 2309 posts 14673 karma points MVP 7x c-trib
    Dec 14, 2017 @ 17:55
    Kevin Jump
    0

    Hi

    I suspect you have an old version of the ezSearch macro script ? (you error line isn't in that place on the latest script)

    I have just tested your quries on a site i have running ezSearch and they work. there are two functions.

    CleanseSearchTerm() and Tokenize() which will remove the small letter queries (so take the 'a' out)

    also, there in the current version there is a check that will not run the search if there are no terms so if you search for 'a' then a blank search shouldn't run.

    I would suggest you grab a new version of ezSearch - you (might) be able to update your script with the one from the repo (assuming none of the macro paramters have changed.

    https://github.com/umco/umbraco-ezsearch/blob/master/Src/Our.Umbraco.ezSearch/Web/UI/Views/MacroPartials/ezSearch.cshtml

    once you have the new script - you can look at changing the line

    if(!string.IsNullOrWhiteSpace(model.SearchTerm))
    

    to also check length, so search wouldn't run for less than 3 characters.

  • David Gregory 82 posts 208 karma points
    Dec 14, 2017 @ 20:26
    David Gregory
    0

    Hi Kevin

    I got the files from the project page version 1.2.

    Is that the latest copy of the code in the link you sent? I pasted that over my version but still get the error. Also, my error is on line 113 and that is the same line in the link you sent.

    Not sure I understand

    David

  • David Gregory 82 posts 208 karma points
    Dec 14, 2017 @ 20:36
    David Gregory
    0

    Sorry pasted my version over the top of my file. But now have done it correctly and pasted your version over the top but get the same error but on line 135

  • Kevin Jump 2309 posts 14673 karma points MVP 7x c-trib
    Dec 15, 2017 @ 09:49
    Kevin Jump
    0

    Hi

    that is odd, i think you might need to do some script debugging :(

    when you search for a single quote " what should happen is that it is wrapped by this line

    groupedOr.AppendFormat(@"{0}:""{1}"" ", searchField, term);
    

    So it becomes """ which looks odd but is fine.

    i would comment most of the remaining code (from line 135 to around 196) out and just write the query string to the page to see what's going on. (so just @query.ToString()

    but it is odd, I will check that the site i have this odd hasn't got some random customisation in it. but i don't think it has.

  • Steve Morgan 1345 posts 4452 karma points c-trib
    Dec 15, 2017 @ 09:55
    Steve Morgan
    0

    Hi,

    You'll need to test this but I had some issues with dodgy chars and short searches and this sort of thing and suggested some changes.

    They are sat in a pull request - might be worth a look.

    https://github.com/cheeseytoastie/ezSearch/blob/patch-2/Src/Our.Umbraco.ezSearch/Web/UI/Views/MacroPartials/ezSearch.cshtml

    HTH

    Steve

Please Sign in or register to post replies

Write your reply to:

Draft