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. Use the evaluate method to compute the objects matching the expression. The following is an example from the academic publications domain that returns publications authored by Jaime Teevan since the year 2013.
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:
|String||equals||Title='latent semantic analysis' (canonical + synonyms)|
|String||equals||Author.Name=='susan t dumais' (canonical only)|
|Int32/Int64/Double||starts_with||Year='20'... (any decimal value starting with "20")|
Year=[2010,2012) (includes only left boundary value: 2010, 2011)
Year=[2000,2012] (includes both boundary values: 2010, 2011, 2012)
For example, the expression "Title='latent s'..." matches all academic publications whose title starts with the string "latent s". 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. Both require the "equals" operator to be specified in the attribute definition.
There is a built-in set of functions allowing the construction of more sophisticated query expressions from basic attribute queries.
Returns the intersection of the two input query expressions.
The following example returns academic publications published in the year 2000 about information retrieval:
And(Year=2000, Keyword=='information retrieval')
Returns the union of the two input query expressions.
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'))
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. 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.
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"))
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"))