command line tdbquery with text index

474 views Asked by At

I trying to run a text search query with Jena via command line.

tdbquery  --desc textsearch.ttl  --query search.rq  

The query return empty results with the messages:

17:23:46 WARN  TextQueryPF          :: Failed to find the text index :    tried context and as a text-enabled dataset
17:23:46 WARN  TextQueryPF          :: No text index - no text search performed

My assembler file is:

    @prefix :        <http://localhost/jena_example/#> .
  @prefix rdf:     <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
  @prefix rdfs:    <http://www.w3.org/2000/01/rdf-schema#> .
  @prefix tdb:     <http://jena.hpl.hp.com/2008/tdb#> .
  @prefix ja:      <http://jena.hpl.hp.com/2005/11/Assembler#> .
  @prefix text:    <http://jena.apache.org/text#> .

  ## Example of a TDB dataset and text index
  ## Initialize TDB
  [] ja:loadClass "org.apache.jena.tdb.TDB" .
  tdb:DatasetTDB  rdfs:subClassOf  ja:RDFDataset .
  tdb:GraphTDB    rdfs:subClassOf  ja:Model .

  ## Initialize text query
  [] ja:loadClass       "org.apache.jena.query.text.TextQuery" .
  # A TextDataset is a regular dataset with a text index.
  text:TextDataset      rdfs:subClassOf   ja:RDFDataset .
  # Lucene index
  text:TextIndexLucene  rdfs:subClassOf   text:TextIndex .
  # Solr index
  text:TextIndexSolr    rdfs:subClassOf   text:TextIndex .

  ## ---------------------------------------------------------------
  ## This URI must be fixed - it's used to assemble the text dataset.

  :text_dataset rdf:type     text:TextDataset ;
    text:dataset   <#dataset> ;
    text:index     <#indexLucene> ;
    .

  # A TDB datset used for RDF storage
  <#dataset> rdf:type      tdb:DatasetTDB ;
    tdb:location "DB2" ;
    tdb:unionDefaultGraph true ; # Optional
    .

  # Text index description
  <#indexLucene> a text:TextIndexLucene ;
    text:directory <file:Lucene2> ;
    ##text:directory "mem" ;
    text:entityMap <#entMap> ;
    .

  # Mapping in the index
  # URI stored in field "uri"
  # rdfs:label is mapped to field "text"
  <#entMap> a text:EntityMap ;
    text:entityField      "uri" ;
    text:defaultField     "text" ;
    text:map (
         [ text:field "text" ; text:predicate rdfs:label ]
         ) .

My query is :

  PREFIX text: <http://jena.apache.org/text#>
  PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

  SELECT ?s
  { ?s text:query 'London' ; 
       rdfs:label ?label 
  }

I would like to know if I miss any configuration or this query can only be done inside fuseki.

1

There are 1 answers

0
berezovskyi On

First, you can do text search outside Fuseki. The example you took the code from shows how to do this using plain Jena Dataset in Java.

Second, Andy Seaborne on Jena mailing list suggests the following:

SELECT (count(*) AS ?C) { ?x text:query .... }

in order to "touch" the index before running the real queries.