Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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