final List<AbstractNode> nodes = new LinkedList<>();
// instantiate all nodes in a single list
try (final Tx tx = StructrApp.getInstance().tx()) {
final Result<AbstractNode> result = nodeFactory.instantiateAll(Iterables.filter(new StructrAndSpatialPredicate(true, false, false), GlobalGraphOperations.at(graphDb).getAllNodes()));
for (AbstractNode node : result.getResults()) {
if (type == null || node.getClass().equals(type)) {
nodes.add(node);
}
}
tx.success();
}
if (type == null) {
logger.log(Level.INFO, "Node type not set or no entity class found. Starting (re-)indexing all nodes");
} else {
logger.log(Level.INFO, "Starting (re-)indexing all nodes of type {0}", new Object[]{type.getSimpleName()});
}
long count = bulkGraphOperation(securityContext, nodes, 100, "RebuildNodeIndex", new BulkGraphOperation<AbstractNode>() {
@Override
public void handleGraphObject(SecurityContext securityContext, AbstractNode node) {
try {
// Set type to update labels
final String type = node.getProperty(NodeInterface.type);
node.setProperty(NodeInterface.type, null);
node.setProperty(NodeInterface.type, type);
} catch (FrameworkException ex) {
ex.printStackTrace();
}
node.updateInIndex();
}
@Override
public void handleThrowable(SecurityContext securityContext, Throwable t, AbstractNode node) {
logger.log(Level.WARNING, "Unable to index node {0}: {1}", new Object[]{node, t.getMessage()});
}
@Override
public void handleTransactionFailure(SecurityContext securityContext, Throwable t) {
logger.log(Level.WARNING, "Unable to index node: {0}", t.getMessage());
}
});
logger.log(Level.INFO, "Done with (re-)indexing {0} nodes", count);
}
if (mode == null || "relsOnly".equals(mode)) {
final List<AbstractRelationship> rels = new LinkedList<>();
long count = 0;
// instantiate all relationships in a single list
try (final Tx tx = StructrApp.getInstance().tx()) {
final List<AbstractRelationship> unfilteredRels = relFactory.instantiate(Iterables.filter(new StructrAndSpatialPredicate(true, false, false), GlobalGraphOperations.at(graphDb).getAllRelationships()));
for (AbstractRelationship rel : unfilteredRels) {
if (relType == null || rel.getType().equals(relType)) {
rels.add(rel);