Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    Apr 21, 2015 @ 12:30
    Craig O'Mahony
    0

    Using Custom Examine Index

    Hi Folks,

    I've set up a custom examine index/profile (following parrot fashion instructions found elsewhere on this site) and what I'd like to do is search for content using only this profile and not the 'standard' one that's already in the config files.

    Here's what I've created in the ExamineIndex file

      <!-- Default Indexset for external searches, this indexes all fields on all types of nodes-->
      <IndexSet SetName="ExternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/External/" />
      
      
      <!-- Search criteria for the courses-->
      <IndexSet SetName="CourseSearch" IndexPath="~/App_Data/TEMP/ExamineIndexes/CourseSearch">
        <IndexAttributeFields>
          <!--The below aren't really needed but included for completeness-->
          <add Name="id" />
          <add Name="nodeName"/>
          <add Name="updateDate" />
          <add Name="writerName" />
          <add Name="nodeTypeAlias" />
        </IndexAttributeFields>
        
        <!--Custom fields that have been created and that we wish to search on-->
        <IndexUserFields>
          <add Name="courseDescription"/>
          <add Name="courseTitle"/>
        </IndexUserFields>
        
        <!--The type of content that is being searched. In this case just the Courses-->
        <IncludeNodeTypes>
          <add Name="Course"/>
        </IncludeNodeTypes>
      </IndexSet>
      
      <!--End of search -->

    This is my ExamineSetting file

      <ExamineIndexProviders>
        <providers>
          <add name="InternalIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
               supportUnpublished="true"
               supportProtected="true"
               analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/>
          <add name="InternalMemberIndexer" type="UmbracoExamine.UmbracoMemberIndexer, UmbracoExamine"
               supportUnpublished="true"
               supportProtected="true"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"/>
            <!-- default external indexer, which excludes protected and unpublished pages-->
            <add name="ExternalIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"/>
          <!--Search indexer for the courses search-->
          <add name="CourseIndexer" type="UmbracoExamine.UmbracoContentIndexer, UmbracoExamine"
               supportUnpublished="false"
               supportProtected="true"
               interval="10"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net"
               indexSet="CourseSearch"/>
          <!--End of search indexer for the courses search-->
          
          
        </providers>
      </ExamineIndexProviders>
      <ExamineSearchProviders defaultProvider="ExternalSearcher">
        <providers>
          <add name="InternalSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
               analyzer="Lucene.Net.Analysis.WhitespaceAnalyzer, Lucene.Net"/>
            
          <add name="ExternalSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine" />
          
          <add name="InternalMemberSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" enableLeadingWildcard="true"/>
          
          <!--Search Provider for the courses search-->
          <add name="CourseSearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" indexSet="CourseSearch" enableLeadingWildcard="true"/>
          
        </providers>
      </ExamineSearchProviders>

    and this is how I'm calling the search in my controller but this is using both indexes I believe (certainly the ExternalIndexSet as I can seeing it's including all node types.

                var zString = "";
                if (!string.IsNullOrEmpty(zST))
                {
                    foreach (var result in Umbraco.TypedSearch(zST))
                    {
                        zString += result.Name + ", ";
                    }
                }

    Could someone point me in the right direction please?

    Thanks in advance,

    Craig

  • Richard Terris 273 posts 715 karma points
    Apr 21, 2015 @ 12:37
    Richard Terris
    0

    Hi Craig,

    This post should have everything you need to get this wired up quite quickly.

    http://24days.in/umbraco/2013/getting-started-with-examine/

  • Craig O'Mahony 364 posts 918 karma points
    Apr 21, 2015 @ 12:54
    Craig O'Mahony
    0

    Hi Richard,

    That's exactly the post I read to create the profile/index but the actual razor snippet that he's put in there (which is great) doesn't appear to do multi word searching, etc. that the Umbraco.TypedSearch seems to which is what really triggered my question.

    Thanks,

  • Richard Terris 273 posts 715 karma points
    Apr 21, 2015 @ 13:48
    Richard Terris
    0

    Does this work:

      ISearchCriteria searchCriteria = ExamineManager.Instance.CreateSearchCriteria(BooleanOperation.And); 
    searchCriteria = searchCriteria.GroupedOr(new[] {"allFields"}, requestObject.Keywords.Replace(',', ' ').Split(' ')).Compile();
        List<IPublishedContent> resultsList = new UmbracoHelper(UmbracoContext.Current).TypedSearch(searchCriteria, ExamineSearcher).ToList();
    

    This is based on passing an object from a webapi controller which I've named 'requestObject' which has a property called 'Keywords' which is just a comma-separated list of keywords.

  • Craig O'Mahony 364 posts 918 karma points
    Apr 21, 2015 @ 14:15
    Craig O'Mahony
    0

    Hi Richard,

    I'm not getting any errors but sadly no results!

    I had to amend your code slightly to this:

                ISearchCriteria searchCriteria = Examine.ExamineManager.Instance.CreateSearchCriteria(BooleanOperation.And);

                searchCriteria = searchCriteria.GroupedOr(new[] { "allFields" }, zST.Replace(',', ' ').Split(' ')).Compile();

                List<IPublishedContent> resultsList = new UmbracoHelper(UmbracoContext.Current).TypedSearch(searchCriteria, Examine.ExamineManager.Instance.SearchProviderCollection["CourseSearcher"]).ToList();

    Where zST is my string eg. "Trust,Management"

  • Richard Terris 273 posts 715 karma points
    Apr 21, 2015 @ 14:26
    Richard Terris
    0

    Yeah I'd expect you to change the variable names but if the code works and you're not getting results I think the issue now is either with the index setup, is it configured properly? Have you checked that you have items in the index? And have you checked to make sure you're using the correct search provider?

  • Craig O'Mahony 364 posts 918 karma points
    Apr 21, 2015 @ 15:00
    Craig O'Mahony
    0

    Hi Richard,

    Everything seems to be configured correctly. I've got items in the index and all that jazz.....

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Apr 21, 2015 @ 15:26
    Ismail Mayat
    0

    Craig,

    If you want to search only in course index you need to do

    ExamineManager.Instance.SearchProviderCollection["CourseSearcher"].CreateSearchCriteria(BooleanOperation.And);

    your code currently defaults to external searcher.

    Regards

    Ismail

Please Sign in or register to post replies

Write your reply to:

Draft