]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsMemorySearcher.java
Added new field TypeId to dependency index for exact type searching
[simantics/platform.git] / bundles / org.simantics.db.indexing / src / org / simantics / db / indexing / IndexedRelationsMemorySearcher.java
index ac0918ea52e9eb9e33bc4c0c6a27a3becbfd7d79..0275c2e00a6274a117c55b88d7fb0d8d9ae17d88 100644 (file)
@@ -11,9 +11,6 @@
  *******************************************************************************/
 package org.simantics.db.indexing;
 
-import gnu.trove.map.hash.THashMap;
-import gnu.trove.set.hash.TLongHashSet;
-
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -23,7 +20,6 @@ import java.util.Map;
 import org.apache.lucene.document.Document;
 import org.apache.lucene.index.CorruptIndexException;
 import org.apache.lucene.index.IndexableField;
-import org.apache.lucene.queryparser.classic.ParseException;
 import org.apache.lucene.search.MatchAllDocsQuery;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
@@ -36,6 +32,11 @@ import org.simantics.db.Session;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.layer0.adapter.GenericRelation;
 import org.simantics.utils.datastructures.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import gnu.trove.map.hash.THashMap;
+import gnu.trove.set.hash.TLongHashSet;
 
 /**
  * @author Tuukka Lehtonen
@@ -43,6 +44,8 @@ import org.simantics.utils.datastructures.Pair;
  */
 public class IndexedRelationsMemorySearcher extends IndexedRelationsSearcherBase {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(IndexedRelationsMemorySearcher.class);
+    
     final IndexedRelationsSearcher backend;
     final GenericRelation r;
     
@@ -90,8 +93,7 @@ public class IndexedRelationsMemorySearcher extends IndexedRelationsSearcherBase
         super.removeIndex(monitor, r, processor, key, keyValues);
     }
     
-    public List<Object[]> allDocs(IProgressMonitor monitor, Session session) throws ParseException, IOException,
-    DatabaseException {
+    public List<Object[]> allDocs(IProgressMonitor monitor, Session session) throws IOException {
         
         Query query = new MatchAllDocsQuery(); 
 
@@ -108,34 +110,23 @@ public class IndexedRelationsMemorySearcher extends IndexedRelationsSearcherBase
         }
 
         for(ScoreDoc scoreDoc:scoreDocs) {
-
-            try {
-
-                Document doc = reader.document(scoreDoc.doc);
-                List<IndexableField> fs = doc.getFields();
-                Object[] o = new Object[fs.size()];
-                int index = 0; 
-                for (IndexableField f : fs) {
-                    String clazz = classMap.get(f.name());
-                    if ("Long".equals(clazz)) {
-                        o[index++] = Long.parseLong(f.stringValue());
-                    } else {
-                        o[index++] = f.stringValue();
-                    }
+            Document doc = reader.document(scoreDoc.doc);
+            List<IndexableField> fs = doc.getFields();
+            Object[] o = new Object[fs.size()];
+            int index = 0; 
+            for (IndexableField f : fs) {
+                String clazz = classMap.get(f.name());
+                if ("Long".equals(clazz)) {
+                    o[index++] = Long.parseLong(f.stringValue());
+                } else {
+                    o[index++] = f.stringValue();
                 }
-                result.add(o);
-            } catch (CorruptIndexException e) {
-                throw new DatabaseException(e);
-            } catch (IOException e) {
-                throw new DatabaseException(e);
             }
-
+            result.add(o);
         }
 
         changeState(monitor, session, State.READY);
-        
-//        closeInternal();
-        
+
         return result;
 
     }
@@ -144,10 +135,8 @@ public class IndexedRelationsMemorySearcher extends IndexedRelationsSearcherBase
         try {
             if(writer != null)
                 writer.commit();
-        } catch (CorruptIndexException e) {
-            e.printStackTrace();
         } catch (IOException e) {
-            e.printStackTrace();
+            getLogger().error("Index commit failed", e);
         }
     }
 
@@ -173,19 +162,16 @@ public class IndexedRelationsMemorySearcher extends IndexedRelationsSearcherBase
     @Override
     Directory getDirectory(Session session) throws IOException {
        MemoryIndexing mem = MemoryIndexing.getInstance(session);
-        String path = indexPath.getAbsolutePath();
+        String path = indexPath.toAbsolutePath().toString();
         return mem.getDirectory(path, Queries.getAnalyzer());
     }
     
     @Override
     Throwable bestEffortClear(IProgressMonitor monitor, Session session) {
-
-       setProblem(null);
-       
        MemoryIndexing mem = MemoryIndexing.getInstance(session);
         changed.clear();
         
-        String path = indexPath.getAbsolutePath();
+        String path = indexPath.toAbsolutePath().toString();
         mem.remove(path);
         
         return null;
@@ -196,5 +182,10 @@ public class IndexedRelationsMemorySearcher extends IndexedRelationsSearcherBase
     protected boolean requireChangeInfoOnReplace() {
        return false;
     }
+
+    @Override
+    protected Logger getLogger() {
+        return LOGGER;
+    }
     
 }