Blazegraph full text search with total count

770 views Asked by At

In SPARQL I can perform the following query in order to retrieve the fields and the total count in one query result:

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
  }
 }

Which returns something like this (s fields matched the specific predicate and filter I provided on the query):

+-------+----------------------------------------+
| total |                   s                    |
+-------+----------------------------------------+
|   150 | http://the/path/to/the/subject         |
|   150 | http://the/path/to/another/subject     |
|   150 | http://the/path/to/yet/another/subject |
+-------+----------------------------------------+

I want to do the same for full text search queries, which can be used as follows ?s bds:search “something” . However, composing a query with the same structure as the previous one, does not work:

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 
 }
}

Even though, those subqueries return the correct result separately.

1

There are 1 answers

0
Didac Montero On

As correctly mentioned by @stanislav-kralin and coming from the issue in Jira, you have to explicitly use SERVICE clause:

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 
 }
}