Azure AI 搜尋服務中的 OData 全文檢索搜尋函式:search.ismatch 與 search.ismatchscoring

附註

Azure AI 搜尋服務 可透過 Azure 入口網站、REST API 及 Azure SDK 取得。 它同時也是 Foundry IQ 的基礎,這是一個管理式知識層,能將企業內容轉化為可重複使用、權限感知的知識庫,供 Microsoft Foundry 入口網站中的代理使用。

Azure AI 搜尋服務在 OData 篩選運算式的內容中支援全文檢索搜尋,透過 search.ismatch 與 search.ismatchscoring 函式提供。 這些功能允許你將全文搜尋與嚴格的布林篩選結合,這是僅靠search 頂層參數無法做到的。

附註

search.ismatch 與 search.ismatchscoring 函式僅支援用於 Search API 的篩選條件。 它們不被 建議 或 自動補全 API 支援。

語法

下列 EBNF (延伸巴科斯諾爾范式) 定義了 search.ismatch 與 search.ismatchscoring 函式的文法:

search_is_match_call ::=
    'search.ismatch'('scoring')?'(' search_is_match_parameters ')'

search_is_match_parameters ::=
    string_literal(',' string_literal(',' query_type ',' search_mode)?)?

query_type ::= "'full'" | "'simple'"

search_mode ::= "'any'" | "'all'"

也提供互動式語法圖:

附註

如需完整的 EBNF,請參閱 Azure AI 搜尋服務的 OData 運算式語法參考。

search.ismatch

search.ismatch 函式會將全文檢索搜尋查詢評估為篩選運算式的一部分。 匹配的文件會顯示在結果集中。 此函式提供下列多載:

  • search.ismatch(search)
  • search.ismatch(search, searchFields)
  • search.ismatch(search, searchFields, queryType, searchMode)

參數定義如下表所示:

參數名稱 類型 描述
search Edm.String 搜尋查詢 (使用簡單或完整 Lucene 查詢語法)。
searchFields Edm.String 要搜尋的可搜尋欄位清單,以逗號分隔;預設為索引中所有可搜尋欄位。 當你在參數中使用欄位搜尋search時,Lucene 查詢中的欄位指定符會覆蓋該參數中指定的欄位。
queryType Edm.String 'simple' 或 'full';預設為 'simple'。 指定 search 參數所使用的查詢語言。
searchMode Edm.String 'any' 或 'all';預設為 'any'。 指出在 search 參數中的搜尋字詞必須符合任一字詞或全部字詞,文件才會視為符合。 當你在參數中使用盧辛布林運算子search時,它們會優先於該參數。

上述所有參數都等同於 Search API 中對應的搜尋要求參數。

該search.ismatch函式回傳一個Edm.Boolean類型的值,這讓你能利用布林邏輯運算符與其他篩選子表達式組合。

附註

Azure AI 搜尋服務 不支援在 lambda 表達式中使用 search.ismatch 或 search.ismatchscoring。 這表示無法在物件集合上寫過濾器,將全文搜尋匹配與同一物件的嚴格篩選匹配相關聯。 關於此限制的更多資訊及範例,請參閱 Azure AI 搜尋服務 中的故障排除集合篩選器。 如需更深入了解此限制存在的原因,請參閱了解 Azure AI 搜尋服務中的集合篩選條件。

search.ismatchscoring

search.ismatchscoring 函式與 search.ismatch 函式類似,會針對符合以參數傳入之全文檢索搜尋查詢的文件傳回 true。 兩者的差異在於,匹配 search.ismatchscoring 查詢的文件相關性分數會影響整體文件分數,而對於 search.ismatch,文件分數則不會改變。 此函式提供下列多載,參數與 search.ismatch 相同:

  • search.ismatchscoring(search)
  • search.ismatchscoring(search, searchFields)
  • search.ismatchscoring(search, searchFields, queryType, searchMode)

