Copied to clipboard

Flag this post as spam?

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


  • marie 22 posts 132 karma points
    Oct 04, 2017 @ 15:25
    marie
    0

    Limiting Examine Search to one page and its sub-pages

    Examine Search is set up on a site I'm working on, but I'm not at all familiar with it or anything related to it. I just found this line of code associated with the search box on the site:

    var searchProvider = Examine.ExamineManager.Instance.SearchProviderCollection["WebsiteSearcher"];
    

    The website already has universal search hooked up and hidden. They want to make an update that allows the search function to apply to only the content/children of one page -- not one DocType, but one page and the pages related to it.

    As I said, I'm not familiar with Examine in the slightest. Is there anything in this search system that would allow me to direct it only to one specific area of the site?

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Oct 04, 2017 @ 20:07
    Marc Goodson
    100

    Hi Marie

    You have a couple of options.

    The low-tech option is to set the IndexParentId, on your IndexSet, and then only content below that parent id will be indexed in that index.

    You'll find the IndexSet defined in the ExamineIndex.config file in the /config folder

    <IndexSet SetName="ExternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/External/" IndexParentId="1234" />
    

    Would limit the index and searchable content to be only below the Parent Umbraco Node with Id 1234.

    https://our.umbraco.org/documentation/reference/Config/ExamineSettings/

    The higher tech approach is to take advantage of the fact that every published Umbraco page, as a Path property (not it's url) this is a list of the Ids of all the Parent Umbraco ids going up to the root of the site.

    If in a page template you write out Model.Content.Path you'll see the value I mean, it looks like this:

    -1,1103,1122,1123

    Where 1123 would be the Id of the page you are on -- 1122, the parent, 1103 the grandparent, up to -1 the root of all content.

    This Path property is in your examine index for all your content, so the idea is you would filter your examine search to be limited to only return results from a certain section eg lets say the section has the id 1103, by only returning those content items that had a path 'beginning with '-1,1103'.

    There is a catch though, Examine doesn't like the commas! so to make this approach work, you have to capture the 'Gathering Node' event that fires whenever examine indexes content, and add a new item to your index, called perhaps SearchablePath - which will be the existing Path item with all it's commas replaced eg:

    -1 1103 1122 1123

    this will enable you to filter items that have a 'searchable path' beginning -1 1103

    I'm trying to find a blog post that explains this approach in more details with code examples:

    This is from ages ago: http://www.attackmonkey.co.uk/blog/2011/12/limiting-an-examine-search-to-the-current-site

    which has the gathering nodes bit, but ApplicationBase isn't the place to wire up this event anymore, there is information how to wire up events here:

    https://our.umbraco.org/Documentation/Reference/Events/Application-Startup

    I can probably dig out a better example if that's what you end up needing to do, but if you just need to put IndexParentId="1234" in the IndexSet config to sort your situation, all is well!

    regards

    Marc

  • marie 22 posts 132 karma points
    Oct 06, 2017 @ 14:38
    marie
    0

    Hi Marc,

    It looks like the simple fix isn't quite working -- I'm still picking up search result content outside the specified node ID and the content below it.

    I think I'd like to give the higher tech option a try before calling it quits, so if you could find that better example while I attempt to cobble together some sort of solution, I'd be very grateful!

    Thanks for your help.

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Oct 06, 2017 @ 15:27
    Marc Goodson
    0

    Hi Marie

    ooh, forgot to say, after adding the IndexParentId to the configuration

    You would need to rebuild your index (from the developer section of Umbraco the Examine dashboard)

    But will try to knock together an example of the complicated version.

    regards

    Marc

  • Craig Mayers 164 posts 508 karma points
    Oct 06, 2017 @ 16:56
    Craig Mayers
    0

    Hi Marie,

    Like Marc says, make sure you rebuild your Examine Indexes after changing their config file.

    I tend to delete my indexes folder and then completely regenerate them using the tools in the Developer section.

    Thanks

    Craig

  • marie 22 posts 132 karma points
    Oct 09, 2017 @ 13:34
    marie
    0

    At first I thought even the index rebuild wasn't working, but I think it just took a little time to clear out old site-wide search results. Everything looks like it's on the right track now.

    Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft