String typeName = graph.getPossibleRelatedValue(type, L0.HasName, Bindings.STRING);
if (typeName == null || typeName.isEmpty())
return null;
- sb.append("Types:").append( IndexQueries.escape( typeName, true ) );
+ sb.append("Types:").append( IndexQueries.quoteTerm(typeName) );
}
if (!emptyFilter) {
if (sb.length() > 0)
sb.append(" AND ");
sb.append(filter);
}
+ if (sb.length() == 0) {
+ sb.append("*:*");
+ }
return sb.toString();
}
@Override
public int getType() {
- return RequestFlags.IMMEDIATE_UPDATE;
+ // This query should not be immediate update since it takes a long time!
+ return RequestFlags.INVALIDATE;
}
}
CollectionSupport coll = graph.getService(CollectionSupport.class);
THashSet<Resource> visited = new THashSet<>();
- List<Resource> rec = findRec(graph, index, filter, visited);
+ List<Resource> rec_ = findRec(graph, index, filter, visited);
+ // We must not modify rec_!
+ List<Resource> rec = rec_;
for(Resource global : Layer0Utils.listGlobalOntologies(graph)) {
if(!visited.add(global)) continue;
List<Resource> rs = graph.syncRequest(new QueryIndex(global, type, filter), TransientCacheListener.<List<Resource>>instance());
- if(rec.isEmpty() && !rs.isEmpty()) {
- // TODO: rec could be an immutable empty list
- rec = new ArrayList<Resource>();
+ if(!rs.isEmpty()) {
+ if(rec == rec_)
+ rec = new ArrayList<>(rec);
+ rec.addAll(rs);
}
- rec.addAll(rs);
}
Collection<Resource> result = coll.asSortedList(rec);
return result;
@Override
public Collection<Resource> findByName(ReadGraph graph, Resource model,
String name) throws DatabaseException {
- Layer0 L0 = Layer0.getInstance(graph);
- CollectionSupport coll = graph.getService(CollectionSupport.class);
- List<Resource> results = coll.createList();
- for(Resource match : find(graph, model, name)) {
- if(name.equals(graph.getPossibleRelatedValue(match, L0.HasName, Bindings.STRING))) results.add(match);
- }
- return results;
+ return find(graph, model, IndexQueries.quoteTerm(name));
}
}