Copied to clipboard

Flag this post as spam?

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


  • Franz 13 posts 66 karma points
    Dec 03, 2013 @ 13:28
    Franz
    0

    Suggestion (help needed): refine search by content type

    First of all, let me say this is a great project! It has been a piece of cake to configure to our look and feel. I <3 it!

    However, I'd like to take it a step forward and I'm struggling to achieve what I want to do, mostly due to my complete inexperience in .net, let alone MVC (pretty sure cleverer people could have done it in 5 mins...).

    Anyway, here's my need. I'd like to offer our users the ability to refine the search by content type.

    Once they are on the search page, we'd like to provide a dropdown listing different content types to search against, so the returned results are only of that specific content type.

    <select name="content-type" id="site-search-select-content-type">
            <option value="all">Everything</option>
            <option value="Service">Services</option>
            <option value="Guide">Guides</option>
            <option value="Information">Information</option>
            <option value="Policy">Policies</option>
    </select> 

    It would be great if somewhere in the code we also could manipulate the values returned from the querystring. For example, we have 2 content type "guide" (GuideMultiPart and QuickGuide). So, really, when the user is selecting "Guides", the search should look at X different content types

    Something along the lines of:

    SearchType = CleanseSearchTerm(("" + Request["content-type"]).ToLower(CultureInfo.InvariantCulture));
    
    If (SearchType == "Guide"){
    //do the search only on these nodes:
    model.Parent.Guide && model.QuickGuide
    
    ...
    }

    Does it make sense? :]

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Dec 03, 2013 @ 18:05
    Matt Brailsford
    100

    Hi Franz,

    It does indeed make sense. I don't think it is something I'd look to build into ezSearch on the whole, as the idea behind ezSearch is to do simple searching well, nothing more, nothing less. That being said, I do make sure that all the source for this is available within the package so that you can make these kinds of changes yourself.

    So, lets see if we can find a solution to your problem.

    As I'm sure you know, all the logic for searching can be found within the ezSearch.cshtml partial file. What this does is actually build a raw Lucene query to run against the general content index. To do what you want to do then, we'll need to update this to take into account a specific doctype. Now, in Lucene, the doc type alias should be stored in a field called __NodeTypeAlias, with that in mind I would imagine you could do something like the following.

    In ezSearch.cshtml, around line 67 (just after we define the "query" Stringbuilder variable) add the following:

    var contentType = CleanseSearchTerm(("" + Request["content-type"]).ToLower(CultureInfo.InvariantCulture));
    if (!string.IsNullOrWhiteSpace(contentType) && contentType != "all") {
        if (contentType == "guide") {
            // "guide" is an alias that should resolve to multiple doc types
            // so handle it specifically.
            query.Append("+((__NodeTypeAlias:guidemultipart) (__NodeTypeAlias:quickguide))");
        } else {
            // for anything other than a guide document, just assume the contentType value
            // is the alias of a doc type
            query.AppendFormat("+(__NodeTypeAlias:{0})", contentType);
        }
    }
    

    (NB: This is all written freehand, so may have mistakes).

    This should should take into account any "content-type" variable passed into it, and filter the results accordingly.

    Give it a try, and let me know how you get on.

    many thanks

    Matt

  • Franz 13 posts 66 karma points
    Dec 04, 2013 @ 10:24
    Franz
    0

    Hello Matt,

    Thank you so much for your reply and your suggestion. I will play around with it and let you know. \o/

  • Franz 13 posts 66 karma points
    Dec 04, 2013 @ 10:38
    Franz
    0

    You, Sir, are a genius! It works and it does exactly what we needed to do. Grazie mille! :D

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Dec 04, 2013 @ 10:39
    Matt Brailsford
    0

    Great stuff.

    Glad I could help :)

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft