SharePoint Search排除搜尋內容驗證


Posted by 江馬特 on 2024-01-07

前言

本身並沒有什麼使用SharePoint的經驗

只是SharePoint On-premises版本已經步入黃昏

再不來玩玩大概就沒機會了

碰上情境題「將SharePoint作為站內搜尋引擎時,如何排除搜尋內容?

雖然是個已經被前人解過的題目,但還是來測試一下有沒有其它的可能性可以執行

前期準備

只是玩票性質的測試,測試情境使用現有的Hyper-V虛擬機搭建模擬內網環境

伺服器

  1. Domain Controller (Windows Server 2019)- SharePoint許多功能或權限都與AD帳戶息息相關(微軟安裝說明文件也是寫出需要AD帳戶)
  2. Database (Windows Server 2022) - 使用 MS SqlServer 2022 做為資料庫
  3. SharePoint Server (Windows Server 2019) - SharePoint Server 2019,只有安裝Search Service
  4. Web Server (Windows Server 2019) - 使用IIS建立簡易的靜態檔案網站

靜態檔案

  1. Index.html
     <!DOCTYPE html>
     <html lang="zh-hant-tw">
       <head>
         <meta charset="UTF-8" />
         <meta name="viewport" content="width=device-width, initial-scale=1.0" />
         <title>首頁</title>
       </head>
       <body>
         <h1>這是首頁</h1>
         <p>這是測試首頁</p>
         <p class="noindex">Search This</p>
         <div style="display: none">
           No Display
           <p>Hidden Inside</p>
         </div>
         <p>Show Display</p>
         <a href="/sub.html">Sub</a>
       </body>
     </html>
    
  2. Sub.html
     <!DOCTYPE html>
     <html lang="zh-hant-tw">
       <head>
         <meta charset="UTF-8" />
         <meta name="viewport" content="width=device-width, initial-scale=1.0" />
         <title>Sub</title>
       </head>
       <body>
         <h1>這是Sub首頁</h1>
         <p>這是測試Sub首頁</p>
         <p class="noindex">Search This</p>
         <div style="display: none">
           No Display
           <p>Hidden Inside</p>
         </div>
         <p>Show Display</p>
         <a href="/index.html">main</a>
       </body>
     </html>
    

Tool

  1. SharePoint Search Query Tool - 無腦測試SharePoint搜尋的好工具

情境

使用SharePoint Search建立外部網站資料源,並且搜尋關鍵字

測試

搜尋「Search」

這個條件是我想做這次lib的原因,其實找的到在早期版本的SharePoint中,加入class為noindex是可以不被索引到的相關文件,但似乎是用在SharePoint網站使用的Webpart,那用在外部網站做為內容來源時還有沒有用處?

結論:無效,我想連帶是否包含遞迴子節點都不用繼續測試了
關鍵字Search

搜尋「Display」、「Hidden」

「Display」為測試style="display: none"inline樣式的關鍵字

結論:有效,並且連帶遞迴子節點也可被排除
關鍵字Display

搜尋「Hidden」為無結果
關鍵字Hidden

額外加碼

SharePoint Search可以建立多組資料來源,在這邊又另外簡單建了一頁與設定不同Domain提供給SharePoint去建立Index

多組資料源

SharePoint Search預設動作很理所當然為搜尋全部來源

搜尋全部來源

可以使用site:"{path}"來做篩選,就可以做出依照路徑的搜尋方式

site參數

結論

其實找一找資料就會發現要讓SharePoint Search不做Index的方式,直接明瞭的方式就是針對SharePoint來的爬蟲UserAgent送來請求時,將不需要建立Index的內容直接做不顯示或是直接不輸出就可以。

但使用SharePoint Search在建立網頁搜尋時有許多的缺點

  1. 使用HTML Raw Value文字搜尋,對於現在前端渲染動作無法做出反應(如Lazy Loading)
  2. 排除Index內容不是從SharePoint建立規則,反而較多文章建議是從修改Response上著手

SharePoint雖然有良好的文件知識管理系統

但搜尋功能對於網頁的部分看起來僅適用於純Server Side Rendering(SSR)的模式

如果是為了使用者體驗做部分更新渲染的頁面

則看的出來SharePoint只有對一開始的HTML做了Index

沒有辦法做出完整內容的Index,不太適用

參考

  1. SharePoint Server 2019
  2. 在單一伺服器上安裝 SharePoint Server 2016 或 2019
  3. 在 SharePoint Server 中初次部署管理帳戶和服務帳戶
  4. SharePoint Search Query Tool
  5. Hiding content from search results by using “display:none or noindex” in Sharepoint Search 2013
  6. Keyword queries and search conditions for eDiscovery

#sharepoint #SharePoint Search







Related Posts

Mongoose - To-Do-List v2

Mongoose - To-Do-List v2

Request 額外補充

Request 額外補充

[11] 模組 Module

[11] 模組 Module


Comments