Blazegraph全文搜索总计数

时间:2017-09-07 12:22:47

标签: sparql blazegraph

在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 |
+-------+----------------------------------------+

我想对full text search queries执行相同操作,可以按照以下方式使用?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 
 }
}

即使这些子查询单独返回正确的结果。

1 个答案:

答案 0 :(得分:2)

正如@ stanislav-kralin正确提到并来自issue in Jira,你必须明确使用SERVICE子句:

PREFIX  bds:  <http://www.bigdata.com/rdf/search#>
SELECT  ?total ?s ?org
WHERE
{
  { SELECT  (COUNT(?s) AS ?total)
      WHERE {
         SERVICE <http://www.bigdata.com/rdf/search#search> {
              ?matchedValue
                        bds:search        "something" ;
                        bds:relevance     ?score ;
                        bds:rank          ?rank .
          }
          ?s        ?matchedProperty  ?matchedValue
          FILTER ( ! isBlank(?s) )
        }
}
  { SELECT  ?s ?matchedProperty ?score ?rank
      WHERE {
         SERVICE <http://www.bigdata.com/rdf/search#search> {
            ?matchedValue
                  bds:search        "something" ;
                  bds:relevance     ?score ;
                  bds:rank          ?rank .
          }
          ?s        ?matchedProperty  ?matchedValue
          FILTER ( ! isBlank(?s) )
        }
      LIMIT 10 
 }
}