在 SPARQL 中,我可以执行以下查询以检索一个查询结果中的字段和总数:
SELECT ?total ?s
WHERE
{
{ SELECT (COUNT(?s) AS ?total)
WHERE
{ ?s <https://some/predicate/for/var1> ?var1 ;
<https://some/predicate/for/var1> ?var2
FILTER ( ( ?var1 = "something" ) && ( ?var2 = "something2" ) )
}
}
{ SELECT ?s
WHERE
{ ?s <https://some/predicate/for/var1> ?var1 ;
<https://some/predicate/for/var1> ?var2
FILTER ( ( ?var1 = "something" ) && ( ?var2 = "something2" ) )
}
LIMIT 3
}
}
它返回类似这样的内容(s 字段与我在查询中提供的特定谓词和过滤器匹配):
+-------+----------------------------------------+
| total | s |
+-------+----------------------------------------+
| 150 | http://the/path/to/the/subject |
| 150 | http://the/path/to/another/subject |
| 150 | http://the/path/to/yet/another/subject |
+-------+----------------------------------------+
我想对全文搜索查询做同样的事情,可以按如下方式使用?s bds:search “something” .
但是,用与前一个相同的结构组成一个查询是行不通的:
PREFIX bds: <http://www.bigdata.com/rdf/search#>
SELECT ?total ?s ?org
WHERE
{
{ SELECT (COUNT(?s) AS ?total)
WHERE{
?matchedValue
bds:search "something" ;
bds:relevance ?score ;
bds:rank ?rank .
?s ?matchedProperty ?matchedValue
FILTER ( ! isBlank(?s) )
}
}
{ SELECT ?s ?matchedProperty ?score ?rank
WHERE{
?matchedValue
bds:search "something" ;
bds:relevance ?score ;
bds:rank ?rank .
?s ?matchedProperty ?matchedValue
FILTER ( ! isBlank(?s) )
}
LIMIT 10
}
}
即使这些子查询分别返回正确的结果。