jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [04/15] jena git commit: Lucene index synchro on triple deletion on jena-text
Date Wed, 17 Jun 2015 20:55:18 GMT
Lucene index synchro on triple deletion on jena-text


Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/b357ddfd
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/b357ddfd
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/b357ddfd

Branch: refs/heads/master
Commit: b357ddfd643a3ed4bbdbd5fa2f507afd49478835
Parents: 7ef374f
Author: Alexis Miara <alexis_miara@hotmail.com>
Authored: Wed Apr 29 14:52:16 2015 -0400
Committer: Alexis Miara <alexis_miara@hotmail.com>
Committed: Wed May 13 14:48:09 2015 -0400

----------------------------------------------------------------------
 .../jena/query/text/TextDocProducerTriples.java | 24 +++++++++----
 .../org/apache/jena/query/text/TextIndex.java   |  1 +
 .../apache/jena/query/text/TextIndexLucene.java | 38 +++++++++++++++++---
 .../apache/jena/query/text/TextIndexSolr.java   |  5 +++
 4 files changed, 58 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/b357ddfd/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerTriples.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerTriples.java
b/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerTriples.java
index c0bcabd..51f5480 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerTriples.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextDocProducerTriples.java
@@ -56,17 +56,29 @@ public class TextDocProducerTriples implements TextDocProducer {
     public void change(QuadAction qaction, Node g, Node s, Node p, Node o) {
         // One document per triple/quad
 
-        if ( qaction != QuadAction.ADD )
+        if ( qaction != QuadAction.ADD &&
+             qaction != QuadAction.DELETE )
             return ;
 
+
         Entity entity = TextQueryFuncs.entityFromQuad(defn, g, s, p, o) ;
         // Null means does not match defn
         if ( entity != null ) {
-            indexer.addEntity(entity) ;
-            
-            // Auto commit the entity if we aren't in a transaction
-            if (!inTransaction.get()) {
-                indexer.commit() ;
+            if (qaction == QuadAction.ADD) {
+                indexer.addEntity(entity);
+
+                // Auto commit the entity if we aren't in a transaction
+                if (!inTransaction.get()) {
+                    indexer.commit();
+                }
+            }
+            else if (qaction == QuadAction.DELETE) {
+                indexer.deleteEntity(entity);
+
+                // Auto commit the entity if we aren't in a transaction
+                if (!inTransaction.get()) {
+                    indexer.commit();
+                }
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/jena/blob/b357ddfd/jena-text/src/main/java/org/apache/jena/query/text/TextIndex.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextIndex.java b/jena-text/src/main/java/org/apache/jena/query/text/TextIndex.java
index 69efb31..fcf72f3 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextIndex.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextIndex.java
@@ -36,6 +36,7 @@ public interface TextIndex extends Closeable //, Transactional
     // Update operations
     void addEntity(Entity entity) ;
     void updateEntity(Entity entity) ;
+    void deleteEntity(Entity entity) ;
     
     
     // read operations

http://git-wip-us.apache.org/repos/asf/jena/blob/b357ddfd/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
index 9107e86..b11f000 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexLucene.java
@@ -45,9 +45,7 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.queryparser.classic.ParseException ;
 import org.apache.lucene.queryparser.classic.QueryParser ;
 import org.apache.lucene.queryparser.classic.QueryParserBase ;
-import org.apache.lucene.search.IndexSearcher ;
-import org.apache.lucene.search.Query ;
-import org.apache.lucene.search.ScoreDoc ;
+import org.apache.lucene.search.*;
 import org.apache.lucene.store.Directory ;
 import org.apache.lucene.util.Version ;
 import org.slf4j.Logger ;
@@ -77,6 +75,9 @@ public class TextIndexLucene implements TextIndex {
     private final Analyzer         analyzer ;
     private final Analyzer         queryAnalyzer ;
 
+    //the BORDER_DELIMITER constant is required for...
+    private static final String BORDER_DELIMITER = "borderdelimiter";
+
     // The IndexWriter can't be final because we may have to recreate it if rollback() is
called.
     // However, it needs to be volatile in case the next write transaction is on a different
thread,
     // but we do not need locking because we are assuming that there can only be one writer
@@ -214,6 +215,35 @@ public class TextIndexLucene implements TextIndex {
         }
     }
 
+    @Override
+    public void deleteEntity(Entity entity) {
+        if ( log.isDebugEnabled() )
+            log.debug("Delete entity: "+entity) ;
+        try {
+            TermQuery qUri = new TermQuery(new Term("uri", entity.getId()));
+            Map<String, Object> map = entity.getMap();
+            String property = map.keySet().iterator().next();
+            String value = (String)map.get(property);
+
+            //escaping special characters to avoid problem in WildcardQuery
+            value = value.replace( "?", "\\?" );
+            value = value.replace( "*", "\\*" );
+            value = value.replace( "\"", "\\\"" );
+
+            QueryParser qp = new QueryParser(VER, property, analyzer);
+            Query qPropValue = qp.parse("\"" + BORDER_DELIMITER + " " + value + " " + BORDER_DELIMITER
+ "\"");
+
+            BooleanQuery q = new BooleanQuery();
+            q.add(qUri, BooleanClause.Occur.MUST);
+            q.add(qPropValue, BooleanClause.Occur.MUST);
+
+            indexWriter.deleteDocuments(q);
+
+        } catch (Exception e) {
+            throw new TextIndexException(e) ;
+        }
+    }
+
     private Document doc(Entity entity) {
         Document doc = new Document() ;
         Field entField = new Field(docDef.getEntityField(), entity.getId(), ftIRI) ;
@@ -226,7 +256,7 @@ public class TextIndexLucene implements TextIndex {
         }
 
         for ( Entry<String, Object> e : entity.getMap().entrySet() ) {
-            Field field = new Field(e.getKey(), (String)e.getValue(), ftText) ;
+            Field field = new Field(e.getKey(), BORDER_DELIMITER + " " + e.getValue() + "
" + BORDER_DELIMITER, ftText) ;
             doc.add(field) ;
         }
         return doc ;

http://git-wip-us.apache.org/repos/asf/jena/blob/b357ddfd/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java
----------------------------------------------------------------------
diff --git a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java
index 54a3263..075eb49 100644
--- a/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java
+++ b/jena-text/src/main/java/org/apache/jena/query/text/TextIndexSolr.java
@@ -104,6 +104,11 @@ public class TextIndexSolr implements TextIndex
         } catch (Exception e) { exception(e) ; }
     }
 
+    @Override
+    public void deleteEntity(Entity entity) {
+         //to be implemented
+    }
+
     private SolrInputDocument solrDoc(Entity entity)
     {
         SolrInputDocument doc = new SolrInputDocument() ;


Mime
View raw message