1

我的简短查询:

我扩展了 ContentBySearchWebpart,以便为搜索创建自定义查询。我修改了 DataProviderJSON 属性并在其中添加了我的自定义 QueryTemplate。但是 Webpart 使用默认结果呈现

我想做的是:

  1. 我创建了目录网站集和其他发布网站集
  2. 在目录站点中创建了一个列表,将其启用为目录,在发布站点中建立了此目录的连接。
  3. 在其结果源是上述目录连接的发布站点中添加了 CSWP。
  4. 现在我想自定义我的查询
4

1 回答 1

0

我已经解决了我的问题。我们需要在扩展 webpart 的构造函数中设置一些基本属性。下面是一个代码示例:

            string dataProviderJson = "{{'Properties':{{'TryCache':true,'Scope':'{0}','HHTitle_WB_Marker1':50,'HHTitle_WB_Marker2':60,'UpdateLinksForCatalogItems':true,'EnableStacking':true,'searchTerms':'','Tag':''}},'QueryGroupName':'Default','SourceID':'8413cd39-2156-4e00-b54d-11efd9abdb89','SourceName':'Local SharePoint Results (System)','SourceLevel':'Ssa','CollapseSpecification':'','QueryTemplate':'{{searchTerms?}} (contentclass:sts_listitem OR IsDocument:True) SPSiteUrl:{1} ListId:3d001e7a-d856-428b-9785-edf7ec4f4876 {{?owstaxidMetadataRegion:{{Tag}}}}  owstaxIdMetadataRegion:{2}','FallbackSort':[{{'p':'Rank','d':0}}],'RankRules':[],'AsynchronousResultRetrieval':false,'SendContentBeforeQuery':true,'BatchClientQuery':true,'FallbackLanguage':-1,'FallbackRankingModelID':'8f6fd0bc-06f9-43cf-bbab-08c377e083f4','EnableStemming':true,'EnablePhonetic':false,'EnableNicknames':false,'EnableInterleaving':true,'EnableQueryRules':true,'EnableOrderingHitHighlightedProperty':false,'HitHighlightedMultivaluePropertyLimit':-1,'IgnoreContextualScope':false,'ScopeResultsToCurrentSite':false,'TrimDuplicates':true,'ClientType':'ContentSearchRegular','UpdateAjaxNavigate':true,'SummaryLength':180,'DesiredSnippetLength':90,'PersonalizedQuery':false,'FallbackRefinementFilters':null,'IgnoreStaleServerQuery':false,'RenderTemplateId':'DefaultDataProvider','AlternateErrorMessage':null,'Title':''}}";
            string siteUrl = SPContext.Current.Site != null ? SPContext.Current.Site.Url.Trim() : "";
            base.ResultsPerPage = 3;
            base.BypassResultTypes = true;
            base.AlwaysRenderOnServer = false;
            dataProviderJson = String.Format(dataProviderJson, siteUrl, siteUrl + "/sites/Catalog", "en");
            base.DataProviderJSON = dataProviderJson;
            base.ItemTemplateId = "/_catalogs/masterpage/Display Templates/Content Web Parts/Banner.js";
            base.GroupTemplateId = "/_catalogs/masterpage/Display Templates/Content Web Parts/Group_Content.js";
            base.SelectedPropertiesJson = "['PublishingImage','PictureURL','PictureThumbnailURL','Path','Title','Description','SecondaryFileExtension','ContentTypeId']";
            base.HitHighlightedPropertiesJson = "['Title','Path','Author','SectionNames','SiteDescription']";
            base.QueryGroupName = "Default";
            base.RenderTemplateId = "/_catalogs/masterpage/Display Templates/Content Web Parts/Control_Banner.js";
            base.StatesJson = "{}";
            base.Title = "Banner Search WebPart";
            base.Description = "Banner Search WebPart";
            base.AllowMinimize = true;
            AllowConnect = true;
            AllowEdit = true;
            AllowHide = true;
            base.ZoneID = "ImportedPartZone";
于 2012-10-22T10:03:39.987 回答