您可以在同一個篩選運算式中同時使用 search.ismatch 與 search.ismatchscoring 函式。

範例

尋找包含「waterfront」一詞的文件。 此篩選查詢等同於使用 的search=waterfront。

    search.ismatchscoring('waterfront')

以下是這個請求的完整查詢語法,你可以在 Azure 入口網站的搜尋總管中執行。 輸出包含對 waterfront、water 與 front 的符合項目。

{
  "search": "*",
  "select": "HotelId, HotelName, Description",
  "searchMode": "all",
  "queryType": "simple",
  "count": true,
  "filter": "search.ismatchscoring('waterfront')"
}

尋找包含「pool」一詞且評分大於或等於 4 分的文件,或包含「motel」一詞且評分為 3.2 的文件。 請注意,這個請求無法在沒有這個 search.ismatchscoring 函數的情況下表達。

    search.ismatchscoring('pool') and Rating ge 4 or search.ismatchscoring('motel') and Rating eq 3.2

以下是搜尋瀏覽器這次請求的完整查詢語法。 輸出包含符合條件的項目:具有集區且評等大於 4 的旅館,或評等等於 3.2 的汽車旅館。

{
  "search": "*",
  "select": "HotelId, HotelName, Description, Tags, Rating",
  "searchMode": "all",
  "queryType": "simple",
  "count": true,
  "filter": "search.ismatchscoring('pool') and Rating ge 4 or search.ismatchscoring('motel') and Rating eq 3.2"
}

尋找不包含「luxury」一詞的文件。

    not search.ismatch('luxury')

以下是這個請求的完整查詢語法。 輸出包含對「奢華」一詞的匹配結果。

{
  "search": "*",
  "select": "HotelId, HotelName, Description, Tags, Rating",
  "searchMode": "all",
  "queryType": "simple",
  "count": true,
  "filter": "not search.ismatch('luxury')"
}

尋找帶有「海洋」字樣或評分為3.2的文件。 search.ismatchscoring查詢僅對欄位 HotelName 和 Description執行。

以下是這個請求的完整查詢語法。 也會傳回只符合析取第二個子句的文件 (具體而言,Rating 等於 3.2 的旅館)。 為了明確表示這些文件與表達式中任何評分部分不符,並以分數為零回傳。

{
  "search": "*",
  "select": "HotelId, HotelName, Description, Rating",
  "searchMode": "all",
  "queryType": "full",
  "count": true,
  "filter": "search.ismatchscoring('ocean', 'Description,HotelName') or Rating eq 3.2"
}

輸出包含4個匹配:描述或飯店名稱中提及「海洋」的飯店,或評分為3.2的飯店。 請注意,第二個子句匹配的搜尋結果分數為零。

{
  "@odata.count": 4,
  "value": [
    {
      "@search.score": 1.6076145,
      "HotelId": "18",
      "HotelName": "Ocean Water Resort & Spa",
      "Description": "New Luxury Hotel for the vacation of a lifetime. Bay views from every room, location near the pier, rooftop pool, waterfront dining & more.",
      "Rating": 4.2
    },
    {
      "@search.score": 1.0594962,
      "HotelId": "41",
      "HotelName": "Windy Ocean Motel",
      "Description": "Oceanfront hotel overlooking the beach features rooms with a private balcony and 2 indoor and outdoor pools. Inspired by the natural beauty of the island, each room includes an original painting of local scenes by the owner. Rooms include a mini fridge, Keurig coffee maker, and flatscreen TV. Various shops and art entertainment are on the boardwalk, just steps away.",
      "Rating": 3.5
    },
    {
      "@search.score": 0,
      "HotelId": "40",
      "HotelName": "Trails End Motel",
      "Description": "Only 8 miles from Downtown. On-site bar/restaurant, Free hot breakfast buffet, Free wireless internet, All non-smoking hotel. Only 15 miles from airport.",
      "Rating": 3.2
    },
    {
      "@search.score": 0,
      "HotelId": "26",
      "HotelName": "Planetary Plaza & Suites",
      "Description": "Extend Your Stay. Affordable home away from home, with amenities like free Wi-Fi, full kitchen, and convenient laundry service.",
      "Rating": 3.2
    }
  ]
}

