Copied to clipboard

Flag this post as spam?

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


  • Hein 29 posts 158 karma points
    Sep 27, 2017 @ 08:43
    Hein
    0

    Get typed document from an index using Umbraco

    What I'll try

    I've got a lot of persons inside the content tree and I'll create a new index for that. This is for improve the performance of the web application when searching for a specific person.


    Create the index

    I've made a new index in the examine manager from Umbraco 7.7 named PersonIndexer to index all the persons. This includes only the node types of a person.

    Examine Manager from Umbraco

    For this I've made this code:

    ExamineSettings.config

    Inside the file ExamineSettings.config inside the ExamineExamineIndexProvidersproviders tag:

    <add name="PersonsIndexer" 
         type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine" 
         supportUnpublished="false"
         supportProtected="true" 
         indexSet="Persons"
         analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/>
    

    And inside the same file I've also added this but inside the ExamineExamineSearchProvidersproviders tag:

    <add name="PersonsSearcher" 
         type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" 
         supportUnpublished="false"
         supportProtected="true" 
         indexSet="Persons"
         analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/>
    

    ExamineIndex.config

    Inside the file ExamineIndex.config inside the ExamineLuceneIndexSets tag:

    <IndexSet SetName="Persons" IndexPath="~/App_Data/TEMP/ExamineIndexes/Persons/" >
        <IndexAttributeFields>
            <add Name="knowledge" />
            <add Name="photo" />
            <add Name="name"/>
            <add Name="firstName"/>
            <add Name="lastName"/>
        </IndexAttributeFields>
    
        <IncludeNodeTypes>
            <add Name="person" />
        </IncludeNodeTypes>
    </IndexSet>
    

    Get the documents

    When I build this index, it got 7 documents inside the index.

    After building the index

    How can I get all this documents inside my view. I've tried this code:

    var indexer = ExamineManager.Instance.IndexProviderCollection["PersonsIndexer"];
    

    This gives me all properties of that index.

    Quick watch of the indexer variable


    The question

    This isn't what I need. So my question is: How could I get the typed documents from that index?

    P.S.: Click on images for original size

  • Hein 29 posts 158 karma points
    Sep 27, 2017 @ 11:50
    Hein
    100

    Found it. I'm using this code now:

    var searcher = ExamineManager.Instance.SearchProviderCollection["PersonsSearcher"];
    var searchCriteria = searcher.CreateSearchCriteria();
    var query = searchCriteria.Field("nodeTypeAlias", "person").Compile();
    var searchResults = searcher.Search(query);
    

    and edited the IndesSet to this:

    <IndexAttributeFields>
      <add Name="id" />
      <add Name="nodeName" />
      <add Name="nodeTypeAlias"/>
      <add Name="updateDate"/>
    </IndexAttributeFields>
    <IndexUserFields>
      <add Name="knowledge" />
      <add Name="photo" />
      <add Name="name"/>
      <add Name="firstName"/>
      <add Name="lastName"/>
    </IndexUserFields>
    <IncludeNodeTypes>
      <add Name="person" />
    </IncludeNodeTypes>
    

  • Hein 29 posts 158 karma points
    Sep 27, 2017 @ 12:03
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies