我目前正在使用Sitecore,在那里我们创建了一个Create New Content部分,该部分打开弹出窗口,显示8个最常用的模板以及使用次数。使用Lucene改善Sitecore中的性能
问题是,如果模板数量太高(当前最高超过11k),则需要太长的时间。
下面是使用以获得8个最常用的模板的代码I'm:
我从数据库中获取的所有项目。
var allItems = db.GetItem("/sitecore/content").Axes.GetDescendants();
然后我得到8使用最多。
var mostUsedTemplates = allItems.GroupBy(x => x.TemplateID)
.Select(x => new { TemplateID = x.Key, Count = x.Count() })
.OrderByDescending(x => x.Count).Take(8);
我们已经实现了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>
再次感谢!
问题是客户端要使用Lucene。我用另一种方式思考,我用一个计划的任务每小时更新一次桌面,并且排名前8,但他们并不喜欢这个想法。他们只是想要Lucene,每次按下按钮时都会查询。 – 2013-02-21 18:16:39
然后,您将需要创建一个只包含模板的自定义索引,以及一个索引模板实例数量的自定义字段。创建一个夜间计划重建。看看scSearchContrib /高级数据库爬行器使这个更加简单。 https://github.com/sitecorian/SitecoreSearchContrib – techphoria414 2013-02-21 19:17:29
好的,我正在制作索引。问题是2件事: 1 - 我不知道如何设置配置,因此它搜索所有模板。 2 - 如何计算一切。我是否需要在每个模板(或每个模板所继承的模板)中添加一个字段,并在其中创建它的次数? – 2013-02-25 14:58:29