Umbraco和索引 [英] Umbraco and Indexing

查看:99
本文介绍了Umbraco和索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有2个解决方案的Visual Studio项目: 解决方案1:UmbracoCms(Umbraco 7.2代码库) 解决方案2:SeachIndexer(lucene.net空间-Windows控制台应用程序)

I have a Visual Studio project with 2 solutions: Solution 1: UmbracoCms (Umbraco 7.2 code base) Solution 2: SeachIndexer (lucene.net spatial - Windows Console Application)

在解决方案2中,我引用了Umbraco解决方案中的以下.dll:

In my solution 2 I have reference to the following .dlls from the Umbraco solution:

  • UmbracoCms.dll
  • cms.dll
  • businesslogic.ddl
  • umbraco.dll
  • umbraco.DataLayer.dll

在Program.cs文件中,我具有以下代码:

In the Program.cs file I have the following code:

Node rootNode = new Node(1103);
string nodeTypeAlias = "articlePage";

if (node.NodeTypeAlias == nodeTypeAlias)
    listNode.Add(node);

foreach (Node childNode in node.Children)
{
    GetDescendantOrSelfNodeList(childNode, nodeTypeAlias);
}

//some other code

运行代码时,出现以下错误:

When I run the code I get the following error:

could not load the umbraco.core.configuration.umbracosettings.iumbracosettingssection from config file

我想做的是在一个单独的解决方案中使用Lucene.net空间索引Umbraco页面(Examine不支持空间),以保持Umbraco基本代码的整洁.我希望能够将SearchIndexer的时间间隔设置为15分钟.

What I'm trying to do is index Umbraco pages using Lucene.net spatial (Examine does not support spatial) in a seperate solution keeping the Umbraco base code clean. I want to able to schedule the SearchIndexer at 15 mins interval.

解决此问题的最佳方法是什么?

What's best way to go about this?

推荐答案

您可以使用Umbraco的Content事件处理功能,并在每次发布节点时对其进行索引,而不是使用控制台项目并安排它每15分钟运行一次.这样,您的索引会立即刷新,而您不必担心外部调度等问题.

Instead of using a console project and scheduling it to run every 15 minutes, you could take advantage of Umbraco's Content event handling and index the node every time it's published. This way your index is refreshed straight away, and you don't have to worry about external scheduling etc.

方法如下:

  1. 创建一个新的解决方案(我通常使用一个空的Web项目,但是您可以仅创建一个Library项目)并安装与您的UmbracoCms版本相对应的UmbracoCms.Core nuget包(它将为您安装所有必要的依赖项,包括Examine)
  2. 根据教程添加Luncene.Net软件包
  3. 添加一个从Umbraco.Core.ApplicationEventHandler派生的类并覆盖ApplicationStarted-这将使您可以访问Umbraco服务以及检查索引"事件-您可以在本练习中使用这两种方法-您可能会发现检查事件"更合适. /li>
  4. 在Umbraco项目中添加对新项目的引用,以便将其引入.
  1. Create a new solution (I normally use an empty Web Project but you can just create a Library project) and install the UmbracoCms.Core nuget package corresponding to your UmbracoCms version (it will install all the necessary dependencies for you including Examine).
  2. Add the Luncene.Net packages as per the tutorial
  3. Add a class deriving from Umbraco.Core.ApplicationEventHandler and override ApplicationStarted - this will give you access to the Umbraco Services as well as the Examine Indexing events - you can use either for this exercise - you may find the Examine Events more suitable.
  4. In your Umbraco project add a reference to your new project so it get's pulled in.

您的EventHandler类可能看起来像这样:

Your EventHandler class may look something like this:

public class SpacialIndexingEventHandler : ApplicationEventHandler
{
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        Umbraco.Core.Services.ContentService.Publishing += ContentService_Publishing;
    }

    private void ContentService_Publishing(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<IContent> e)
    {
        // For each published node, perform the necessary indexing.
        string nodeTypeAlias = "ArticlePage";
        foreach (var node in e.PublishedEntities.Where(a => a.ContentType.Alias == nodeTypeAlias))
        {
            // Index this

        }
    }
}

如果您希望在Umbraco的索引触发时进行索引,请改用此方法:

If you wanted to do the indexing whenever Umbraco's indexing triggers, use this instead:

public class SpacialDataIndexingEventHandler : ApplicationEventHandler
{
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        // connect to the GatheringNodeData event of the provider you're interested in:
        foreach(var provider in ExamineManager.Instance.IndexProviderCollection.AsEnumerable<BaseIndexProvider>()) {
            if (provider.Name.StartsWith("External")) {
                provider.GatheringNodeData += provider_GatheringNodeData;
                break;
            }
        }
    }

    void provider_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
    {
        if (e.IndexType == IndexTypes.Content)
        {
            // Get the Node from the ContentService:
            var node = ApplicationContext.Current.Services.ContentService.GetById(e.NodeId);
            // Do your spacial indexing here;
        }
    }
}

这篇关于Umbraco和索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