Copied to clipboard

Flag this post as spam?

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


  • Duncan Sawyer 4 posts 25 karma points
    Jul 20, 2015 @ 18:31
    Duncan Sawyer
    1

    EzSearch Project

    Currently I'm working on setting up a private site for customers to access Reference Manuals for our products.

    This is a Reference

    So say I'm in Sub Page 1 under Parent Node 1 and I want to search for a definition that I know is in Page 3 of Parent node 1. I want a search function using EzSearch (if possible) that dynamically limits the search to the specific parent node that I'm within.

    If someone could let me know if this is possible or knows how to do it that would be fantastic. In the mean time if I can come up with an answer before someone else I will post it in here.

  • Kevin Jump 1430 posts 9166 karma points MVP 3x c-trib
    Jul 21, 2015 @ 06:49
    Kevin Jump
    1

    Hi,

    In ezSearch you can pass the root node for your search as a parameter to the macro.

    I have a project where the search page is placed beneath the page you want to search from. the macro looks like this.

    @Umbraco.RenderMacro("ezSearch", new
     {
       RootContentNodeId = Model.Content.Parent.Id,
       IndexType = "CONTENT",
       searchFormLocation = "Top",
       pageSize = 5
     })
    

    If you want to go upto a certain type of page (so if you parent pages have a specifc doctype). then you could get that by calling

    var parent = Model.AncestorsOrSelf("name-of-doctype").Last()

    this will get you the nearest parent of the doctype. (see https://our.umbraco.org/forum/developers/razor/28410-AncestorOrSelf-by-document-type)

  • Tony Groome 261 posts 803 karma points
    Sep 18, 2015 @ 11:02
    Tony Groome
    0

    Hi

    I'm using ezsearch for a phonebook type search. Each person is stored as a page of doctype branchStaff. This is (I think level 3 nodes) created under a branch which is under Homepage. Is there a way I can force ezsearch to only search this level of node or else to only search by doctype?

    Thanks. Tony

  • Kevin Jump 1430 posts 9166 karma points MVP 3x c-trib
    Sep 18, 2015 @ 11:15
    Kevin Jump
    1

    Hi,

    you can specify the rootNode that you want ezSearch to start from, as in the post above.

    Out of the box ezSearch doesn't limit searches by DocType.

    I have added this code in a project recently to do this. chaning the ezSearch.cshtml

    i added this to the search model.

    var model = new SearchViewModel
    {
       ... (existing bits) ...
       NodesToSearch = GetMacroParam(Model, "nodesToSearch", s => SplitToList(s), new List<string> {}),
    }
    

    i then added this in the main section that builds the search query (just above // Ensure page contains all search terms in some way)

    if ( model.NodesToSearch.Any() )
    {
        foreach(var doctype in model.NodesToSearch)
        {
            query.AppendFormat("+nodeTypeAlias:({0}) ", doctype );
        }
    }
    

    you can just add nodesToSearch = "doctypea,doctypeb" to the macro.

    I did a similar thing for NodesToExclude so you could do it the other way around. I haven't gotten around to submitting a Pull request for ezSearch yet

  • Tony Groome 261 posts 803 karma points
    Sep 18, 2015 @ 13:17
    Tony Groome
    0

    Hi Kevin

    I'm obviously missing something here, I added

    NodesToSearch = GetMacroParam(Model, "nodesToSearch", s => SplitToList(s), new List

    to the SearchViewModel, and the block of code to just above //Ensure page contains all search terms in some way.

    Where does nodesToSearch = "branchStaff" go? branchStaff is my Document Type that I want to search.

    Thanks. :)

  • Kevin Jump 1430 posts 9166 karma points MVP 3x c-trib
    Sep 18, 2015 @ 13:20
    Kevin Jump
    1

    HI,

    yes i might have missed something too : (

    You also need to add the parameter to the ezSearch macro (in macros section, click on the properties tab of the ezSearch Macro and add the NodesToSearch paramater), If you don't do this the parameter can be set but it never reaches the code.

    Then you can add NodesToSearch to the the place you call ezSearch from (probibly you're template?) something like.

    @Umbraco.RenderMacro("ezSearch", new { IndexType = "CONTENT", searchFormLocation = "Top", pageSize = 5, nodesToSearch="nodename" })

  • Tony Groome 261 posts 803 karma points
    Sep 18, 2015 @ 14:08
    Tony Groome
    1

    Hi Kevin

    I think I must be having a blonde day! enter image description here

    enter image description here

    And then I added the

    @Umbraco.RenderMacro("ezSearch", new { IndexType = "CONTENT", searchFormLocation = "Top", pageSize = 5, nodesToSearch="branchStaff" })

    to the template and if fails to load.

    Thanks. Tony

  • Kevin Jump 1430 posts 9166 karma points MVP 3x c-trib
    Sep 18, 2015 @ 14:14
    Kevin Jump
    1

    don't worry it's nearly beer o'clock.

    I would say the property should be textbox not content picker - as you are just passing a string.

    that might be it.

  • Tony Groome 261 posts 803 karma points
    Sep 18, 2015 @ 14:18
    Tony Groome
    0

    Exactly - beer o clock. :) WooHoo!!

    That didn't work so I'm going to revert to beer o clock and leave it till Monday....

    Thanks :)

  • Sam Pearson 36 posts 89 karma points
    Jan 25, 2017 @ 11:17
    Sam Pearson
    0

    To anybody coming across this thread now, I used Kevin Jump's solution for limiting the search to document types, but found that if implemented as stated above, the search would only work on single document types. If multiple doctypes were entered, no results would be returned.

    Kevin's solution will only work on multiple document types if the appended query string is written like this:

        @* ADDED to limit searches to specified doctypes *@ 
        if (model.NodesToSearch.Any())
        {   
            var groupedOr = new StringBuilder();
    
            foreach(var doctype in model.NodesToSearch)
            {
                groupedOr.AppendFormat("{0}* ", doctype);
            }
    
            query.Append("+nodeTypeAlias:(" + groupedOr.ToString() + ") ");
        }
    

    Also, Tony - I know you have probably solved this a long time ago, but for the benefit of others; your attempt here was not working because you named a parameter 'branchStaff' when it should have been named 'doctype', as per the variable name inside the scope of the foreach.

Please Sign in or register to post replies

Write your reply to:

Draft