2015-11-06 64 views
1

嗨,我知道最有可能这个查询被问到。如何提高Sitecore查询的查询性能?我已经安装了dotTrancer并获得了可以在this图片中看到的结果。我的方法与我没有显示在图像中需要2,551毫秒和Sitecore查询叉2,344毫秒这是巨大的。 我正在使用Sitecore 7.2,我认为他们的数据库中有大约10K条记录。我们没有更多的每个项目5版本。我们要做的查询是:如何优化sitecore查询?

return rootItem.Axes.SelectSingleItem(string.Format("descendant::*[@@{0}='{1}']", attributeName, attributeValue)); 

attributeName = TemplateName。

你有什么想法可以优化请求吗?

回答

4

请勿使用Sitecore API进行搜索。使用Sitecore搜索:

public void Search(Item rootItem, string templateName) 
{ 
    var index = ContentSearchManager.GetIndex("sitecore_" + Sitecore.Context.Database.Name + "_index"); 
    using (var context = index.CreateSearchContext()) 
    { 
     var result = context.GetQueryable<SearchResultItem>().FirstOrDefault(i => i.TemplateName == templateName && i.Paths.Contains(rootItem.ID)); 
     if (result != null) 
     { 
      Item resultItem = result.GetItem(); 
     } 
    } 
} 
+0

@MarekMusilak,谢谢你的回答。我不知道为什么有时候,当我做第一个查询时,它的工作原理以及当我做你的版本不起作用。我正在重建索引,可能这是问题所在。 – Radu

+0

当然,索引必须重建 –

+0

@MareMusielak我已经重建了索引,并在代码中更改了所有工作正常。我有一个问题,上面的查询也适用于类似rootItem.Axes.SelectSingleItem(string.Format(“ancestor :: * [@ {0} ='{1}']”,fieldName,fieldValue))? – Radu