2016-10-27 6 views
2

私は以前まで開発者が使用していたものを常に使用していましたが、これまではsitecoreの検索機能を掘り下げました。私は、特定の述語は、コードの以下の部分でウォーキングするようには見えなかった問題を見ていた:SearchManagerとContentSearchManagerはどちらですか?

public IEnumerable<IndexedEvent> SearchItems(Expression<Func<IndexedEvent, bool>> predicate) 
{ 
    using (IProviderSearchContext _context = ContentSearchManager.GetIndex(indexName).CreateSearchContext()) 
    { 
     IEnumerable<IndexedEvent> results = _context 
       .GetQueryable<IndexedEvent>() 
       .Where(predicate); 

      return results; 

    } 
} 

は、私は上記に書いていない、私はちょうどそれを使用しています。

私はコードが含まれ、この例の質問 Very basic usage of sitecore searchに出くわしたとき、私の問題を検討していた

// use id of from the index configuration 
using (IndexSearchContext indexSearchContext = SearchManager.GetIndex("my-custom-index").CreateSearchContext()) 
{ 
    // MatchAllDocsQuery will return everything. Use proper query from the link below 
    SearchHits hits = indexSearchContext.Search(new MatchAllDocsQuery(), int.MaxValue); 
    // Get Sitecore items from the results of the query 
    List<Item> items = hits.FetchResults(0, int.MaxValue).Select(result => result.GetObject<Item>()).Where(item => item != null).ToList(); 
} 

今これはインデックスを照会する全く異なる方法を使用しているようだ、IndexSearchContext私のコード(私が書いたものではない)はIProviderSearchContextです。どちらのマニュアルも見つからず、まったく別のアセンブリに存在します。

私はIndexSearchContextをいつ使うべきですか?IProviderSearchContextはいつ使うべきですか?そこにfundermental違いがあるか、それは同じnett結果を受け入れるだけの2つの方法ですか?

答えて

2

もしSearchManagerIndexSearchContextとを参照している質問およびコードは、サイトコア6(でよく、7+)ContentSearchManagerIProviderSearchContextとコードサイトコア7又は8のためのものであるからです。

あなたのコードがSitecore8用であり、コード例で示唆しているとおり、ContentSearchManagerを使用する方法があります。

+0

これはちょうど古いです。ありがとう。私は実際にコードの最初のビットで問題を抱えていますが、それは別の問題です。おかげで – Liam

+0

あなたはいつも別の質問をすることができます;) – Gatogordo

+0

私は、ちょうどいくつかをチェックするかもしれません。 – Liam

関連する問題