Azure AI 搜尋服務的 OData 運算式語法參考
Azure AI 搜尋會使用 OData 運算式 作為整個 API 的參數。 最常用於和 $filter
參數的 $orderby
OData 表達式。 這些表達式可能相當複雜,包含多個子句、函式和運算符。 不過,即使是像屬性路徑這樣的簡單 OData 運算式,也會在 Azure AI 搜尋 REST API 的許多部分中使用。 例如,路徑表達式可用來參考 API 中任何地方的複雜字段子欄位,例如在建議工具中列出子字段、評分函式、$select
參數,甚至是 Lucene 查詢中的欄位搜尋時。
本文說明所有這些形式的 OData 運算式使用正式文法。 還有互動式 圖表 可協助以可視化方式探索文法。
正式文法
我們可以使用 EBNF (Extended Backus-Naur Form) 文法來描述 Azure AI 搜尋所支援的 OData 語言子集。 規則會以最複雜的表達式開頭列出「由上而下」,並將它們細分為更基本表達式。 頂端是對應至 Azure AI 搜尋服務 REST API 特定參數的文法規則:
$filter
,由filter_expression
規則定義。$orderby
,由order_by_expression
規則定義。$select
,由select_expression
規則定義。- 規則所
field_path
定義的欄位路徑。 整個 API 都會使用欄位路徑。 它們可以參考索引的最上層欄位,或具有一或多個 複雜欄位上階的子欄位 。
在EBNF是可 瀏覽的語法圖表 之後,可讓您以互動方式探索其規則之間的文法和關聯性。
/* Top-level rules */
filter_expression ::= boolean_expression
order_by_expression ::= order_by_clause(',' order_by_clause)*
select_expression ::= '*' | field_path(',' field_path)*
field_path ::= identifier('/'identifier)*
/* Shared base rules */
identifier ::= [a-zA-Z_][a-zA-Z_0-9]*
/* Rules for $orderby */
order_by_clause ::= (field_path | sortable_function) ('asc' | 'desc')?
sortable_function ::= geo_distance_call | 'search.score()'
/* Rules for $filter */
boolean_expression ::=
collection_filter_expression
| logical_expression
| comparison_expression
| boolean_literal
| boolean_function_call
| '(' boolean_expression ')'
| variable
/* This can be a range variable in the case of a lambda, or a field path. */
variable ::= identifier | field_path
collection_filter_expression ::=
field_path'/all(' lambda_expression ')'
| field_path'/any(' lambda_expression ')'
| field_path'/any()'
lambda_expression ::= identifier ':' boolean_expression
logical_expression ::=
boolean_expression ('and' | 'or') boolean_expression
| 'not' boolean_expression
comparison_expression ::=
variable_or_function comparison_operator constant |
constant comparison_operator variable_or_function
variable_or_function ::= variable | function_call
comparison_operator ::= 'gt' | 'lt' | 'ge' | 'le' | 'eq' | 'ne'
/* Rules for constants and literals */
constant ::=
string_literal
| date_time_offset_literal
| integer_literal
| float_literal
| boolean_literal
| 'null'
string_literal ::= "'"([^'] | "''")*"'"
date_time_offset_literal ::= date_part'T'time_part time_zone
date_part ::= year'-'month'-'day
time_part ::= hour':'minute(':'second('.'fractional_seconds)?)?
zero_to_fifty_nine ::= [0-5]digit
digit ::= [0-9]
year ::= digit digit digit digit
month ::= '0'[1-9] | '1'[0-2]
day ::= '0'[1-9] | [1-2]digit | '3'[0-1]
hour ::= [0-1]digit | '2'[0-3]
minute ::= zero_to_fifty_nine
second ::= zero_to_fifty_nine
fractional_seconds ::= integer_literal
time_zone ::= 'Z' | sign hour':'minute
sign ::= '+' | '-'
/* In practice integer literals are limited in length to the precision of
the corresponding EDM data type. */
integer_literal ::= sign? digit+
float_literal ::=
sign? whole_part fractional_part? exponent?
| 'NaN'
| '-INF'
| 'INF'
whole_part ::= integer_literal
fractional_part ::= '.'integer_literal
exponent ::= 'e' sign? integer_literal
boolean_literal ::= 'true' | 'false'
/* Rules for functions */
function_call ::=
geo_distance_call |
boolean_function_call
geo_distance_call ::=
'geo.distance(' variable ',' geo_point ')'
| 'geo.distance(' geo_point ',' variable ')'
geo_point ::= "geography'POINT(" lon_lat ")'"
lon_lat ::= float_literal ' ' float_literal
boolean_function_call ::=
geo_intersects_call |
search_in_call |
search_is_match_call
geo_intersects_call ::=
'geo.intersects(' variable ',' geo_polygon ')'
/* You need at least four points to form a polygon, where the first and
last points are the same. */
geo_polygon ::=
"geography'POLYGON((" lon_lat ',' lon_lat ',' lon_lat ',' lon_lat_list "))'"
lon_lat_list ::= lon_lat(',' lon_lat)*
search_in_call ::=
'search.in(' variable ',' string_literal(',' string_literal)? ')'
/* Note that it is illegal to call search.ismatch or search.ismatchscoring
from inside a lambda expression. */
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'"
語法圖表
若要以可視化方式探索 Azure AI 搜尋所支援的 OData 語言文法,請嘗試互動式語法圖表: