Copied to clipboard

Flag this post as spam?

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


  • Abdul Raheem 17 posts 61 karma points
    Dec 19, 2014 @ 12:26
    Abdul Raheem
    0

    how to integrate ublogsy search with site search

    Hi, I have Implemented site search in Umbraco 7 using examine.

    Now i need to add blog data to be visible in the search, I have used Ublogsy for implmnetation of blod.

    Here is the code what I am trying to do to add blog data in seearch

    Examine code:

          <IndexAttributeFields>
          <add Name="id" />
          <add Name="nodeName"/>
          <add Name="updateDate" />
            <add Name="writerName" />
          <add Name="path" />
          <add Name="nodeTypeAlias" />
          <add Name="umbracoNaviHide" />
           <add Name="parentID" />
    
        </IndexAttributeFields>
        <IndexUserFields>
         <add Name="bodyText" />
        <add Name="uBlogsyContentBody" />
        <add Name="uBlogsyContentTitle" />
        <add Name="uBlogsyContentSummary" />
        </IndexUserFields>
        <ExcludeNodeTypes>
          <add Name="Folder" />
        </ExcludeNodeTypes>
       

    Search code:

     

    @inherits Umbraco.Web.Macros.PartialViewMacroPage @using Examine.LuceneEngine.SearchCriteria @{ var searchTerm = Request.QueryString["s"]; if (String.IsNullOrWhiteSpace(searchTerm)) { searchTerm = ""; } var searcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"]; var searchCriteria = searcher.CreateSearchCriteria(UmbracoExamine.IndexTypes.Content); Examine.SearchCriteria.IBooleanOperation filter = null; var searchKeywords = searchTerm.Split(' '); int i = 0; for (i = 0; i < searchKeywords.Length; i++) { if (filter == null) { filter = searchCriteria.GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags", "uBlogsyContentTitle", "uBlogsyContentSummary", "uBlogsyContentBody" }, searchKeywords[i]); } else { filter = filter.Or().GroupedOr(new string[] { "nodeName", "bodyText", "browserTitle", "tags", "mediaTags", "uBlogsyContentTitle", "uBlogsyContentSummary", "uBlogsyContentBody" }, searchKeywords[i]); } } var searchResults = searcher.Search(searchCriteria).Where(r => r["__IndexType"] == "content").ToList(); if (searchResults.Any()) { int total = 0; @*

    *@ foreach (var result in searchResults) { if (result.Fields.ContainsKey("bodyText") && Umbraco.Field("umbracoNaviHide").ToString() == "True" || result.Fields.ContainsKey("uBlogsyContentBody")) { string bodyText = result["bodyText"]; //string blogTitle = result["uBlogsyContentTitle"]; //string blogSummary = result["uBlogsyContentSummary"]; string blogContent = result.Fields["uBlogsyContentBody"]; if (bodyText.Trim().Length >0 || blogContent.Trim().Length > 0) { total = total + 1; } } } @**@

    Your search for @searchTerm returned @total.ToString() result(s)

      @foreach (var result in searchResults) { if (result.Fields.ContainsKey("bodyText")) { string bodyText = result["bodyText"]; if ((string.IsNullOrEmpty(bodyText)) || bodyText.Trim().Length < 1) { continue; } } else { continue; } var node = Umbraco.TypedContent(result.Id); var pathIds = result["__Path"].Split(','); var path = Umbraco.TypedContent(pathIds).Where(p => p != null).Select(p => new { p.Name }).ToList();
    • @node.Name

      xyz.com@node.Url

      @if (result.Fields.ContainsKey("title") || result.Fields.ContainsKey("uBlogsyContentTitle")) {

      @result["title"]

      } @if (result.Fields.ContainsKey("bodyText") || result.Fields.ContainsKey("uBlogsyContentSummary") || result.Fields.ContainsKey("uBlogsyContentBody")) {

      @result["bodyText"].Truncate(250)

      }
    • }
    } else {

    There are no results matching your search criteria: @if (!String.IsNullOrWhiteSpace(searchTerm)) { '@searchTerm' }

    } }

     

     

    I get error string blogContent = result.Fields["uBlogsyContentBody"]; doesnot contains key.

    Please hel and guide where I am doing it wrong

    Thanks

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Dec 26, 2014 @ 16:28
    Alex Skrypnyk
    0

    Hi Abdul,

    It looks like you used wrong indexSet. Try to use

    <!-- Default Indexset for external searches, this indexes all fields on all types of nodes-->
    <IndexSet SetName="ExternalIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/External/" >
    <IndexAttributeFields>
    <add Name="uBlogsyContentBody" />
        <add Name="uBlogsyContentTitle" />
        <add Name="uBlogsyContentSummary" />
    </IndexAttributeFields>
    </IndexSet>
    
  • Abdul Raheem 17 posts 61 karma points
    Dec 29, 2014 @ 09:45
    Abdul Raheem
    0

    Hi Alex,

    Thanks for your reply.

    I tried this but it doesnot work.

    Now  I am able to get ublogsy data in search, but there is another issue.

    If I add a new post, it doesnot create its index automatically and also not after rebuilding indexes.

    I always have to delete the old indexes to feth the new blog data into the search, Can you help me in that, I have pasted my indexconfig

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

        <IndexAttributeFields>

          <add Name="id" />

          <add Name="nodeName"/>

          <add Name="nodeTypeAlias" />

          <add Name="umbracoNaviHide" />

          <add Name="parentID" />

          <add Name="updateDate" />

          <add Name="writerName" />

          <add Name="uBlogsyPost" />   

        </IndexAttributeFields>

        <IndexUserFields> 

          <add Name="bodyText"/> 

        <add Name="uBlogsyContentBody" />

          <add Name="uBlogsyContentSummary" />

        </IndexUserFields>

        <IncludeNodeTypes>

        </IncludeNodeTypes>

        <ExcludeNodeTypes>

          <add Name="Folder" />

        </ExcludeNodeTypes>

      </IndexSet>

       

         

         

         

         

         

         

         

           

       

        

          

       

         

       

       

       

       

         

       

     

Please Sign in or register to post replies

Write your reply to:

Draft