我怀疑您已经知道了,但为了确定:您可以全局定义哪些类型应该允许显示在控制面板导航设置的搜索结果中,然后将相关部分导出并包含到产品的 GS 配置文件中-propertiestool.xml
.
但是,如果您希望仅在某些部分中排除某些类型,您可以自定义Products.CMFPlone/skins/plone_scripts/livesearch_reply
,它已经过滤了类型,仅在第 38 行(版本 4.3.1)周围显示“Friendly_types”,并添加如下条件:
Edit:我删除了检查上下文的 Absolute_url 的解决方案,因为在这种情况下,上下文实际上是 livesearch_reply,而不是当前的部分位置。相反,该语句现在检查引用者是否是我们的部分:
REQUEST = context.REQUEST
current_location = REQUEST['HTTP_REFERER']
location_to_filter = '/fullpath/relative/to/siteroot/sectionId'
url_to_filter = str(portal_url) + location_to_filter
types_to_filter = ['Event', 'News Item']
if current_location.find(url_to_filter) != -1 or current_location.endswith(url_to_filter):
friendly_types = types_to_filter
else:
friendly_types = ploneUtils.getUserFriendlyTypes()
然而,如果用户点击回车键或回车键或“高级搜索...”链接,则登陆到与肝脏结果不同的结果页面,这会使情况悬而未决。
Update:将过滤应用到 @@search-template 的方法可以是注册具有以下内容的 Javascript:
(function($) {
$(document).ready(function() {
// Let's see, if we are coming from our special section:
if (document.referrer.indexOf('/fullpath/relative/to/siteroot/sectionId') != -1) {
// Yes, we have the button to toggle portal_type-filter:
if ($('#pt_toggle').length>0) {
// If it's checked we uncheck it:
if ($('#pt_toggle').is(':checked')) {
$('#pt_toggle').click();
}
// If for any reason it's not checked, we check and uncheck it,
// which results in NO types to filter, for now:
else {
$('#pt_toggle').click();
$('#pt_toggle').click();
}
// Then we check types we want to filter:
$("input[value='Event']").click();
$("input[value='News Item']").click();
}
}
})
})(jQuery);
此外,不同的用户操作会导致不同的、不一致的行为:
Update:为了克服尖锐的结果,您可以将其添加到 JS 中的 if 语句之后:
// Get search-term and add an asterix for blurry results:
var searchterm = decodeURI(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURI('SearchableText').replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1")) + '*';
// Insert new searchterm in input-text-field:
$('input[name=SearchableText]').val(searchterm);
Update2:在此相关任务中,Eric Brehault 提供了在提交期间传递星号的更好解决方案:自定义克隆搜索 https://stackoverflow.com/questions/41811422/customize-plone-search
当然,你也可以在livesearch_reply中自定义advanced-search-link的目标,分别在@@search的JS中,但这个链接在UI方面是相当多余的,恕我直言。
另外,如果您仍在使用原型,并且根据上下文有更多预过滤搜索结果的用例,我可以建议您看看集体形式标准 https://github.com/collective/collective.formcriteria,它允许通过 UI 定义搜索条件。我喜欢它,因为它通用且简单的克隆方法:编目 indizi 和集合。与 eea.facetednavigation 相反,它不会破坏可访问性,并且也可以通过一些 live-search-js-magic 逐步增强,只需付出一点努力。感谢罗斯帕特森 http://rpatterson.net/这里!只需通过更改集合(旧式)的视图即可将其转换为搜索表单,并且它也可以显示为集合 portlet。您可以决定用户应该能够更改哪些标准(例如,您隐藏类型过滤器并提供文本搜索输入)。