Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
在多个表和列中搜索文本模式。
语法
[T|] search [kind=CaseSensitivity ] [in(TableSources)] SearchPredicate
详细了解语法约定。
参数
| 客户 | 类型 | 必需 | 说明 |
|---|---|---|---|
| T | string |
要搜索的表格数据源,例如表名、union 运算符或表格查询的结果。 不能与 TableSources 一起指定。 | |
| CaseSensitivity | string |
一个标志,它控制所有 string 标量运算符(例如 has)在区分大小写方面的行为。 有效值为 default、case_insensitive、case_sensitive。 选项 default 和 case_insensitive 同义,因为默认行为是不区分大小写。 |
|
| TableSources | string |
要参与搜索的“带通配符的”表名的逗号分隔列表。 此列表具有与 union 运算符列表相同的语法。 不能与表格数据源(T)一起指定。 | |
| SearchPredicate | string |
✔️ | 要对输入中的每个记录计算的布尔表达式。 如果它返回 true,则输出记录。 请参阅搜索谓词语法。 |
注意
如果省略表格数据源(T)和 TableSources ,则搜索将覆盖范围内数据库的所有不受限制的表和视图。
搜索谓词语法
使用 SearchPredicate 可以搜索所有表列中的特定字词。 应用于搜索词的运算符取决于术语中通配符星号(*)的存在和位置,如下表所示。
| 文本 | 运算符 |
|---|---|
billg |
has |
*billg |
hassuffix |
billg* |
hasprefix |
*billg* |
contains |
bi*lg |
matches regex |
还可以将搜索限制为特定的列,查找完全匹配项而不是字词匹配项,或者按正则表达式进行搜索。 下表显示了其中每个案例的语法。
| 语法 | 说明 |
|---|---|
| ColumnNameStringLiteral | 此语法可用于将搜索限制为特定的列。 默认行为是搜索所有列。 |
| ColumnNameStringLiteral | 此语法可用于根据字符串值搜索列的完全匹配项。 默认行为是查找字词匹配项。 |
列matches regexStringLiteral |
此语法指示正则表达式匹配,其中 StringLiteral 是正则表达式模式。 |
使用布尔表达式合并条件并创建更复杂的搜索。 例如,"error" and x==123 将搜索在任何列中具有字词 error 且在 123 列中具有值 x 的记录。
搜索谓词语法示例
| # | 语法 | 含义(等效的 where) |
注释 |
|---|---|---|---|
| 1 | search "err" |
where * has "err" |
|
| 2 | search in (T1,T2,A*) "err" |
并集 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:search运算符不支持自定义输出列的这些选项。 相反,它会自动为输出选择一组相关的列,这相当于运算符中project-smart选项检索find的列集。
示例
本文中的示例使用 帮助群集中的公开可用表,例如
StormEvents数据库中的 表。
下面的示例演示如何执行全局术语搜索。 在 ContosoSales 数据库的所有表中搜索术语 Green。
输出查找字词绿色为姓氏或表中颜色CustomersProducts的SalesTable记录。
search "Green"
输出
| $table | CityName | ContinentName | 客户密钥 | 教育 | 名字 | 性别 | LastName |
|---|---|---|---|---|---|---|---|
| 客户 | 巴拉德 | 北美洲 | 16549 | 部分学院 | 石匠 | M | 绿色 |
| 客户 | 贝灵厄姆 | 北美洲 | 2070 | 高中 | 亚当 | M | 绿色 |
| 客户 | 贝灵厄姆 | 北美洲 | 10658 | 学士学位 / 单身汉 | 萨拉 | F | 绿色 |
| 客户 | 贝弗利山 | 北美洲 | 806 | 研究生学位 | 理查 | M | 绿色 |
| 客户 | 贝弗利山 | 北美洲 | 7674 | 研究生学位 | 詹姆斯 | M | 绿色 |
| 客户 | 伯班克 | 北美洲 | 5241 | 研究生学位 | 马德琳 | F | 绿色 |
以下示例演示如何执行条件全局术语搜索。 在 ContosoSales 数据库中搜索包含术语 Green 和术语之一的“豪华”或“散文件”的记录。
search "Green" and ("Deluxe" or "Proseware")
输出
| $table | ProductName | 制造者 | ColorName | ClassName | 产品类别名称 |
|---|---|---|---|---|---|
| 产品 | Contoso 8GB 时钟和无线电 MP3 播放器 X850 绿色 | Contoso, Ltd | 绿色 | 豪华 | 音频 |
| 产品 | Proseware Scan Jet Digital Flat Bed Scanner M300 Green | 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 即时 PDF Sheet-Fed 扫描仪 M300 绿色 | Proseware, Inc. | 绿色 | 常规的 | 计算机 |
| 产品 | Proseware Desk Jet 全能打印机、扫描仪、复制器 M350 绿色 | Proseware, Inc. | 绿色 | 常规的 | 计算机 |
| 产品 | Proseware 双工扫描仪 M200 绿色 | Proseware, Inc. | 绿色 | 常规的 | 计算机 |
以下示例演示如何搜索特定表中的术语。
仅在表中搜索Customers”一词。
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 交易者 | 绿色 |
| 产品 | NT 无线发射器和蓝牙耳机 M150 绿色 | Northwind 交易者 | 绿色 |
以下示例演示如何搜索区分大小写的术语。 搜索与 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 | 客户密钥 | 教育 | 名字 | 性别 | LastName |
|---|---|---|---|---|---|
| 客户 | 18285 | 高中 | 莱利 | F | 休斯 |
| 客户 | 802 | 研究生学位 | 亚伦 | M | 夏尔马 |
| 客户 | 986 | 学士学位 / 单身汉 | 梅兰妮 | F | 休斯 |
| 客户 | 12669 | 高中 | 杰西卡 | F | 休斯 |
| 客户 | 13436 | 研究生学位 | 玛丽亚 | F | 休斯 |
| 客户 | 10152 | 研究生学位 | 亚伦 | M | 坎贝尔 |
以下示例演示如何使用时间戳搜索字词。 在 ContosoSales 数据库中搜索术语 Hughes,如果术语出现在日期大于给定日期的记录中,则为“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" |
搜索 * | 其中 * 有 "billg";* 有 "steveb" |