2012-02-17 2 views
0

enter image description here내가 고급 검색 사용자 정의 작업입니다

C#을 사용는 SharePoint 고급 검색 페이지에서 등록 정보를 관리 만들기. 고급 검색 페이지에는 관리 속성으로 채울 수있는 속성 선택 도구가 있으며 SharePoint 인터페이스로 관리 속성을 노출 할 수 있습니다. 그러나 C#을 사용하여 고급 검색 페이지의 관리 속성을 만들어야합니다. 프로그래밍 방식으로 관리 속성을 만들고 고급 검색 속성에 추가하려면 어떻게해야합니까? 그 생각을 알아?

감사합니다.

답변

2

나는 내 문제를 해결했다. 첫째, 매핑을 통해 관리 속성을 만들었다. 이 link에서 솔루션에 액세스 할 수 있습니다.

 public void CreateManagedProperty() 
    { 
     // Get the default service context 
     SPServiceContext context = SPServiceContext.GetContext(SPServiceApplicationProxyGroup.Default, SPSiteSubscriptionIdentifier.Default);// Get the search service application proxy 
     var searchProxy = context.GetDefaultProxy(typeof(SearchServiceApplicationProxy)) as SearchServiceApplicationProxy; 

     // Get the search service application info object so we can find the Id of our Search Service App 
     if (searchProxy != null) 
     { 
      SearchServiceApplicationInfo ssai = searchProxy.GetSearchServiceApplicationInfo(); 

      // Get the application itself 
      var application = SearchService.Service.SearchApplications.GetValue<SearchServiceApplication>(ssai.SearchServiceApplicationId); 

      // Get the schema of our Search Service Application 
      var schema = new Schema(application); 

      // Get all the managed properties 
      ManagedPropertyCollection properties = schema.AllManagedProperties; 

      // Add a new property 
      ManagedProperty myProperty = properties.Create(Constants.ManagedPropertyName, ManagedDataType.Text); 
      myProperty.EnabledForScoping = true; 

      // Get the current mappings 
      MappingCollection mappings = myProperty.GetMappings(); 

      // Add a new mapping to a previously crawled field 
      var myMapping = new Mapping(
       new Guid(Constants.CrawledPropertyGuid), Constants.CrawledPropertyName, 31, myProperty.PID); 

      // Add the mapping 
      mappings.Add(myMapping); 

      // Update the collection of mappings 
      myProperty.SetMappings(mappings); 

      // Write the changes back 
      myProperty.Update(); 
     } 
    } 

그런 다음 관리 속성이 고급 검색 속성에 추가되었습니다.

 public void AddAdvancedSearchProperty() 
    { 
     string sourcefile = 
      string.Format(
       "{0}\\{1}", SPUtility.GetGenericSetupPath("TEMPLATE\\ADMIN\\ManagedProperties"), "NewAdvancedSearchProperty.xml"); 
     // Load the xml file into XmlDocument object. 
     var xmlDoc = new XmlDocument(); 
     try 
     { 
      xmlDoc.Load(sourcefile); 
     } 
     catch (XmlException e) 
     { 
      Console.WriteLine(e.Message); 
     } 

     // Now create StringWriter object to get data from xml document. 
     var sw = new StringWriter(); 
     var xw = new XmlTextWriter(sw); 
     xmlDoc.WriteTo(xw); 
     string newXmlString = sw.ToString(); 

     using (var sc = new SPSite("YOUR SITE")) 
     { 
      using (SPWeb web = sc.OpenWeb("searchcentre")) 
      { 
       SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager("pages/advanced.aspx", PersonalizationScope.Shared); 
       foreach (var wp in mgr.WebParts) 
       { 
        if (wp is AdvancedSearchBox) 
        { 
         var asb = wp as AdvancedSearchBox; 
         asb.Properties = newXmlString; 
         mgr.SaveChanges(asb); 
        } 
       } 

       mgr.Web.Dispose(); 
      } 
     } 
    } 

참고 : 잊지 마세요 !! 새 관리 속성을 만든 후 전체 크롤링을 시작합니다.