建立自訂搜尋網頁

您目前查看的是 Apigee Edge 說明文件。
參閱 Apigee X 說明文件
資訊

如要啟用入口網站中公開內容的搜尋功能,您可以建立專屬搜尋網頁,將 Google 自訂搜尋引擎 (CSE) 嵌入其中。舉例來說,下圖所示的入口網站嵌入了 Google CSE,能夠搜尋 Google 建立索引的內容。


搜尋頁面

如何建立自訂搜尋網頁:

  1. 發布您的入口網站內容
  2. 建立 Google 自訂搜尋引擎:
    a. 前往 Google 自訂搜尋設定頁面。
    b. 按一下 [新增] 來建立新的自訂搜尋引擎。

    c. 設定自訂搜尋引擎,並指明入口網站網站網域。請參閱 Google 自訂搜尋說明中的建立搜尋引擎一文。
    d. 使用 Google WebMaster 工具驗證並提交您的網站,加快網站索引速度。詳情請參閱 Google 自訂搜尋說明中的使用 Search Console 驗證網站一文。

  3. 將以下自訂指令碼新增至入口網站。請參閱「新增自訂指令碼」。

    cx 變數設為 Google 搜尋引擎 ID,並將 path 值設為搜尋網頁網址。

    <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>
    
  4. 在入口網站中建立新的搜尋頁面,並視需要加以自訂。請參閱「管理入口網站中的頁面」。

  5. 在自訂指令碼中定義的自訂搜尋元素 ID (search-box) 加到您希望 Google 搜尋框顯示的位置。 例如:

    <div id="search-box"></div>
    
  6. 視需要將搜尋頁面新增至入口網站導覽中。詳情請參閱「設定導覽」一文。

  7. 發布搜尋網頁和導覽的更新。