本文介绍了自定义显示模板以进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 限时删除!! HI我已经创建了一个自定义项目模板,如下所示.我想用我的自定义结果类型映射它,但是它不起作用< html xmlns:mso =" urn:schemas-microsoft-com:office:office" xmlns:msdt =" uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"< head>< title>新闻项目</title><!-[if gte mso 9]>< xml>< mso:CustomDocumentProperties>< mso:TemplateHidden> 0lt//mso:TemplateHidden>< mso:MasterPageDescription msdt:dt ="string"> $ Resources:Microsoft.Office.Server.Search,DisplayTemplateDescription_SearchDefaultItem</mso:MasterPageDescription>< mso:ContentTypeId msdt:dt =字符串"> 0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId>< mso:TargetControlType msdt:dt =字符串"> ;;#SearchResults;#</mso:TargetControlType>< mso:HtmlDesignAssociated msdt:dt =字符串"> 1</mso:HtmlDesignAssociated>< mso:ManagedPropertyMapping msdt:dt ='"string">'Title':'Title','Path':'Path','Description':'Description','EditorOWSUSER':'EditorOWSUSER','LastModifiedTime' :'LastModifiedTime','CollapsingStatus':'CollapsingStatus','DocId':'DocId','HitHighlightedSummary':'HitHighlightedSummary','HitHighlightedProperties':'HitHighlightedProperties','FileExtension':'FileExtension','ViewLife ViewsLifeTime','ParentLink':'ParentLink','FileType':'FileType','IsContainer':'IsContainer','SecondaryFileExtension':'SecondaryFileExtension','SEDWMPNewsPublishDate':'SEDWMPNewsPublishDate','DisplayAuthor':'Display ,"SiteTitle":"SiteTitle"</mso:ManagedPropertyMapping>< mso:HtmlDesignConversionSucceeded msdt:dt =字符串"> True</mso:HtmlDesignConversionSucceeded>< mso:CrawlerXSLFile msdt:dt =字符串"</mso:CrawlerXSLFile>< mso:HtmlDesignPreviewUrl msdt:dt =字符串"></mso:HtmlDesignPreviewUrl></mso:CustomDocumentProperties></xml><![endif]-></head><身体> < div id =" StoraEnso_Item_Default"><!-#_ if(!$ isNull(ctx.CurrentItem)&&!$ isNull(ctx.ClientControl)){ var id = ctx.ClientControl.get_nextUniqueId(); var itemId = id + Srch.U.Ids.item;var hoverId = id + Srch.U.Ids.hover;var hoverUrl =〜sitecollection/_catalogs/母版页/显示模板/搜索/Item_Default_HoverPanel.js"; $ setResultItem(itemId,ctx.CurrentItem);if(ctx.CurrentItem.IsContainer){ctx.CurrentItem.csr_Icon = Srch.U.getFolderIconUrl();}ctx.currentItem_ShowHoverPanelCallback = Srch.U.getShowHoverPanelCallback(itemId,hoverId,hoverUrl); ctx.currentItem_HideHoverPanelCallback = Srch.U.getHideHoverPanelCallback();_#-> < div id =" _#= $ htmlEncode(itemId)=#_" name ="SEItem" data-displaytemplate ="StoraEnsoDefaultItem" class ="ms-srch-item" onmouseover =" __ = ctx.currentItem_ShowHoverPanelCallback =#_" onmouseout =" __ = ctx.currentItem_HideHoverPanelCallback =#_>< h2 class =标题">< a href =" _#= ctx.CurrentItem.Path =#_> _#= ctx.CurrentItem.Title =#_</a>//h2>< div id =" _#= $ htmlEncode(hoverId)=#_" class ="ms-srch-hover-outerContainer"</div>.< p> _#= Srch.U.processHHXML(ctx.CurrentItem.HitHighlightedSummary)=#_</p>< div class =页脚">< dl class ="desc">< dt> SiteTitle</dt> _#= ctx.CurrentItem.SEDWMPNewsPublishDate =#_< dd>< a class =状态" href =#"> _#= ctx.CurrentItem.SiteTitle =#_</a></dd>< dt>作者</dt>< dd>< a class =状态" href =#"> _#= ctx.CurrentItem.DisplayAuthor =#_</a></dd></dl></div> </div><!-#_ }_#-> </div></body></html> 如果您在"managedPropertyMapping"中看到我添加了一个新属性"SEDWMPNewsPublishDate",当我在html中使用时,我没有得到价值.我检查了提琴手,发现此属性未映射. Json对象的确会返回此属性.但是,此属性具有价值.我还用内容搜索Webpart和我的代码进行了测试.它返回值.任何人都可以让我知道上面的渲染模板代码有什么问题吗?对此进行更新时,我使用页面上的resultscript Webpart来显示数据,并且创建了自定义结果类型来修改显示.我发现,当我在结果上添加所需的自定义属性时,脚本webpart 用作 scriptWebPart.SelectedPropertiesJson ="[\" SEDWMPNewsPublishDate \,\" SEDWMPIntroduction \]"保存更改,然后开始获取自定义属性的值.我不知道结果类型如何根据显示模板工作,以及何时将其应用于搜索数据.如果有人知道,请告诉我.如果我不能使用具有自定义属性的显示模板,那么显示模板上ManagedPropertyMapping的用途是什么?有人可以让我理解吗?解决方案 HI I have Created a custom Item Template as shown below.I want to map this with my custom result type but it is not working<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"><head><title>News Item</title><!--[if gte mso 9]><xml><mso:CustomDocumentProperties><mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden><mso:MasterPageDescription msdt:dt="string">$Resources:Microsoft.Office.Server.Search,DisplayTemplateDescription_SearchDefaultItem</mso:MasterPageDescription><mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId><mso:TargetControlType msdt:dt="string">;#SearchResults;#</mso:TargetControlType><mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated><mso:ManagedPropertyMapping msdt:dt="string">'Title':'Title','Path':'Path','Description':'Description','EditorOWSUSER':'EditorOWSUSER','LastModifiedTime':'LastModifiedTime','CollapsingStatus':'CollapsingStatus','DocId':'DocId','HitHighlightedSummary':'HitHighlightedSummary','HitHighlightedProperties':'HitHighlightedProperties','FileExtension':'FileExtension','ViewsLifeTime':'ViewsLifeTime','ParentLink':'ParentLink','FileType':'FileType','IsContainer':'IsContainer','SecondaryFileExtension':'SecondaryFileExtension','SEDWMPNewsPublishDate':'SEDWMPNewsPublishDate','DisplayAuthor':'DisplayAuthor1','SiteTitle':'SiteTitle'</mso:ManagedPropertyMapping><mso:HtmlDesignConversionSucceeded msdt:dt="string">True</mso:HtmlDesignConversionSucceeded><mso:CrawlerXSLFile msdt:dt="string"></mso:CrawlerXSLFile><mso:HtmlDesignPreviewUrl msdt:dt="string"></mso:HtmlDesignPreviewUrl></mso:CustomDocumentProperties></xml><![endif]--></head><body> <div id="StoraEnso_Item_Default"><!--#_ if(!$isNull(ctx.CurrentItem) && !$isNull(ctx.ClientControl)){ var id = ctx.ClientControl.get_nextUniqueId(); var itemId = id + Srch.U.Ids.item;var hoverId = id + Srch.U.Ids.hover;var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default_HoverPanel.js"; $setResultItem(itemId, ctx.CurrentItem);if(ctx.CurrentItem.IsContainer){ctx.CurrentItem.csr_Icon = Srch.U.getFolderIconUrl();}ctx.currentItem_ShowHoverPanelCallback = Srch.U.getShowHoverPanelCallback(itemId, hoverId, hoverUrl); ctx.currentItem_HideHoverPanelCallback = Srch.U.getHideHoverPanelCallback();_#--> <div id="_#= $htmlEncode(itemId) =#_" name="SEItem" data-displaytemplate="StoraEnsoDefaultItem" class="ms-srch-item" onmouseover="_#= ctx.currentItem_ShowHoverPanelCallback =#_" onmouseout="_#= ctx.currentItem_HideHoverPanelCallback =#_"><h2 class="heading"><a href="_#= ctx.CurrentItem.Path =#_">_#= ctx.CurrentItem.Title =#_</a></h2> <div id="_#= $htmlEncode(hoverId) =#_" class="ms-srch-hover-outerContainer"></div><p>_#= Srch.U.processHHXML(ctx.CurrentItem.HitHighlightedSummary) =#_</p><div class="footer"><dl class="desc"><dt>SiteTitle</dt> _#= ctx.CurrentItem.SEDWMPNewsPublishDate =#_<dd><a class="status" href="#">_#= ctx.CurrentItem.SiteTitle =#_</a></dd><dt>Author</dt><dd><a class="status" href="#">_#= ctx.CurrentItem.DisplayAuthor =#_</a></dd></dl></div> </div><!--#_ }_#--> </div></body></html>If you see in "managedPropertyMapping" I have added a new property "SEDWMPNewsPublishDate" and when I use in my html I am not getting the value.I checked with fiddler and I found that This property is not getting mapped. Json object does return this property.However  this property has value. I have tested with content search webpart nad my code also.it returns value.Can anyone let me know is there any issue in the above rendering template code On update to this, I was using resultscript webpart on the page to display data and I have created custom result type to modify the display.What I found that when I add the custom properties which I need, on result script webpart  using as follows  scriptWebPart.SelectedPropertiesJson = "[\"SEDWMPNewsPublishDate\",\"SEDWMPIntroduction\"]"and save the changes then I start getting the value of my custom properties.I don't know how the result type works in accordance with display templates and when does it gets applied on the search data.If anyone is aware please let me know.If I can't use the display templates with custom properties then what is the use of ManagedPropertyMapping on display templates.Can anyone please make me understand? 解决方案 这篇关于自定义显示模板以进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的..
09-08 03:49