爲了能夠對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 + "']");
}
正如你所看到的meta標籤將出現在這的搜索引擎將返回XML。你可以讓自己的類能夠將你的dtSearchResult轉換爲列表,然後使用Linq進行排序。
無論如何不確定這個helsp,但我從來沒有發現dtSearch特別好。如果你只是想要基本搜索,或多或少沒有配置它的方式,它是可用的。但讓它工作和索引等我的網頁等我發現是一個無用的,只是不值得。如果可能的話,切換到其他的,Lucene,Google等。 – Holger