2013-10-09 50 views
0

dtSearch的文檔對此有點混淆。我試圖讓dtSearch返回的項目按照創建的降序(最新的第一個)的順序返回。現在engine.Search方法似乎在返回的結果中根本不包含有關日期的任何信息。在sitecore中獲取dtsearch以通過createdDate對項目進行排序

我知道我需要在創建索引時使用高級選項以獲取日期字段,因此我可以按此排序,但我該怎麼做?

我看到這個:http://support.dtsearch.com/dts0150.htm但我不確定在哪裏或如何應用它。我沒有從文檔中引用的演示文稿,任何人都可以顯示如何爲索引添加日期?

+0

無論如何不確定這個helsp,但我從來沒有發現dtSearch特別好。如果你只是想要基本搜索,或多或少沒有配置它的方式,它是可用的。但讓它工作和索引等我的網頁等我發現是一個無用的,只是不值得。如果可能的話,切換到其他的,Lucene,Google等。 – Holger

回答

0

爲了能夠對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進行排序。

相關問題