Azure AI Search の OData 式構文参照

Azure AI Search では、API 全体でパラメータとして OData 式が使用されます。 $orderby および $filter パラメーターに OData 式を使用するのが最も一般的です。 これらの式は、複数の句、関数、および演算子を含む複合式になることがあります。 ただし、プロパティ パスなどの単純な OData 式も、Azure AI Search REST API の多くの部分で使用されます。 たとえば、suggester 内のサブフィールドの一覧表示、スコアリング関数$select パラメーター、さらには Lucene クエリのフィールド化検索など、API のいたるところで、パス式を使用して複合フィールドのサブフィールドを参照します。

この記事では、これらすべての形式の OData 式について、正式な文法を使用して説明します。 文法を視覚的に調べるために役立つ対話形式のダイアグラムもあります。

正式な文法

EBNF (Extended Backus-Naur Form) 文法を使用して、Azure AI Search でサポートされる OData 言語のサブセットについて説明できます。 規則は "トップダウン" で列挙しています。最も複雑な式から始めて、よりプリミティブな式に分解していきます。 上部には、Azure AI Search REST API の特定のパラメータに対応する文法規則があります:

  • $filterfilter_expression 規則によって定義。
  • $orderbyorder_by_expression 規則によって定義。
  • $selectselect_expression 規則によって定義。
  • フィールド パス、field_path 規則によって定義。 フィールド パスは API 全体で使用されます。 インデックスの最上位フィールド、または 1 つ以上の複合フィールドを先祖に持つサブフィールドのいずれかを参照できます。

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 Search でサポートされている OData 言語文法を視覚的に調べるには、対話型の構文図を試してください:

関連項目