2013-12-09 46 views
0

我想在umbraco中設置一個搜索題目。我有兩個搜索字段,材料和製造商。當我試圖用一種材料和一個製造商搜索時,它會給出正確的結果。試圖尋找一種以上材料或製造商不給result.here是我的代碼在umbraco中的多個搜索詞檢查搜索

const string materialSearchFields = "material"; 
    const string manufacturerSearchFields = "manufacturer"; 

如果(!string.IsNullOrEmpty(的Request.QueryString [「材料」)){ 材料 = Helper.StripTags(的Request.QueryString [ 「材料」]); } if(!string.IsNullOrEmpty(Request.QueryString [「manufacturer」])) { manufacturer = Helper.StripTags(Request.QueryString [「manufacturer」]); } 如果(!string.IsNullOrEmpty(的Request.QueryString [ 「材料」])||!string.IsNullOrEmpty(的Request.QueryString [ 「製造商」)) { 變種查詢= userFieldSearchCriteria.Field(materialSearchFields,材料) .And()。Field(manufacturerSearchFields,製造商).Compile(); contentResults = contentSearcher.Search(query).ToList(); }

這裏

我的搜索keywors在查詢字符串是材料=鐵,鋼

我們如何拆分此關鍵字和搜索做了什麼? 在此先感謝您的幫助....

回答

0

您正在使用AND運算符,您的情況我認爲您正在尋找GROUPEDOR?

我只是在一箇舊的項目中工作,並從那裏抓住了這個snipet(我已經適應了您的需求)。我認爲這會幫助你:

public IEnumerable<DynamicNode> SearchUmbraco(string[] keywords, string currentCulture) 
     { 
      // In this case I had some diferent cultures, so this sets the BaseSearchProvider to the given culture parameter. You might not need this, use your default one. 
      BaseSearchProvider searcher = SetBaseSearchProvider(currentCulture); 

      var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.Or); 
      var groupedQuery = searchCriteria.GroupedOr(new[] {"manufacturer", "material"}, keywords).Compile(); 

      var searchResults = searcher.Search(groupedQuery); 

      // ... return IEnumerable of dynamic nodes (in this snipet case) 

     } 

我只是分裂(ETC)在助手的關鍵字,並通過他們向一個字符串數組,當我把這個方法。

只需在umbraco博客上查看此信息:http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine.aspx