Indexing 正在sitecore中获取dtsearch以按createdDate对项目进行排序
dtSearch的文档在这方面有点混乱。我试图让dtSearch返回的项目按照创建日期的降序(最新的第一个)返回。目前,engine.Search方法在返回的结果中似乎根本不包含任何有关日期的信息 我知道我在创建索引时需要使用高级选项来获取其中的日期字段,这样我就可以按此进行排序,但是我该如何做呢Indexing 正在sitecore中获取dtsearch以按createdDate对项目进行排序,indexing,sitecore,dtsearch,Indexing,Sitecore,Dtsearch,dtSearch的文档在这方面有点混乱。我试图让dtSearch返回的项目按照创建日期的降序(最新的第一个)返回。目前,engine.Search方法在返回的结果中似乎根本不包含任何有关日期的信息 我知道我在创建索引时需要使用高级选项来获取其中的日期字段,这样我就可以按此进行排序,但是我该如何做呢 我看到了这一点:但不确定在哪里或如何应用它。我没有文档中引用的演示,有人能告诉我如何将日期添加到索引中吗?为了能够在此(对于dtSearch)自定义字段上排序,您需要向通过dtSearch索引的页面添
我看到了这一点:但不确定在哪里或如何应用它。我没有文档中引用的演示,有人能告诉我如何将日期添加到索引中吗?为了能够在此(对于dtSearch)自定义字段上排序,您需要向通过dtSearch索引的页面添加一个带有创建日期的元标记。您可以获取dtSearch文档,并检查其中是如何完成的 元标记的外观如下所示:
<meta id="scDateCreated" name="scDateCreated" content="20100629" />
这将得到你的结果。现在排序(this.FormatSearchResults):
//如果给定了templateId
if(templateId!=string.Empty)
{
list=xmlResult.SelectNodes(“/sitecore/result/item[scWebsitePath=”“+sitecoreContextItemPath+”,scTemplateId=”“+templateId+”,scDateCreated>”“+publishedFrom+”,scDateCreated<“+publishedTo+”);
}
其他的
{
list=xmlResult。选择节点(“/sitecore/result/item[scWebsitePath=”+sitecoreContextItemPath+”,scDateCreated>”“+publishedFrom+”,scDateCreated<“+publishedTo+”]”);
}
正如您所看到的,元标记将出现在这个搜索引擎将返回的XML中。您可以让自己的类将dtSearchResult强制转换为列表,然后使用Linq进行排序。无论如何,我不确定这是否有帮助,但我从未发现dtSearch特别好。如果您只想进行基本搜索,而几乎没有办法对其进行配置,那么它是可以使用的。但让它工作和索引所有的网页等我发现是一个麻烦,只是不值得。如果可能的话,换个别的,Lucene,Google等等。
ISearch engine = this.GetEngine();
// Search with the given searchPhrase and the set SearchOptions
engine.Search(searchPhrase, this.searchOptions);
// If there are searchResults return the searchResults formatted
if (engine.SearchResults != null)
{
return this.FormatSearchResults(engine.SearchResults, engine, searchPhrase, templateId, publishedFrom, publishedTo, specifiedPath, sortOrder);
}
// If a templateId was given
if (templateId != string.Empty)
{
list = xmlResult.SelectNodes("/sitecore/result/item[scWebsitePath='" + sitecoreContextItemPath + "' and scTemplateId='" + templateId + "' and scDateCreated > '" + publishedFrom + "' and scDateCreated < '" + publishedTo + "']");
}
else
{
list = xmlResult.SelectNodes("/sitecore/result/item[scWebsitePath='" + sitecoreContextItemPath + "' and scDateCreated > '" + publishedFrom + "' and scDateCreated < '" + publishedTo + "']");
}