Skip to content

Instantly share code, notes, and snippets.

@darrenferguson
Created January 11, 2015 10:22
Show Gist options
  • Save darrenferguson/7559866bb8a2800e8f36 to your computer and use it in GitHub Desktop.
Save darrenferguson/7559866bb8a2800e8f36 to your computer and use it in GitHub Desktop.
using System.Linq;
using Examine;
using Umbraco.Core.Persistence;
using Umbraco.Web;
using UmbracoExamine;
namespace Moriyama.PlasterCast.Examine.Indexer
{
public class FasterInternalIndexer : UmbracoContentIndexer
{
private class QuickNode
{
public int NodeId { get; set; }
}
private const string Sql =
@"select cmsDocument.nodeId from cmsDocument, umbracoNode, cmsContent, cmsContentType
where
umbracoNode.id = cmsDocument.nodeId
and cmsContent.nodeId = umbracoNode.id
and cmsContent.contentType = cmsContentType.nodeId
and newest = 1 and umbracoNode.id > 0";
protected override void PerformIndexRebuild()
{
var d = new Database("umbracoDbDSN");
var nodes = d.Query<QuickNode>(Sql);
const int blockSize = 1000;
var group = nodes.Select(x => x.NodeId).Select((x, index) => new {x, index}).GroupBy(x => x.index/blockSize, y => y.x);
var contentService = UmbracoContext.Current.Application.Services.ContentService;
foreach (var block in group)
{
var content = contentService.GetByIds(block);
foreach (var contentItem in content)
{
var serialised = UmbracoContext.Current.Application.Services.PackagingService.Export(contentItem, false);
EnqueueIndexOperation(new IndexOperation()
{
Operation = IndexOperationType.Add,
Item = new IndexItem(serialised, contentItem.ContentType.Alias, contentItem.Id.ToString())
});
}
SafelyProcessQueueItems();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment