You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2013/12/09 15:01:08 UTC

svn commit: r1549572 - in /jena/trunk/jena-text/src/main/java: jena/ org/apache/jena/query/text/

Author: andy
Date: Mon Dec  9 14:01:08 2013
New Revision: 1549572

URL: http://svn.apache.org/r1549572
Log:
Fixes for blank node subjects.
General tidying up.

Modified:
    jena/trunk/jena-text/src/main/java/jena/textindexer.java
    jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/Entity.java
    jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerEntities.java
    jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerTriples.java
    jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
    jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java
    jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextQuery.java

Modified: jena/trunk/jena-text/src/main/java/jena/textindexer.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-text/src/main/java/jena/textindexer.java?rev=1549572&r1=1549571&r2=1549572&view=diff
==============================================================================
--- jena/trunk/jena-text/src/main/java/jena/textindexer.java (original)
+++ jena/trunk/jena-text/src/main/java/jena/textindexer.java Mon Dec  9 14:01:08 2013
@@ -32,7 +32,6 @@ import arq.cmdline.CmdARQ ;
 import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.query.Dataset ;
 import com.hp.hpl.jena.sparql.core.Quad ;
-import com.hp.hpl.jena.sparql.util.FmtUtils ;
 
 /**
  * Text indexer application that will read a dataset and index its triples in
@@ -122,7 +121,7 @@ public class textindexer extends CmdARQ 
             Iterator<Quad> quadIter = dataset.find(Node.ANY, Node.ANY, property, Node.ANY) ;
             for (; quadIter.hasNext();) {
                 Quad quad = quadIter.next() ;
-                Entity entity = createEntity(quad) ;
+                Entity entity = TextQuery.entityFromQuad(entityDefinition, quad) ;
                 if (entity != null) {
                     textIndex.addEntity(entity) ;
                     progressMonitor.progressByOne() ;
@@ -142,30 +141,6 @@ public class textindexer extends CmdARQ 
         return result ;
     }
 
-    private Entity createEntity(Quad quad) {
-        Node s = quad.getSubject() ;
-        String x = (s.isURI()) ? s.getURI() : s.getBlankNodeLabel() ;
-        Entity result = new Entity(x) ;
-        Node p = quad.getPredicate() ;
-        String field = entityDefinition.getField(p) ;
-        if (field == null)
-            return null ;
-        Node o = quad.getObject() ;
-        String val = null ;
-        if (o.isURI())
-            val = o.getURI() ;
-        else
-            if (o.isLiteral())
-                val = o.getLiteralLexicalForm() ;
-            else {
-                log.warn("Not a literal value for mapped field-predicate: " + field + " :: "
-                         + FmtUtils.stringForString(field)) ;
-                return null ;
-            }
-        result.put(field, val) ;
-        return result ;
-    }
-
     // TDBLoader has a similar progress monitor
     // Not used here to avoid making ARQ dependent on TDB
     // So potential to rationalise and put progress monitor in a common

Modified: jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/Entity.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/Entity.java?rev=1549572&r1=1549571&r2=1549572&view=diff
==============================================================================
--- jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/Entity.java (original)
+++ jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/Entity.java Mon Dec  9 14:01:08 2013
@@ -32,6 +32,8 @@ public class Entity
         this.graph = entityGraph;
     }
 
+    /** @deprecated Use {@linkplain #Entity(String, String)} */
+    @Deprecated
     public Entity(String entityId)          { this(entityId, null) ; }
     
     public String getId()                   { return id ; }

Modified: jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerEntities.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerEntities.java?rev=1549572&r1=1549571&r2=1549572&view=diff
==============================================================================
--- jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerEntities.java (original)
+++ jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerEntities.java Mon Dec  9 14:01:08 2013
@@ -16,81 +16,78 @@
  * limitations under the License.
  */
 
-package org.apache.jena.query.text;
+package org.apache.jena.query.text ;
 
 import java.util.List ;
 
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.iterator.Transform ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
 import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
 import com.hp.hpl.jena.sparql.core.DatasetChangesBatched ;
 import com.hp.hpl.jena.sparql.core.Quad ;
 import com.hp.hpl.jena.sparql.core.QuadAction ;
 import com.hp.hpl.jena.sparql.util.FmtUtils ;
 
