使用Lucene提高Sitecore的性能

fed*_*rio 1 c# lucene performance search sitecore

我目前正在使用Sitecore,在那里我们创建了一个Create New Content部分,它打开一个弹出窗口,显示8个最常用的模板,以及使用次数.

问题是,当模板数量太高时(目前最高的模板超过11k)需要太长时间.

这是我用来获取8个最常用模板的代码:

我从数据库中获取所有项目.

var allItems = db.GetItem("/sitecore/content").Axes.GetDescendants();
Run Code Online (Sandbox Code Playgroud)

然后我得到最常用的8个.

var mostUsedTemplates = allItems.GroupBy(x => x.TemplateID)
                .Select(x => new { TemplateID = x.Key, Count = x.Count() })
                .OrderByDescending(x => x.Count).Take(8);
Run Code Online (Sandbox Code Playgroud)

我们已经实现了Lucene,我真的不知道如何使用它.

我试图找到获取所有模板的方法,计算它们,然后获得最常用的8个模板,但我什么也没找到.

简而言之,我需要计算用于在内容中创建项目的所有模板,并恢复具有最高计数的8.

任何帮助将不胜感激.谢谢.

扩展:这是我目前正在制作的配置.我试图包含所有模板,并能够计算它们.

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<search>
  <configuration>
    <indexes>
      <index id="usage_template_count" type="Sitecore.Search.Index, Sitecore.Kernel">
        <param desc="name">$(id)</param>
        <param desc="folder">usage_template_count</param>
        <Analyzer ref="search/analyzer" />
        <locations hint="list:AddCrawler">   

        For what I understand, here is what I specify what to index.
        From what I read, I know how to include some templates, or excludes others, but no idea how to include ALL.
        Also don´t know if I have to set up something in the config to be able to count the results.

        </locations>
      </index>
    </indexes>
  </configuration>
</search>
</sitecore>
</configuration>   
Run Code Online (Sandbox Code Playgroud)

再次感谢!

tec*_*414 7

首先,永远不要迭代或检索整个内容树并期望它执行.这不是一个合理的期望.

您可以在lucene中执行此操作,但它需要索引模板本身并添加包含模板实例计数的字段.(查看scSearchContrib以使其更容易.)但是,您需要对此索引进行预定的完全重建,因为模板项永远不会重新编制索引,除非它们自己更改.

Links DB可能会让您获得更好的性能,因为应该包含对模板的引用.但是,您仍然需要遍历所有模板,并检查每个模板的引用数量.

无论使用哪种解决方案,我都绝对建议实施缓存层.

最后,为什么有必要动态地这样做呢?您安装的八个最常用或最有用的模板是否会经常更改?为什么不在内容树中的某个位置为此配置元素,并根据模板使用情况的报告定期更新?您可以使用Sitecore Powershell控制台之类的东西来运行报告.如果您确实需要自动化它,请编写执行查询的Sitecore Powershell脚本,然后自动更新配置元素.安排脚本每天运行.