5.6 Bindings for SPARQL Variables in Matching Subgraphs in a Document (SEM_CONTAINS_SELECT Ancillary Operator)
You can use the SEM_CONTAINS_SELECT ancillary operator to return additional information about each document matched using the SEM_CONTAINS operator.
Specifically, the bindings for the variables used in SPARQL-based document search criteria can be returned using this operator. This operator is ancillary to the SEM_CONTAINS operator, and a literal number is used as an argument to this operator to associate it with a specific instance of SEM_CONTAINS operator, as in the following example:
SELECT docId, SEM_CONTAINS_SELECT(1) as result FROM Newsfeed WHERE SEM_CONTAINS (article, '{ ?org rdf:type class:Organization . ?org pred:hasCategory cat:BusinessFinance }', .., 1)= 1;
The SEM_CONTAINS_SELECT ancillary operator returns the bindings for the variables in SPARQL Query Results XML format, as CLOB data. The variables may be bound to multiple data instances from a single document, in which case all bindings for the variables are returned. The following example is an excerpt from the output of the preceding query: a value returned by the SEM_CONTAINS_SELECT ancillary operator for a document matching the specified search criteria.
<results> <result> <binding name="ORG"> <uri>http://newscorp.com/Org/AcmeCorp</uri> </binding> </result> <result> <binding name="ORG"> <uri>http://newscorp.com/Org/ABCCorp</uri> </binding> </result> </results>
You can rank the search results by creating an instance of XMLType for the CLOB value returned by the SEM_CONTAINS_SELECT ancillary operator and applying an XPath expression to sort the results on some attribute values.
By default, the SEM_CONTAINS_SELECT ancillary operator returns bindings for all variables used in the SPARQL-based document search criteria. However, when the values for only a subset of the variables are relevant for a search, the SPARQL pattern can include a SELECT clause with space-separated list of variables for which the values should be returned, as in the following example:
SELECT docId, SEM_CONTAINS_SELECT(1) as result FROM Newsfeed WHERE SEM_CONTAINS (article, 'SELECT ?org ?city WHERE { ?org rdf:type class:Organization . ?org pred:hasLocation ?city . ?city geo:hasState state:NewHampshire }', .., 1) = 1;
Parent topic: Semantic Indexing for Documents