[英]getting dtsearch in sitecore to sort items by createdDate
dtSearch的文檔對此有些困惑。 我正在嘗試讓dtSearch返回的項目按創建日期降序返回(所以最新的優先)。 現在,engine.Search方法似乎在返回的結果中根本不包含有關日期的任何信息。
我了解在創建索引以獲取日期字段時需要使用高級選項,以便我可以按此進行排序,但是我該怎么做呢?
我看到了: http : //support.dtsearch.com/dts0150.htm但是我不確定在哪里或如何使用它。 我沒有文檔中引用的演示,在那里有人可以顯示如何為索引添加日期嗎?
為了能夠在此(用於dtSearch)自定義字段上進行排序,您需要向dtSearch索引的頁面添加帶有創建日期的元標記。 您可以獲取dtSearch文檔,並查看其中的操作方式。
您的meta標簽看起來像這樣:
<meta id="scDateCreated" name="scDateCreated" content="20100629" />
然后,您可以在dtSearch搜尋器工具中指定此元標記(字段)的索引。 在dtSearch將該字段編入索引之后,您可以使用該字段按照創建項目/頁面的日期對搜索結果進行排序。 請注意,如果您使用通配符設置(URL中的/ *)在通配符項目上顯示來自其他數據源的項目,則必須從通配符上顯示的項目而不是Sitecore.Context獲取創建日期。 。項目。
按日期排序的示例代碼:
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轉換為List,然后使用Linq進行排序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.