-public class TextDocProducerEntities extends DatasetChangesBatched implements TextDocProducer
-{
-    private static Logger log = LoggerFactory.getLogger(TextDocProducer.class) ;
+public class TextDocProducerEntities extends DatasetChangesBatched implements TextDocProducer {
+    private static Logger          log     = LoggerFactory.getLogger(TextDocProducer.class) ;
     private final EntityDefinition defn ;
-    private final TextIndex indexer ;
-    private boolean started = false ;
-    
-    public TextDocProducerEntities(EntityDefinition defn, TextIndex indexer)
-    {
+    private final TextIndex        indexer ;
+    private boolean                started = false ;
+
+    public TextDocProducerEntities(EntityDefinition defn, TextIndex indexer) {
         this.defn = defn ;
         this.indexer = indexer ;
     }
-    
+
     @Override
-    protected void startBatched()
-    { indexer.startIndexing() ; started = true ;}
+    protected void startBatched() {
+        indexer.startIndexing() ;
+        started = true ;
+    }
 
     @Override
-    protected void finishBatched()
-    { indexer.finishIndexing() ; }
+    protected void finishBatched() {
+        indexer.finishIndexing() ;
+    }
 
     @Override
-    protected void dispatch(QuadAction quadAction, List<Quad> batch)
-    {
-        if ( ! started )
+    protected void dispatch(QuadAction quadAction, List<Quad> batch) {
+        if ( !started )
             throw new IllegalStateException("Not started") ;
-        if ( ! QuadAction.ADD.equals(quadAction) )
+        if ( !QuadAction.ADD.equals(quadAction) )
             return ;
         if ( batch.size() == 0 )
             return ;
-        Quad q = batch.get(0) ;
-        Node g = q.getGraph() ;
-        Node s = q.getSubject() ;
-        List<Triple> triples = quadsToTriples(batch) ;
-        //docEntity(s, triples) ;   // One docment per entity - future possibility.
-        docTriples(s,triples) ; // Does not need batching.
+        if ( false ) {
+            // One document per entity - future possibility.
+            Quad q = batch.get(0) ;
+            Node g = q.getGraph() ;
+            Node s = q.getSubject() ;
+            docEntity(g, s, batch) ;
+        }
+        docQuads(batch) ; // Does not need batching.
     }
 
-    private void docEntity(Node s, List<Triple> batch)
-    {
+    private void docEntity(Node g, Node s, List<Quad> batch) {
         // One document per entity
-        
-        String x = (s.isURI() ) ? s.getURI() : s.getBlankNodeLabel() ;
-        Entity entity = new Entity(x) ;
-        for ( Triple triple : batch )
-        {
-            Node p = triple.getPredicate() ;
+        String x = TextQuery.subjectToString(s) ;
+        String gx = TextQuery.graphNodeToString(g) ;
+        Entity entity = new Entity(x, gx) ;
+        for ( Quad quad : batch ) {
+            Node p = quad.getPredicate() ;
             String field = defn.getField(p) ;
             if ( field == null )
                 continue ;
-            Node o = triple.getObject() ;
+            Node o = quad.getObject() ;
             String val = null ;
             if ( o.isURI() )
                 val = o.getURI() ;
             else if ( o.isLiteral() )
                 val = o.getLiteralLexicalForm() ;
-            else
-            {
-                log.warn("Not a literal value for mapped field-predicate: "+field+" :: "+FmtUtils.stringForString(field)) ;
+            else {
+                log.warn("Not a literal value for mapped field-predicate: " + field + " :: "
+                         + FmtUtils.stringForString(field)) ;
                 continue ;
             }
             entity.put(field, val) ;
@@ -98,38 +95,13 @@ public class TextDocProducerEntities ext
         indexer.addEntity(entity) ;
     }
 
-    private void docTriples(Node s, List<Triple> batch)
-    {
-        String x = (s.isURI() ) ? s.getURI() : s.getBlankNodeLabel() ;
-        // One document per triple.
-        for ( Triple triple : batch )
-        {
-            Entity entity = new Entity(x) ;
-            Node p = triple.getPredicate() ;
-            String field = defn.getField(p) ;
-            if ( field == null )
-                continue ;
-            Node o = triple.getObject() ;
-            if ( ! o.isLiteral() )
-            {
-                log.warn("Not a literal value for mapped field-predicate: "+field+" :: "+FmtUtils.stringForString(field)) ;
-                continue ;
-            }
-            entity.put(field, o.getLiteralLexicalForm()) ;
-            indexer.addEntity(entity) ;
-        }
-    }
+    private void docQuads(List<Quad> batch) {
 
-    static Transform<Quad, Triple> QuadsToTriples = new Transform<Quad, Triple>() 
-    {
-        @Override
-        public Triple convert(Quad item)
-        {
-            return item.asTriple() ;
+        // One document per triple/quad
+        for ( Quad quad : batch ) {
+            Entity entity = TextQuery.entityFromQuad(defn, quad) ;
+            if ( entity != null )
+                indexer.addEntity(entity) ;
         }
-        
-    } ;
-    
-    static private List<Triple> quadsToTriples(List<Quad> quads) { return Iter.map(quads, QuadsToTriples) ; } 
+    }
 }
-

Modified: jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerTriples.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerTriples.java?rev=1549572&r1=1549571&r2=1549572&view=diff
==============================================================================
--- jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerTriples.java (original)
+++ jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerTriples.java Mon Dec  9 14:01:08 2013
@@ -18,18 +18,11 @@
 
 package org.apache.jena.query.text ;
 
-import java.util.List ;
-
-import org.apache.jena.atlas.iterator.Iter ;
-import org.apache.jena.atlas.iterator.Transform ;
 import org.slf4j.Logger ;
 import org.slf4j.LoggerFactory ;
 
 import com.hp.hpl.jena.graph.Node ;
-import com.hp.hpl.jena.graph.Triple ;
-import com.hp.hpl.jena.sparql.core.Quad ;
 import com.hp.hpl.jena.sparql.core.QuadAction ;
-import com.hp.hpl.jena.sparql.util.FmtUtils ;
 
 public class TextDocProducerTriples implements TextDocProducer {
     private static Logger          log     = LoggerFactory.getLogger(TextDocProducerTriples.class) ;
@@ -60,31 +53,9 @@ public class TextDocProducerTriples impl
         if ( qaction != QuadAction.ADD )
             return ;
 
-        String field = defn.getField(p) ;
-        if ( field == null )
-            return ;
-
-        String x = (s.isURI()) ? s.getURI() : s.getBlankNodeLabel() ;
-        String graph = TextQuery.graphNodeToString(g) ;
-        Entity entity = new Entity(x, graph) ;
-
-        if ( !o.isLiteral() ) {
-            log.warn("Not a literal value for mapped field-predicate: " + field + " :: "
-                     + FmtUtils.stringForString(field)) ;
-            return ;
-        }
-        entity.put(field, o.getLiteralLexicalForm()) ;
-        indexer.addEntity(entity) ;
-    }
-
-    static Transform<Quad, Triple> QuadsToTriples = new Transform<Quad, Triple>() {
-                                                      @Override
-                                                      public Triple convert(Quad item) {
-                                                          return item.asTriple() ;
-                                                      }
-                                                  } ;
-
-    static private List<Triple> quadsToTriples(List<Quad> quads) {
-        return Iter.map(quads, QuadsToTriples) ;
+        Entity entity = TextQuery.entityFromQuad(defn, g, s, p, o) ;
+        if ( entity != null )
+            // Null means does not match defn
+            indexer.addEntity(entity) ;
     }
 }

Modified: jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java?rev=1549572&r1=1549571&r2=1549572&view=diff
==============================================================================
--- jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java (original)
+++ jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java Mon Dec  9 14:01:08 2013
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-package org.apache.jena.query.text;
+package org.apache.jena.query.text ;
 
 import java.io.IOException ;
 import java.util.* ;
@@ -49,14 +49,13 @@ import com.hp.hpl.jena.graph.Node ;
 import com.hp.hpl.jena.graph.NodeFactory ;
 import com.hp.hpl.jena.sparql.util.NodeFactoryExtra ;
 
-public class TextIndexLucene implements TextIndex
-{
-    private static Logger log = LoggerFactory.getLogger(TextIndexLucene.class) ;
-    
-    private static int MAX_N = 10000 ;
-    public static final Version VER = Version.LUCENE_43 ;
-    
-    public static final FieldType ftIRI ;
+public class TextIndexLucene implements TextIndex {
+    private static Logger          log      = LoggerFactory.getLogger(TextIndexLucene.class) ;
+
+    private static int             MAX_N    = 10000 ;
+    public static final Version    VER      = Version.LUCENE_43 ;
+
+    public static final FieldType  ftIRI ;
     static {
         ftIRI = new FieldType() ;
         ftIRI.setTokenized(false) ;
@@ -64,100 +63,118 @@ public class TextIndexLucene implements 
         ftIRI.setIndexed(true) ;
         ftIRI.freeze() ;
     }
-    public static final FieldType ftString = StringField.TYPE_NOT_STORED ;
-    public static final FieldType ftText = TextField.TYPE_NOT_STORED ;
+    public static final FieldType  ftString = StringField.TYPE_NOT_STORED ;
+    public static final FieldType  ftText   = TextField.TYPE_NOT_STORED ;
     // Bigger index, easier to debug!
     // public static final FieldType ftText = TextField.TYPE_STORED ;
-    
+
     private final EntityDefinition docDef ;
-    private final Directory directory ;
-    private IndexWriter indexWriter ;
-    private Analyzer analyzer ;
-    
-    public TextIndexLucene(Directory directory, EntityDefinition def)
-    {
+    private final Directory        directory ;
+    private IndexWriter            indexWriter ;
+    private Analyzer               analyzer ;
+
+    public TextIndexLucene(Directory directory, EntityDefinition def) {
         this.directory = directory ;
         this.docDef = def ;
-        
+
         // create the analyzer as a wrapper that uses KeywordAnalyzer for
         // entity and graph fields and StandardAnalyzer for all other
-        Map<String,Analyzer> analyzerPerField = new HashMap<String,Analyzer>() ;
+        Map<String, Analyzer> analyzerPerField = new HashMap<String, Analyzer>() ;
         analyzerPerField.put(def.getEntityField(), new KeywordAnalyzer()) ;
-        if (def.getGraphField() != null)
+        if ( def.getGraphField() != null )
             analyzerPerField.put(def.getGraphField(), new KeywordAnalyzer()) ;
         this.analyzer = new PerFieldAnalyzerWrapper(new StandardAnalyzer(VER), analyzerPerField) ;
-        
+
         // force creation of the index if it don't exist
-        // otherwise if we get a search before data is written we get an exception
-        startIndexing();
-        finishIndexing();
-    }
-    
-    public Directory getDirectory()     { return directory ; }
-    public Analyzer getAnalyzer()       { return analyzer ; }
-    
+        // otherwise if we get a search before data is written we get an
+        // exception
+        startIndexing() ;
+        finishIndexing() ;
+    }
+
+    public Directory getDirectory() {
+        return directory ;
+    }
+
+    public Analyzer getAnalyzer() {
+        return analyzer ;
+    }
+
     @Override
-    public void startIndexing()
-    { 
+    public void startIndexing() {
         try {
             IndexWriterConfig wConfig = new IndexWriterConfig(VER, analyzer) ;
             indexWriter = new IndexWriter(directory, wConfig) ;
-        } catch (IOException e) { exception(e) ; }
+        }
+        catch (IOException e) {
+            exception(e) ;
+        }
     }
 
     @Override
-    public void finishIndexing()
-    {
-        try { indexWriter.commit() ; indexWriter.close() ; indexWriter = null ; }
-        catch (IOException e) { exception(e) ; }
+    public void finishIndexing() {
+        try {
+            indexWriter.commit() ;
+            indexWriter.close() ;
+            indexWriter = null ;
+        }
+        catch (IOException e) {
+            exception(e) ;
+        }
     }
-    
+
     @Override
-    public void abortIndexing()
-    {
-        try { indexWriter.rollback() ; }
-        catch ( IOException ex) { exception(ex) ; }
+    public void abortIndexing() {
+        try {
+            indexWriter.rollback() ;
+        }
+        catch (IOException ex) {
+            exception(ex) ;
+        }
     }
 
     @Override
-    public void close()
-    { 
-        if ( indexWriter != null ) 
-            try { indexWriter.close() ; } catch (IOException ex) { exception(ex) ; }
+    public void close() {
+        if ( indexWriter != null )
+            try {
+                indexWriter.close() ;
+            }
+            catch (IOException ex) {
+                exception(ex) ;
+            }
     }
 
     @Override
-    public void addEntity(Entity entity)
-    {
+    public void addEntity(Entity entity) {
         if ( log.isDebugEnabled() )
-            log.debug("Add entity: "+entity) ;
+            log.debug("Add entity: " + entity) ;
         try {
             boolean autoBatch = (indexWriter == null) ;
-            
+
             Document doc = doc(entity) ;
             if ( autoBatch )
                 startIndexing() ;
             indexWriter.addDocument(doc) ;
             if ( autoBatch )
                 finishIndexing() ;
-        } catch (IOException e) { exception(e) ; }
+        }
+        catch (IOException e) {
+            exception(e) ;
+        }
     }
 
-    private Document doc(Entity entity)
-    {
+    private Document doc(Entity entity) {
         Document doc = new Document() ;
         Field entField = new Field(docDef.getEntityField(), entity.getId(), ftIRI) ;
         doc.add(entField) ;
 
         String graphField = docDef.getGraphField() ;
-        if ( graphField != null )
-        {
+        if ( graphField != null ) {
             Field gField = new Field(graphField, entity.getGraph(), ftString) ;
             doc.add(gField) ;
         }
-        
-        for ( Entry<String, Object> e : entity.getMap().entrySet() )
-        {
+
+        for ( Entry<String, Object> e : entity.getMap().entrySet() ) {
             Field field = new Field(e.getKey(), (String)e.getValue(), ftText) ;
             doc.add(field) ;
         }
@@ -165,46 +182,45 @@ public class TextIndexLucene implements 
     }
 
     @Override
-    public Map<String, Node> get(String uri)
-    {
+    public Map<String, Node> get(String uri) {
         try {
             IndexReader indexReader = DirectoryReader.open(directory) ;
             List<Map<String, Node>> x = get$(indexReader, uri) ;
-            if ( x.size() == 0)
+            if ( x.size() == 0 )
                 return null ;
-//            if ( x.size() > 1)
-//                throw new TextIndexException("Multiple entires for "+uri) ;
+            // if ( x.size() > 1)
+            // throw new TextIndexException("Multiple entires for "+uri) ;
             return x.get(0) ;
-        } catch (Exception ex) { exception(ex) ; return null ; } 
+        }
+        catch (Exception ex) {
+            exception(ex) ;
+            return null ;
+        }
     }
-    
-    private List<Map<String, Node>> get$(IndexReader indexReader, String uri)  throws ParseException, IOException {
-        String escaped = QueryParser.escape(uri);
-        String qs = docDef.getEntityField()+":"+escaped ;
-        QueryParser queryParser = new QueryParser(VER, docDef.getPrimaryField(), analyzer);
-        Query query = queryParser.parse(qs);
-        IndexSearcher indexSearcher = new IndexSearcher(indexReader);
-        ScoreDoc[] sDocs = indexSearcher.search(query, 1).scoreDocs ;    
+
+    private List<Map<String, Node>> get$(IndexReader indexReader, String uri) throws ParseException, IOException {
+        String escaped = QueryParser.escape(uri) ;
+        String qs = docDef.getEntityField() + ":" + escaped ;
+        QueryParser queryParser = new QueryParser(VER, docDef.getPrimaryField(), analyzer) ;
+        Query query = queryParser.parse(qs) ;
+        IndexSearcher indexSearcher = new IndexSearcher(indexReader) ;
+        ScoreDoc[] sDocs = indexSearcher.search(query, 1).scoreDocs ;
         List<Map<String, Node>> records = new ArrayList<Map<String, Node>>() ;
 
         // Align and DRY with Solr.
-        for ( ScoreDoc sd : sDocs )
-        {
+        for ( ScoreDoc sd : sDocs ) {
             Document doc = indexSearcher.doc(sd.doc) ;
             String[] x = doc.getValues(docDef.getEntityField()) ;
-            if ( x.length != 1 )
-            {}
+            if ( x.length != 1 ) {}
             String uriStr = x[0] ;
-            Map<String, Node> record = new HashMap<String, Node>() ; 
+            Map<String, Node> record = new HashMap<String, Node>() ;
             Node entity = NodeFactory.createURI(uriStr) ;
             record.put(docDef.getEntityField(), entity) ;
-                    
-            for ( String f : docDef.fields() )
-            {
-                //log.info("Field: "+f) ;
+
+            for ( String f : docDef.fields() ) {
+                // log.info("Field: "+f) ;
                 String[] values = doc.getValues(f) ;
-                for ( String v : values )
-                {
+                for ( String v : values ) {
                     Node n = entryToNode(v) ;
                     record.put(f, n) ;
                 }
@@ -214,62 +230,63 @@ public class TextIndexLucene implements 
         return records ;
     }
 
-
     @Override
-    public List<Node> query(String qs) { return query(qs, MAX_N) ; } 
-    
+    public List<Node> query(String qs) {
+        return query(qs, MAX_N) ;
+    }
+
     @Override
-    public List<Node> query(String qs, int limit)
-    {
+    public List<Node> query(String qs, int limit) {
         try {
-            // Upgrade at Java7 ... 
+            // Upgrade at Java7 ...
             IndexReader indexReader = DirectoryReader.open(directory) ;
-            try { return query$(indexReader, qs, limit) ; } 
-            finally { indexReader.close() ; }
-        } catch (Exception ex) { exception(ex) ; return null ; } 
-    }
-        
-    private List<Node> query$(IndexReader indexReader , String qs, int limit) throws ParseException, IOException {
-        IndexSearcher indexSearcher = new IndexSearcher(indexReader);
-        QueryParser queryParser = new QueryParser(VER, docDef.getPrimaryField(), analyzer);
-        Query query = queryParser.parse(qs);
-        
+            try {
+                return query$(indexReader, qs, limit) ;
+            }
+            finally {
+                indexReader.close() ;
+            }
+        }
+        catch (Exception ex) {
+            exception(ex) ;
+            return null ;
+        }
+    }
+
+    private List<Node> query$(IndexReader indexReader, String qs, int limit) throws ParseException, IOException {
+        IndexSearcher indexSearcher = new IndexSearcher(indexReader) ;
+        QueryParser queryParser = new QueryParser(VER, docDef.getPrimaryField(), analyzer) ;
+        Query query = queryParser.parse(qs) ;
+
         if ( limit <= 0 )
             limit = MAX_N ;
         ScoreDoc[] sDocs = indexSearcher.search(query, limit).scoreDocs ;
-        
+
         List<Node> results = new ArrayList<Node>() ;
-        
+
         // Align and DRY with Solr.
-        for ( ScoreDoc sd : sDocs )
-        {
+        for ( ScoreDoc sd : sDocs ) {
             Document doc = indexSearcher.doc(sd.doc) ;
             String[] values = doc.getValues(docDef.getEntityField()) ;
-            for ( String v : values )
-            {
-                Node n = NodeFactory.createURI(v);
+            for ( String v : values ) {
+                Node n = TextQuery.stringToNode(v) ;
                 results.add(n) ;
             }
         }
         return results ;
     }
 
-    
     @Override
-    public EntityDefinition getDocDef()
-    {
+    public EntityDefinition getDocDef() {
         return docDef ;
     }
 
-    private Node entryToNode(String v)
-    {
+    private Node entryToNode(String v) {
         // TEMP
         return NodeFactoryExtra.createLiteralNode(v, null, null) ;
     }
 
-    private static void exception(Exception ex)
-    {
+    private static void exception(Exception ex) {
         throw new TextIndexException(ex) ;
     }
 }
-

Modified: jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java?rev=1549572&r1=1549571&r2=1549572&view=diff
==============================================================================
--- jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java (original)
+++ jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java Mon Dec  9 14:01:08 2013
@@ -172,9 +172,10 @@ public class TextIndexSolr implements Te
 
         for ( SolrDocument sd : solrResults )
         {
-            String uriStr = (String)sd.getFieldValue(docDef.getEntityField()) ;
+            String str = (String)sd.getFieldValue(docDef.getEntityField()) ;
             //log.info("Entity: "+uriStr) ;
-            results.add(NodeFactory.createURI(uriStr)) ;
+            Node n = TextQuery.stringToNode(str) ;
+            results.add(n) ;
         }
 
         if ( limit > 0 && results.size() > limit )

Modified: jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextQuery.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextQuery.java?rev=1549572&r1=1549571&r2=1549572&view=diff
==============================================================================
--- jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextQuery.java (original)
+++ jena/trunk/jena-text/src/main/java/org/apache/jena/query/text/TextQuery.java Mon Dec  9 14:01:08 2013
@@ -18,16 +18,21 @@
 
 package org.apache.jena.query.text;
 
+import org.apache.jena.atlas.logging.Log ;
 import org.apache.jena.query.text.assembler.TextAssembler ;
 
 import com.hp.hpl.jena.graph.Node ;
+import com.hp.hpl.jena.graph.NodeFactory ;
+import com.hp.hpl.jena.rdf.model.AnonId ;
 import com.hp.hpl.jena.sparql.SystemARQ ;
+import com.hp.hpl.jena.sparql.core.Quad ;
 import com.hp.hpl.jena.sparql.lib.Metadata ;
 import com.hp.hpl.jena.sparql.mgt.ARQMgt ;
 import com.hp.hpl.jena.sparql.mgt.SystemInfo ;
 import com.hp.hpl.jena.sparql.pfunction.PropertyFunction ;
 import com.hp.hpl.jena.sparql.pfunction.PropertyFunctionFactory ;
 import com.hp.hpl.jena.sparql.pfunction.PropertyFunctionRegistry ;
+import com.hp.hpl.jena.sparql.util.FmtUtils ;
 import com.hp.hpl.jena.sparql.util.Symbol ;
 import com.hp.hpl.jena.tdb.TDB ;
 
@@ -72,10 +77,63 @@ public class TextQuery
         }
     }
     
+    public static String subjectToString(Node s) {
+        if ( s == null )
+            throw new IllegalArgumentException("Subject node can not be null") ;
+        if ( ! (s.isURI() || s.isBlank() ) )
+            throw new TextIndexException("Found a subject that is not a URI nor a blank node: "+s) ; 
+        return nodeToString(s) ;
+    }
+    
     public static String graphNodeToString(Node g) {
+        if ( g == null )
+            return null ;
         if ( ! (g.isURI() || g.isBlank() ) )
             throw new TextIndexException("Found a graph label that is not a URI nor a blank node: "+g) ; 
-        return (g.isURI() ) ? g.getURI() : "_:" + g.getBlankNodeLabel() ;
+        return nodeToString(g) ;
+    }
+    
+    private static String nodeToString(Node n) {
+        return (n.isURI() ) ? n.getURI() : "_:" + n.getBlankNodeLabel() ;
+    }
+
+    /** Reverse the translation of Nodes to string stored in indexes */
+    public static Node stringToNode(String v) {
+        if ( v.startsWith("_:") ) {
+            v = v.substring("_:".length()) ;
+            return NodeFactory.createAnon(new AnonId(v)) ;
+        }
+        else
+            return NodeFactory.createURI(v) ;
+    }
+
+    /** Create an Entity from a quad.
+     * Returns null if the quad is not a candidate for indexing.
+     */
+    public static Entity entityFromQuad(EntityDefinition defn , Quad quad ) {
+        return entityFromQuad(defn, quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ;
+    }
+
+    /** Create an Entity from a quad (as g/s/p/o).
+     * Returns null if the quad is not a candidate for indexing.
+     */
+    public static Entity entityFromQuad(EntityDefinition defn , Node g , Node s , Node p , Node o ) {
+        String field = defn.getField(p) ;
+        if ( field == null )
+            return null ;
+
+        String x = TextQuery.subjectToString(s) ;
+        String graph = TextQuery.graphNodeToString(g) ;
+        Entity entity = new Entity(x, graph) ;
+
+        if ( !o.isLiteral() ) {
+            Log.warn(TextQuery.class, "Not a literal value for mapped field-predicate: " + field + " :: "
+                     + FmtUtils.stringForString(field)) ;
+            return null ;
+        }
+        entity.put(field, o.getLiteralLexicalForm()) ;
+        return entity ;
     }
 }
 
+