Copied to clipboard

Flag this post as spam?

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


  • Damon 217 posts 288 karma points
    Oct 26, 2015 @ 13:17
    Damon
    0

    Restricting Examine search to just particular sections

    Hi,

    I have a main search and then I want to add landing pages that have their own search box and only search their own sub pages and folders.

    How can this be achieved? Can indexes be set up to only search certain nodes? What about is new sections are added in the future? Would a new index then have to be manually set up? An editor would not be able to do this. Can it be done programatically?

    Thanks a lot for any info!

  • Mark Bowser 273 posts 860 karma points c-trib
    Oct 30, 2015 @ 18:57
    Mark Bowser
    0

    We did something a lot like this for a site we are working on right now. We had set up a custom index and were using it for a faceted search. We needed to be able to restrict search results to the children of the page with the search on it. This is what we did:

    Below is what I added to the config/ExamineIndex.config. What is most important here is adding the parentID to the IndexAttributeFields.

    <IndexSet SetName="MyCustomIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/CustomContent/">
      <IndexAttributeFields>
        <add Name="id" />
        <add Name="nodeName" />
        <add Name="updateDate" />
        <add Name="writerName" />
        <add Name="path" />
        <add Name="nodeTypeAlias" />
        <add Name="parentID" />
      </IndexAttributeFields>
      <IndexUserFields>
        <add Name="title" />
        <add Name="subTitle" />
        <add Name="description" />
        <add Name="inactive" />
      </IndexUserFields>
      <IncludeNodeTypes>
        <add Name="SomeDocumentType"/>
      </IncludeNodeTypes>
      <ExcludeNodeTypes>
      </ExcludeNodeTypes>
    </IndexSet>
    

    When I wanted to perform my search, I add search criteria that restricts my search results to pages with a parentID that matches the id of the current page we are searching from. It might look something like this.

    // Note: I have already set containerId up as the id of the current node (the node doing the searching)
    var customSearcher = ExamineManager.Instance.SearchProviderCollection["CustomSearcher"];
    
    var searchCriteria = customSearcher.CreateSearchCriteria();
    
    var query = searchCriteria.Field("inactive", "0");
    if (containerId > 0)
    {
        query.And().Field("parentID", containerId.ToString());
    }
    
    var searchResults = customSearcher.Search(query.Compile());
    

    Hope this helps you get started. Let me know if you have any questions.

Please Sign in or register to post replies

Write your reply to:

Draft