Sitefinity 6.1: Creating a search index for a specific blog

Posted by Community Admin on 04-Aug-2018 20:09

Sitefinity 6.1: Creating a search index for a specific blog

All Replies

Posted by Community Admin on 01-Dec-2013 00:00

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?

Posted by Community Admin on 04-Dec-2013 00:00

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

Posted by Community Admin on 04-Dec-2013 00:00

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

Posted by Community Admin on 05-Dec-2013 00:00

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

Posted by Community Admin on 05-Dec-2013 00:00

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();
            
        
    

Posted by Community Admin on 05-Dec-2013 00:00

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!

Posted by Community Admin on 06-Dec-2013 00:00

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

This thread is closed