Sitefinity 6.1: Creating a search index for a specific blog
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);
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();
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"
);
publishingPoint.GetInboundPipes().Where(ip => ip.Name !=
"DocumentSearchInboundPipe"
).First();
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
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);
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();
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();
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