search 運算子
在多個數據表和數據行中搜尋文字模式。
注意
如果您知道想要搜尋的特定數據表和數據行,使用等位和運算符會更有效能。
search
當搜尋大量的數據表和數據行時,運算子可能會很慢。
語法
[T|
] search
[kind=
CaseSensitivity ] [in
(
TableSources)
] SearchPredicate
深入瞭解 語法慣例。
參數
姓名 | 類型 | 必要 | 描述 |
---|---|---|---|
T | string |
要搜尋的表格式數據來源,例如數據表名稱、 等位運算符或表格式查詢的結果。 無法與 TableSources一起指定。 | |
CaseSensitivity | string |
旗標,控制所有 string 純量運算符的行為,例如 has ,對於區分大小寫。 合法值為default 、 case_insensitive 、 case_sensitive 選項 default 和 case_insensitive 是同義字,因為預設行為不區分大小寫。 |
|
TableSources | string |
要參與搜尋的「通配符」數據表名稱逗號分隔清單。 此清單的語法與等位運算子的清單相同。 無法與表格式數據源一起指定 (T)。 | |
SearchPredicate | string |
✔️ | 要針對輸入中每個記錄評估的布爾表達式。 如果傳回 true ,則會輸出記錄。 請參閱 搜尋述詞語法。 |
注意
如果同時省略表格式數據源(T)和 TableSources,則搜尋會承載在範圍內資料庫的所有不受限制的數據表和檢視。
搜尋述詞語法
SearchPredicate 可讓您在資料表的所有數據行中搜尋特定字詞。 套用至搜尋字詞的運算符取決於字詞中通配符星號 (*
) 的存在和位置,如下表所示。
常值 | Operator |
---|---|
billg |
has |
*billg |
hassuffix |
billg* |
hasprefix |
*billg* |
contains |
bi*lg |
matches regex |
您也可以將搜尋限制為特定數據行、尋找完全相符專案,而不是字詞比對,或依正則表達式搜尋。 下表顯示上述每個案例的語法。
語法 | 說明 |
---|---|
ColumnName: StringLiteral |
此語法可用來將搜尋限制為特定數據行。 默認行為是搜尋所有數據行。 |
ColumnName== StringLiteral |
此語法可用來針對字串值搜尋數據行的完全相符專案。 默認行為是尋找字詞比對。 |
數據行matches regex StringLiteral |
此語法表示正則表達式比對,其中 StringLiteral 是 regex 模式。 |
使用布爾表達式結合條件並建立更複雜的搜尋。 例如,"error" and x==123
會產生搜尋任何數據行中字詞error
的記錄,以及數據行中的123
值x
。
搜尋述詞語法範例
# | 語法 | 意義(對等 where ) |
註解 |
---|---|---|---|
1 | search "err" |
where * has "err" |
|
2 | search in (T1,T2,A*) "err" |
union T1,T2,A* |其中 * 有 “err” |
|
3 | search col:"err" |
where col has "err" |
|
4 | search col=="err" |
where col=="err" |
|
5 | search "err*" |
where * hasprefix "err" |
|
6 | search "*err" |
where * hassuffix "err" |
|
7 | search "*err*" |
where * contains "err" |
|
8 | search "Lab*PC" |
where * matches regex @"\bLab.*PC\b" |
|
9 | search * |
where 0==0 |
|
10 | search col matches regex "..." |
where col matches regex "..." |
|
11 | search kind=case_sensitive |
所有字串比較都會區分大小寫 | |
12 | search "abc" and ("def" or "hij") |
where * has "abc" and (* has "def" or * has hij") |
|
13 | search "err" or (A>a and A<b) |
where * has "err" or (A>a and A<b) |
備註
不同於 find 運算子,search
運算符不支援下列語法:
-
withsource=
:輸出一律包含名為$table
類型的數據行string
,其值為從中擷取每個記錄的數據表名稱(如果來源不是數據表,而是複合表達式,則為某些系統產生的名稱)。 -
project=
,project-smart
輸出架構相當於project-smart
輸出架構。
範例
本節中的範例示範如何使用 語法來協助您開始使用。
本文中的範例會使用 說明叢集中公開可用的數據表,例如 Samples 資料庫中的
StormEvents
數據表。
本文中的範例會使用公開可用的數據表,例如天氣分析中的
StormEvents
數據表,範例數據。
全域字詞搜尋
在 ContosoSales 資料庫中的所有數據表中搜尋 Green 一詞。
輸出會尋找 綠色 一詞做為姓氏或 Customers
、Products
和 SalesTable
數據表中的色彩的記錄。
search "Green"
輸出
$table | CityName | ContinentName | CustomerKey | 教育 | FirstName | 性 | LastName |
---|---|---|---|---|---|---|---|
客戶 | 巴拉德 | 北美洲 | 16549 | 部分學院 | 石匠 | M | 綠 |
客戶 | 貝林厄姆 | 北美洲 | 2070 | 高中 | 亞當 | M | 綠 |
客戶 | 貝林厄姆 | 北美洲 | 10658 | 單身漢 | 薩拉 | F | 綠 |
客戶 | 貝弗利山 | 北美洲 | 806 | 研究生學位 | 理查 | M | 綠 |
客戶 | 貝弗利山 | 北美洲 | 7674 | 研究生學位 | 詹姆斯 | M | 綠 |
客戶 | 伯班克 | 北美洲 | 5241 | 研究生學位 | 馬德琳 | F | 綠 |
條件式全域字詞搜尋
在 contosoSales 資料庫中搜尋包含 Green 字詞和其中一個字詞 豪華 或 Proseware。
search "Green" and ("Deluxe" or "Proseware")
輸出
$table | ProductName | 製造者 | ColorName | ClassName | ProductCategoryName |
---|---|---|---|---|---|
產品 | Contoso 8GB 時鐘 & 無線電 MP3 播放器 X850 綠色 | Contoso, Ltd | 綠 | 豪華 | 音訊 |
產品 | 散文軟體掃描噴氣數位平面床掃描器 M300 綠色 | Proseware, Inc. | 綠 | 定期 | 計算機 |
產品 | Proseware All-In-One Photo Printer M200 Green | Proseware, Inc. | 綠 | 定期 | 計算機 |
產品 | Proseware Ink Jet Wireless All-In-One Printer M400 Green | Proseware, Inc. | 綠 | 定期 | 計算機 |
產品 | Proseware Ink Jet Instant PDF Sheet-Fed Scanner M300 Green | Proseware, Inc. | 綠 | 定期 | 計算機 |
產品 | Proseware Desk Jet All-in-One Printer, Scanner, Copier M350 Green | Proseware, Inc. | 綠 | 定期 | 計算機 |
產品 | Proseware 雙工掃描器 M200 綠色 | Proseware, Inc. | 綠 | 定期 | 計算機 |
搜尋特定數據表
只在 Customers
數據表中搜尋 Green 一詞。
search in (Products) "Green"
輸出
$table | ProductName | 製造者 | ColorName |
---|---|---|---|
產品 | Contoso 4G MP3 Player E400 Green | Contoso, Ltd | 綠 |
產品 | Contoso 8GB Super-Slim MP3/Video Player M800 Green | Contoso, Ltd | 綠 |
產品 | Contoso 16GB Mp5 Player M1600 Green | Contoso, Ltd | 綠 |
產品 | Contoso 8GB 時鐘 & 無線電 MP3 播放器 X850 綠色 | Contoso, Ltd | 綠 |
產品 | NT 無線藍牙立體聲耳機 M402 綠色 | Northwind Traders | 綠 |
產品 | NT 無線傳輸器和藍牙耳機 M150 綠色 | Northwind Traders | 綠 |
區分大小寫的搜尋
搜尋符合 ContosoSales 資料庫中區分大小寫字詞的記錄。
search kind=case_sensitive "blue"
輸出
$table | ProductName | 製造者 | ColorName | ClassName |
---|---|---|---|---|
產品 | Contoso 16GB 新一代 MP5 播放器 M1650 藍色 | Contoso, Ltd | 藍 | 定期 |
產品 | Contoso Bright Light battery E20 blue | Contoso, Ltd | 藍 | 經濟 |
產品 | Litware 120mm Blue LED Case Fan E901 blue | Litware, Inc. | 藍 | 經濟 |
NewSales | Litware 120mm Blue LED Case Fan E901 blue | Litware, Inc. | 藍 | 經濟 |
NewSales | Litware 120mm Blue LED Case Fan E901 blue | Litware, Inc. | 藍 | 經濟 |
NewSales | Litware 120mm Blue LED Case Fan E901 blue | Litware, Inc. | 藍 | 經濟 |
NewSales | Litware 120mm Blue LED Case Fan E901 blue | Litware, Inc. | 藍 | 經濟 |
搜尋特定數據行
在 ContosoSales 資料庫中,分別在 “FirstName” 和 “LastName” 數據行中搜尋 Aaron 和 Hughes字詞。
search FirstName:"Aaron" or LastName:"Hughes"
輸出
$table | CustomerKey | 教育 | FirstName | 性 | LastName |
---|---|---|---|---|---|
客戶 | 18285 | 高中 | 萊利 | F | 休斯 |
客戶 | 802 | 研究生學位 | 亞倫 | M | 夏爾馬 |
客戶 | 986 | 單身漢 | 梅蘭妮 | F | 休斯 |
客戶 | 12669 | 高中 | 潔西卡 | F | 休斯 |
客戶 | 13436 | 研究生學位 | Mariah | F | 休斯 |
客戶 | 10152 | 研究生學位 | 亞倫 | M | 坎貝爾 |
依時間戳限制搜尋
在 ContosoSales 資料庫中搜尋休斯 字詞,如果字詞出現在日期大於 'datetime' 中指定日期的記錄中。
search "Hughes" and DateKey > datetime('2009-01-01')
輸出
$table | DateKey | SalesAmount_real |
---|---|---|
SalesTable | 2021-12-13T00:00:00Z | 446.4715 |
SalesTable | 2021-12-13T00:00:00Z | 120.555 |
SalesTable | 2021-12-13T00:00:00Z | 48.4405 |
SalesTable | 2021-12-13T00:00:00Z | 39.6435 |
SalesTable | 2021-12-13T00:00:00Z | 56.9905 |
效能秘訣
# | 提示 | 喜歡 | 目前超過 |
---|---|---|---|
1 | 偏好使用單 search 一運算子超過數個連續 search 運算符 |
search "billg" and ("steveb" or "satyan") |
搜尋 “billg” |搜尋 “steveb” 或 “satyan” |
2 | 偏好在運算子內 search 篩選 |
search "billg" and "steveb" |
search * |其中 * 有 “billg” 且 * 有 “steveb” |