您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

结构化查询表达式Structured Query Expression

结构化查询表达式指定了一组要根据数据索引进行评估的操作。A structured query expression specifies a set of operations to evaluate against the data index. 它包含属性查询表达式和更高级别函数。It consists of attribute query expressions and higher-level functions. evaluate 方法可用于计算与表达式匹配的对象。Use the evaluate method to compute the objects matching the expression. 下面的示例来自学术出版物领域,它返回自 2013 年起由 Jaime Teevan 撰写的出版物。The following is an example from the academic publications domain that returns publications authored by Jaime Teevan since the year 2013.

And(Composite(Author.Name=='jaime teevan'),Y>=2013)

可通过 interpret 请求获取结构化查询表达式,其中每个解释的语义输出都是结构化查询表达式,用于返回与输入自然语言查询匹配的索引对象。Structured query expressions may be obtained from interpret requests, where the semantic output of each interpretation is a structured query expression that returns the index objects matching the input natural language query. 也可以使用本部分中的语法手动编写。Alternatively, they may be manually authored using the syntax described in this section.

属性查询表达式Attribute Query Expression

属性查询表达式确定了一组与特定属性匹配的对象。An attribute query expression identifies a set of objects based on matching against a specific attribute. 支持的匹配操作因架构中指定的属性类型和索引操作而异:Different matching operations are supported depending on the attribute type and indexed operation specified in the schema:

TypeType OperationOperation 示例Examples
StringString equalsequals Title='latent semantic analysis'(规范 + 同义词)Title='latent semantic analysis' (canonical + synonyms)
StringString equalsequals Author.Name=='susan t dumais'(仅规范)Author.Name=='susan t dumais' (canonical only)
StringString starts_withstarts_with Title='latent s'...Title='latent s'...
Int32/Int64/DoubleInt32/Int64/Double equalsequals Year=2000Year=2000
Int32/Int64/DoubleInt32/Int64/Double starts_withstarts_with Year='20'...(任何以“20”开头的十进制值)Year='20'... (any decimal value starting with "20")
Int32/Int64/DoubleInt32/Int64/Double is_betweenis_between Year<2000Year<2000
Year<=2000Year<=2000
Year>2000Year>2000
Year>=2000Year>=2000
Year=[2010,2012)(仅包括左边界值: 2010、2011)Year=[2010,2012) (includes only left boundary value: 2010, 2011)
Year=[2000,2012](包括两个边界值: 2010、2011、2012)Year=[2000,2012] (includes both boundary values: 2010, 2011, 2012)
DateDate equalsequals BirthDate='1984-05-14'BirthDate='1984-05-14'
DateDate is_betweenis_between BirthDate<='2008/03/14'BirthDate<='2008/03/14'
PublishDate=['2000-01-01','2009-12-31']PublishDate=['2000-01-01','2009-12-31']
GuidGuid equalsequals Id='602DD052-CC47-4B23-A16A-26B52D30C05B'Id='602DD052-CC47-4B23-A16A-26B52D30C05B'

例如,表达式“Title='latent s'...”匹配标题以字符串“latent s”开头的所有学术出版物。For example, the expression "Title='latent s'..." matches all academic publications whose title starts with the string "latent s". 属性 Title 必须在用于生成索引的架构中指定“starts_with”操作,才能评估此表达式。In order to evaluate this expression, the attribute Title must specify the "starts_with" operation in the schema used to build the index.

对于关联有同义词的属性,查询表达式可以使用“==”运算符指定规范值与给定字符串匹配的对象,也可以使用“=”运算符指定任意规范值/同义词值匹配的对象。For attributes with associated synonyms, a query expression may specify objects whose canonical value matches a given string using the "==" operator, or objects where any of its canonical/synonym values match using the "=" operator. 两者都需要在属性定义中指定“equals”运算符。Both require the "equals" operator to be specified in the attribute definition.

函数Functions

内置有一组函数,可便于通过基本属性查询构造更复杂的查询表达式。There is a built-in set of functions allowing the construction of more sophisticated query expressions from basic attribute queries.

And 函数And Function

And(expr1, expr2)

返回两个输入查询表达式的交集。Returns the intersection of the two input query expressions.

下面的示例返回 2000 年发表的与信息检索相关的学术出版物:The following example returns academic publications published in the year 2000 about information retrieval:

And(Year=2000, Keyword=='information retrieval')

Or 函数Or Function

Or(expr1, expr2)

返回两个输入查询表达式的并集。Returns the union of the two input query expressions.

下面的示例返回 2000 年发表的与信息检索或用户建模相关的学术出版物:The following example returns academic publications published in the year 2000 about information retrieval or user modeling:

And(Year=2000, Or(Keyword='information retrieval', Keyword='user modeling'))

Composite 函数Composite Function

Composite(expr)

返回封装内部表达式的表达式,内部表达式包含对常见复合属性的子属性执行的查询。Returns an expression that encapsulates an inner expression composed of queries against sub-attributes of a common composite attribute. 封装要求,任何匹配数据对象的复合属性至少必须有一个值单独满足内部表达式。The encapsulation requires the composite attribute of any matching data object to have at least one value that individually satisfies the inner expression. 请注意,必须使用 Composite() 函数封装对复合属性的子属性执行的查询表达式,然后才能将它与其他查询表达式结合使用。Note that a query expression on sub-attributes of a composite attribute has to be encapsulated using the Composite() function before it can be combined with other query expressions.

例如,下面的表达式返回就职于“microsoft”的“harry shum”的学术出版物:For example, the following expression returns academic publications by "harry shum" while he was at "microsoft":

Composite(And(Author.Name="harry shum", 
              Author.Affiliation="microsoft"))

相比之下,下面的表达式返回作者之一是“harry shum”且附属关系之一是“microsoft”的学术出版物:On the other hand, the following expression returns academic publications where one of the authors is "harry shum" and one of the affiliations is "microsoft":

And(Composite(Author.Name="harry shum"), 
    Composite(Author.Affiliation="microsoft"))