]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexUtils.java
Improvements to Lucene indexing
[simantics/platform.git] / bundles / org.simantics.db.indexing / src / org / simantics / db / indexing / IndexUtils.java
index 5262d99a2d85690715f4264a9a01cfaf664bcf95..23e93ea1c9a7c743f80118dab680ca3026d4fa09 100644 (file)
@@ -17,8 +17,8 @@ import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.common.procedure.adapter.TransientCacheListener;
 import org.simantics.db.common.request.ObjectsWithType;
-import org.simantics.db.common.utils.NameUtils;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.layer0.genericrelation.IndexQueries;
 import org.simantics.db.layer0.util.Layer0Utils;
 import org.simantics.db.service.CollectionSupport;
 import org.simantics.layer0.Layer0;
@@ -96,8 +96,9 @@ public class IndexUtils {
     public static Collection<Resource> findByType(ReadGraph graph, Resource model, Resource type) throws DatabaseException {
        
         HashSet<Resource> results = new HashSet<Resource>();
-        
-               String search = "Types:*" + NameUtils.getSafeName(graph, type);
+        Layer0 L0 = Layer0.getInstance(graph);
+        String typeName = graph.getRelatedValue(type, L0.HasName, Bindings.STRING);
+               String search = "Types:" + IndexQueries.quoteTerm(typeName);
 
         for(Map<String, Object> entry : find(graph, model, search)) {
                Resource resource = (Resource)entry.get("Resource");
@@ -111,12 +112,12 @@ public class IndexUtils {
         Layer0 L0 = Layer0.getInstance(graph);
         
         HashSet<Resource> results = new HashSet<Resource>();
-        
-               String search = "Types:*" + type + " AND Name:" + name;
+        String typeName = graph.getRelatedValue(type, L0.HasName, Bindings.STRING);
+               String search = "Types:" + IndexQueries.quoteTerm(typeName) + " AND Name:" + IndexQueries.quoteTerm(name);
 
         for(Map<String, Object> entry : find(graph, model, search)) {
                Resource resource = (Resource)entry.get("Resource");
-               if(graph.isInstanceOf(resource, type) && name.equals(graph.getPossibleRelatedValue(resource, L0.HasName, Bindings.STRING))) results.add(resource);
+               if(graph.isInstanceOf(resource, type)) results.add(resource);
         }
         return results;
     }