共用方式為


搜尋運算子

在多個數據表和數據行中搜尋文字模式。

注意

如果您知道想要搜尋的特定數據表和數據行,使用等位運算符會更有效能。 search當搜尋大量的數據表和數據行時,運算子可能會很慢。

語法

[T |] search [kind= CaseSensitivity ] [in (TableSources)] SearchPredicate

深入瞭解 語法慣例

參數

姓名 類型​​ 必要 描述
T string 要搜尋的表格式數據來源,例如數據表名稱、 等位運算符或表格式查詢的結果。 無法與 TableSources 一起出現。
CaseSensitivity string 旗標,控制所有 string 純量運算符的行為,例如 has,對於區分大小寫。 合法值為defaultcase_insensitivecase_sensitive 選項 defaultcase_insensitive 是同義字,因為預設行為不區分大小寫。
TableSources string 要參與搜尋的「通配符」數據表名稱逗號分隔清單。 此清單的語法與等位運算子的清單相同。 無法與 TabularSource 一起出現。
SearchPredicate string ✔️ 要針對輸入中每個記錄評估的布爾表達式。 如果傳回 true,則會輸出記錄。 請參閱 搜尋述詞語法

搜尋述詞語法

SearchPredicate 可讓您在資料表的所有數據行中搜尋特定字詞。 將套用至搜尋字詞的運算符取決於字詞中通配符星號 (*) 的存在和位置,如下表所示。

常值 運算子
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的記錄,以及數據行中的x123

注意

如果省略 TabularSourceTableSources,則搜尋會傳遍範圍中資料庫的所有不受限制的數據表和檢視表。

搜尋述詞語法範例

# 語法 意義(對等 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運算子不支援下列專案:

  1. withsource=:輸出一律會包含名為 $table string 的數據行,其值為從中擷取每個記錄的數據表名稱(如果來源不是數據表,而是復合表達式,則為某些系統產生的名稱)。
  2. project=project-smart輸出架構相當於 project-smart 輸出架構。

範例

搜尋範圍中資料庫的所有不受限制數據表和檢視的字詞。

search "Green"

輸出包含、 ProductsSalesTable 資料表中的Customers記錄。 記錄Customers會顯示姓氏為 「Green」 的所有客戶,而 和 記錄會顯示產品,其中ProductsSalesTable一些提及 「Green」。

搜尋符合範圍中資料庫所有不受限制數據表和檢視之字詞的記錄。

search "Green" and ("Deluxe" or "Proseware")

搜尋特定數據表

只在數據表中 Customers 搜尋。

search in (Products) "Green"

搜尋符合範圍中資料庫所有不受限制數據表和檢視之區分大小寫字詞的記錄。

search kind=case_sensitive "blue"

搜尋特定數據行

在範圍中所有不受限制的數據表和檢視表上,搜尋 「FirstName」 和 「LastName」 資料行中的字詞。

search FirstName:"Aaron" or LastName:"Hughes"

依時間戳限制搜尋

如果字詞出現在日期大於指定日期的記錄中,則搜尋範圍中資料庫的所有不受限制數據表和檢視的字詞。

search "Hughes" and DateKey > datetime('2009-01-01')

效能秘訣

# 提示 喜歡 目前超過
1 偏好使用單 search 一運算子超過數個連續 search 運算符 search "billg" and ("steveb" or "satyan") 搜尋 “billg” |搜尋 “steveb” 或 “satyan”
2 偏好在運算子內 search 篩選 search "billg" and "steveb" search * |其中 * 有 “billg” 且 * 有 “steveb”