2014-05-06 163 views
3

我们使用Sitecore的6.5和Lucene搜索。重建Lucene的搜索索引失败

我试图重建使用索引浏览器的索引,但我得到一个错误:

An error occurred

System.InvalidOperationException: Item's template is null. at Sitecore.Search.Crawlers.DatabaseCrawler.GetAllTemplates(Item item)

但我不知道如何找到这些项目没有模板...

回答

2

你已经遇到了不应该存在于你的sitecore数据库中的东西。找到我相信该项目的最好方法是打开你的SQL Management Studio并使用下面的查询主数据库上:

select * from items where templateid not in (select id from items) 
+0

谢谢你,但在这种情况下,这是一个客户机上没有直接访问SQL管理Studio或SQL服务器。我可以得到这个SQL执行,但有另一种方式? –

+1

你也可以设置一个DatabaseContext并直接在它上面运行这个查询! – Younes

-1

刚刚调试项目中的索引文件进行调试的最好办法是

只要您发布站点或自动项目索引重建或重建索引的时间,把断点在索引文件和观赏确切的问题

这里是示例代码

protected override void AddAllFields(Document document, Item item, bool versionSpecific) 
{ 
} 
<index id="Index name" type="Sitecore.Search.Index, Sitecore.Kernel"> 
    <param desc="name">$(id)</param> 
    <param desc="folder">__GermanUrl</param> 
    <Analyzer ref="search/analyzer" /> 
     <locations hint="list:AddCrawler"> 
     <customSearch type="BusinessModul.UrlIndexer,BusinessModule"> 
     <Database>web</Database> 
     <Root>/sitecore/content/</Root> 
     <Boost>2.0</Boost> 
     <IndexAllFields>false</IndexAllFields> 
     <include hint="list:IncludeTemplate"> 
     <includeTemplate>template id</includeTemplate> 
     </include> 
    </customSearch> 
    </locations> 
</index> 
0

你也许可以找到它在日志中根据您的日志记录设置。抓取工具向Item.Template调用它会记录这个模板,项目和数据库

if (templateItem == null) 
     Sitecore.Diagnostics.Log.SingleError(string.Format("Data template '{0}' not found for item '{1}' in '{2}' database 
0

提到您可以查询的项目表,如果你没有访问SQL服务器,我假设Sitecore的解决方案在你的机器上,你有连接字符串? 然后编写一个小应用程序为您运行查询。

var itemIds = (from i in dbContext.items select i.id).ToList(); 
var orphanItems = (from oi in dbContext.items where !itemIds.Contains(i.templateId) select oi).ToList();