在这一点上,dtSearch的文档有点混乱。我正在尝试让dtSearch返回的项目按照创建日期的降序顺序返回(所以先返回最新的日期)。现在,在返回的结果中,engine.Search方法似乎根本不包含任何有关日期的信息。
我知道在创建索引时需要使用高级选项来获取日期字段,这样我就可以按日期字段进行排序,但是我该怎么做呢?
我看到了这个:http://support.dtsearch.com/dts0150.htm,但不确定在哪里或如何应用它。我没有文档中引用的demo,有人能向我展示一下如何将日期添加到索引中吗?
发布于 2013-10-22 15:51:14
为了能够对这个(对于dtSearch)自定义域进行排序,您需要向通过dtSearch建立索引的页面添加一个带有创建日期的meta标记。您可以获取dtSearch文档并检查其中是如何完成的。
你的meta标签看起来像这样:
<meta id="scDateCreated" name="scDateCreated" content="20100629" />然后,在dtSearch crawler工具中,您可以指定应该对此元标记(字段)进行索引。在dtSearch对此字段建立索引后,您可以使用此字段按项目/页面的创建日期对搜索结果进行排序。请注意,如果使用通配符设置(url中的/*)在通配符项目上显示来自不同数据源的项目,则必须从通配符上显示的项目而不是Sitecore.Context.Item中获取创建日期。
按日期排序的示例代码:
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);
}这将得到您的结果。现在排序(this.FormatSearchResults):
// 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 + "']");
} 如您所见,元标记将出现在此searchEngine将返回的XML中。您可以获得自己的类,以便能够将dtSearchResult转换为列表,然后使用Linq进行排序。
https://stackoverflow.com/questions/19279030
复制相似问题