+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Sitefinity 6.1: Creating a search index for a specific blog

Sitefinity 6.1: Creating a search index for a specific blog

7 posts, 2 answered
  1. Nicholas
    Nicholas avatar
    9 posts
    Registered:
    30 Jun 2013
    01 Dec 2013
    Link to this post
    In Sitefinity 6.1, I'm trying to create a search index that will allow you to search one blog only. I found the following examples for Sitefinity 4, but they don't work when I apply them:

    http://www.apteradesign.com/Blog/Post/11-12-15/Sitefinity_4_Tips_2nd_Edition.aspx
    http://www.sitefinity.com/blogs/teodorgeorgiev/posts/team-blog/2011/09/07/adding_a_new_content_type_to_search

    Here is an excerpt from my current Global.asax.cs:

    //Add a search index for My Blog
    var blog = App.WorkWith().Blogs().Where(b => b.Title.ToString() == "My Blog").Get().SingleOrDefault();
    if (blog != null)
    {
        var pipeSettings = (SitefinityContentPipeSettings)PublishingSystemFactory.GetPipeSettings(ContentInboundPipe.PipeName);
        pipeSettings.ContentTypeName = typeof(Telerik.Sitefinity.Blogs.Model.BlogPost).FullName;
        pipeSettings.ContentLinks = new Guid[] { blog.Id };
        pipeSettings.UIName = "My Blog Posts";
        pipeSettings.MaxItems = 0;
        PublishingSystemFactory.RegisterTemplatePipe("SearchItemTemplate", pipeSettings);
    }


    This is running on the Bootstrapper.Initialized event, and I could see with the debugger that I'm getting the blog.Id correctly. However, when I go to create a search index in the backend, nothing new appears. What's missing?
    Answered
  2. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    04 Dec 2013
    Link to this post
    Hi,

    You are trying to register new template pipe, rather than just modifying the existing one.
    Just create a regular search index for blogs and then use the code below to modify it to search only in one blog.
    var manager = PublishingManager.GetManager();
                    var publishingPoint = manager.GetPublishingPoints().Where(pp => pp.Name == "BlogsSearchIndex").First();
                    var pipeSettings = publishingPoint.GetInboundPipes().First(); // If you have more than one, just filter it. If only "blogs" are selected - you should have only one inbound pipe setting.
                    ((SitefinityContentPipeSettings)pipeSettings).ContentLinks = new Guid[] { blog.Id };
                    manager.SaveChanges();

    If you will create multiple indexes like this, you can create some control that will execute this code for given blog and search index.
    Please don't hesitate to contact me again if you need further assistance.

    Regards,
    Bonny
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Nicholas
    Nicholas avatar
    9 posts
    Registered:
    30 Jun 2013
    04 Dec 2013
    Link to this post
    Bonny,

    I tried your code and had a couple problems:

    First, it wasn't finding the index unless I changed the first line to
    var manager = PublishingManager.GetManager("SearchPublishingProvider");


    Now that it's finding the search index, though,  when execution gets to the third line I get the error `No pipe registered with name 'DocumentSearchInboundPipe'`. I tried filtering, but without success. I get the same error even if I change it to
    publishingPoint.GetInboundPipes().Where(ip => ip.Name != "DocumentSearchInboundPipe").First();


    Do you have any ideas what to do next? Anyway, thanks a lot for your help!

    Nick
    Answered
  4. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    05 Dec 2013
    Link to this post
    Hello,

    First - I am sorry about the provider problem - my bad. About the second problem, I think it is happening, because the publishing system is not initialized yet. Are you doing this OnAplicationStart, or after that? It will be much better to create an aspx page and in it on button click for example to execute this code. This way the system will be fully functional when the code is executed.
    Please contact me again if you can't resolve this problem.

    Regards,
    Bonny
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Nicholas
    Nicholas avatar
    9 posts
    Registered:
    30 Jun 2013
    05 Dec 2013 in reply to Bonny
    Link to this post
    It was running in the Bootstrapper_Initialized delegate:
    //Global.asax.cs
    protected void Application_Start(object sender, EventArgs e)
    {
        Bootstrapper.Initialized += new EventHandler<ExecutedEventArgs>(Bootstrapper_Initialized);
    }

    I tried doing it in an aspx file on the Page_Load event, and it's finding the inbound pipe now, but it still isn't limiting the index to the one blog, even after I re-index: 
    namespace SitefinityWebApp
    {
        public partial class InitNewsSearchIndex : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //Add a search index for the News blog
                var blog = App.WorkWith().Blogs().Where(b => b.Title.ToString() == "News").Get().SingleOrDefault();
                if (blog != null)
                {
                    var manager = PublishingManager.GetManager("SearchPublishingProvider");
                    var publishingPoint = manager.GetPublishingPoints().Where(pp => pp.Name == "News Index").First();
                    var pipeSettings = publishingPoint.GetInboundPipes().First().PipeSettings as SitefinityContentPipeSettings;
                    pipeSettings.ContentLinks = new Guid[] { blog.Id };
                    manager.SaveChanges();
                }
            }
        }
    }

  6. Nicholas
    Nicholas avatar
    9 posts
    Registered:
    30 Jun 2013
    05 Dec 2013 in reply to Nicholas
    Link to this post
    It turns out there were multiple inbound pipes, so I figured out which one of them represented blogs using the output from PublishingService.svc  that was being  queried by the Edit Index page, and then I changed the settings on that specific pipe:

    namespace SitefinityWebApp
    {
        public partial class InitNewsSearchIndex : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //Add a search index for the News blog
                var blog = App.WorkWith().Blogs().Where(b => b.Title.ToString() == "News").Get().SingleOrDefault();
                if (blog != null)
                {
                    var manager = PublishingManager.GetManager("SearchPublishingProvider");
                    var publishingPoint = manager.GetPublishingPoints().Where(pp => pp.Name == "News Index").First();
                    var pipeSettings = publishingPoint
                            .GetInboundPipes()
                            .Where(ip => ip.PipeSettings.Id.Equals(new Guid("7da0f3b4-876e-6f25-b333-ff0000b26694")))
                            .First()
                            .PipeSettings
                            as SitefinityContentPipeSettings;
                    pipeSettings.ContentLinks = new Guid[] { blog.Id };
                    manager.SaveChanges();
                }
            }
        }
    }

    And it works!
  7. Bonny
    Bonny avatar
    58 posts
    Registered:
    11 Nov 2016
    06 Dec 2013
    Link to this post
    Hello,

    I am glad to hear that you resolved your problem. I will close this ticket, but you can reopen it if there is some problem with this solution.

    Regards,
    Bonny
    Telerik
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
7 posts, 2 answered