【问题标题】:Umbraco and IndexingUmbraco 和索引
【发布时间】:2015-04-30 23:15:24
【问题描述】:

我有一个带有 2 个解决方案的 Visual Studio 项目: 解决方案 1:UmbracoCms(Umbraco 7.2 代码库) 解决方案2:SeachIndexer(lucene.net spatial - Windows Console Application)

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

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

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

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

当我运行代码时,我收到以下错误:

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

我要做的是在单独的解决方案中使用 Lucene.net 空间(检查不支持空间)索引 Umbraco 页面,以保持 Umbraco 基本代码的清洁。我希望能够以 15 分钟的间隔安排 SearchIndexer。

最好的方法是什么?

【问题讨论】:

  • 您可以通过挂钩服务事件在 Umbraco 网站环境中执行处理 - 这样您就无需担心配置是否设置正确,或在外部控制台应用程序中运行等-有关详细信息,请参阅下面的答案

标签: umbraco lucene.net umbraco7 spatial-index


【解决方案1】:

您遇到这种错误是因为 Umbraco 看不到它的配置。

你可以有两种解决方案:

Umbraco 控制台:意思是在控制台应用程序中重新创建 Umbraco 环境。你可以看到/使用this project(例如)。如您所见,在App.config 中重新创建了 Umbraco 所需的所有配置。我以前从未使用过它(这是我的第一个谷歌结果),但它似乎是一个很好的起点。

直接访问 Umbraco DB:如果您不需要广泛使用 Umbraco API,最好直接在 Umbraco DB 中查找您的内容。显然,您必须探索 Umbraco DB 才能了解要查找的内容,如果您不了解 Umbraco,这可能会很耗时

【讨论】:

  • 怎么样?抱歉,我是 Umbraco 的新手。我想为某些文档类型的 Umbraco 页面实现本教程。 leapinggorilla.com/Blog/Read/1010/…
  • 我不建议尝试直接访问 Umbraco 数据库 - 内容节点的元数据查询起来很复杂,最重要的是,每次保存内容节点时都会有一个新版本的所有内容添加到数据库表中。最好让 Umbraco 为您将数据翻译成它的模型。
【解决方案2】:

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

方法如下:

  1. 创建一个新的解决方案(我通常使用一个空的 Web 项目,但您可以只创建一个库项目)并安装与您的 UmbracoCms 版本相对应的 UmbracoCms.Core nuget 包(它将为您安装所有必要的依赖项,包括检查) .
  2. 按照教程添加 Luncene.Net 包
  3. 添加一个派生自 Umbraco.Core.ApplicationEventHandler 的类并覆盖 ApplicationStarted - 这将使您能够访问 Umbraco 服务以及检查索引事件 - 您可以在本练习中使用其中任何一个 - 您可能会发现检查事件更合适。
  4. 在您的 Umbraco 项目中添加对新项目的引用,以便将其拉入。

您的 EventHandler 类可能如下所示:

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 的索引触发时进行索引,请改用它:

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;
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多