找一些「飯店」和「機場」這兩個詞在飯店描述中相距不到5個字,且至少部分房間禁止吸菸的文件。

    search.ismatch('"hotel airport"~5', 'Description', 'full', 'any') and Rooms/any(room: not room/SmokingAllowed)

以下是完整的查詢語法。 若要在 Search Explorer 中執行,請使用反斜線字元逸出內部引號。

{
  "search": "*",
  "select": "HotelId, HotelName, Description, Tags, Rating",
  "searchMode": "all",
  "queryType": "simple",
  "count": true,
  "filter": "search.ismatch('\"hotel airport\"~5', 'Description', 'full', 'any') and Rooms/any(room: not room/SmokingAllowed)"
}

輸出包含單一文件,其中「hotel」與「airport」兩個詞在 5 個字距內。 大多數飯店允許吸菸,包括這個搜尋結果中的飯店。

{
  "@odata.count": 1,
  "value": [
    {
      "@search.score": 1,
      "HotelId": "40",
      "HotelName": "Trails End Motel",
      "Description": "Only 8 miles from Downtown. On-site bar/restaurant, Free hot breakfast buffet, Free wireless internet, All non-smoking hotel. Only 15 miles from airport.",
      "Tags": [
        "bar",
        "free wifi",
        "restaurant"
      ],
      "Rating": 3.2
    }
  ]
}

尋找在 Description 欄位中,以「lux」字母開頭的字詞之文件。 此查詢會搭配 使用search.ismatch。

    search.ismatch('lux*', 'Description')

以下是完整的查詢:

{
  "search": "*",
  "select": "HotelId, HotelName, Description, Tags, Rating",
  "searchMode": "all",
  "queryType": "simple",
  "count": true,
  "filter": "search.ismatch('lux*', 'Description')"
}

輸出包含下列符合項目。

{
  "@odata.count": 4,
  "value": [
    {
      "@search.score": 1,
      "HotelId": "18",
      "HotelName": "Ocean Water Resort & Spa",
      "Description": "New Luxury Hotel for the vacation of a lifetime. Bay views from every room, location near the pier, rooftop pool, waterfront dining & more.",
      "Tags": [
        "view",
        "pool",
        "restaurant"
      ],
      "Rating": 4.2
    },
    {
      "@search.score": 1,
      "HotelId": "13",
      "HotelName": "Luxury Lion Resort",
      "Description": "Unmatched Luxury. Visit our downtown hotel to indulge in luxury accommodations. Moments from the stadium and transportation hubs, we feature the best in convenience and comfort.",
      "Tags": [
        "bar",
        "concierge",
        "restaurant"
      ],
      "Rating": 4.1
    },
    {
      "@search.score": 1,
      "HotelId": "16",
      "HotelName": "Double Sanctuary Resort",
      "Description": "5 star Luxury Hotel - Biggest Rooms in the city. #1 Hotel in the area listed by Traveler magazine. Free WiFi, Flexible check in/out, Fitness Center & espresso in room.",
      "Tags": [
        "view",
        "pool",
        "restaurant",
        "bar",
        "continental breakfast"
      ],
      "Rating": 4.2
    },
    {
      "@search.score": 1,
      "HotelId": "14",
      "HotelName": "Twin Vortex Hotel",
      "Description": "New experience in the making. Be the first to experience the luxury of the Twin Vortex. Reserve one of our newly-renovated guest rooms today.",
      "Tags": [
        "bar",
        "restaurant",
        "concierge"
      ],
      "Rating": 4.4
    }
  ]
}

後續步驟