本页面适用于 Apigee 和 Apigee Hybrid。
查看 Apigee Edge 文档。
如要在您的门户内搜索公开可用内容,您可以创建一个专用搜索页,并在其中嵌入 Google 自定义搜索引擎 (CSE)。
要创建自定义搜索页,请执行以下操作:
- 发布您的门户内容。
创建 Google 自定义搜索引擎:
- 前往 Google 自定义搜索配置页面。
- 点击添加以创建新的自定义搜索引擎。
- 配置自定义搜索引擎并确定门户网站网域。
请参阅 Google 自定义搜索帮助中的创建搜索引擎。自定义搜索配置会返回如下内容:
其中,<script async src="https://cse.google.com/cse.js?cx=e13bcb52d46f04dfd"></script> <div class="gcse-search"></div>
cx=e13bcb52d46f04dfd
是 Google 搜索引擎 ID。
将以下自定义脚本添加到您的门户。请参阅添加自定义脚本。
将
cx
变量设置为您的 Google 搜索引擎 ID(例如e13bcb52d46f04dfd
),并将path
值设置为搜索页网址(例如/search
)。<script> window.portal = { pageEventListeners: { onLoad: (path) => { // Update with your search page URL if (path === '/your-search-page-URL') { // Add your Google search engine ID var cx = 'your-search-engine-id'; var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true; gcse.src = 'https://cse.google.com/cse.js?cx=' + cx; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s); gcse.onload = function () { var search = document.createElement('gcse:search'); // Note the element ID name var searchBox = document.getElementById('search-box'); searchBox.appendChild(search); }; } } } }; </script>
在门户中创建新的搜索页,并按照管理门户中的页面中的说明对其进行自定义。
在需要显示 Google 搜索框的位置,添加在自定义脚本中定义的自定义搜索元素 ID (
search-box
)。例如<div id="search-box"></div>
按照设置导航中的说明,将搜索页添加到门户导航中。
发布您的搜索页和导航更新。