Search in sources :

Example 1 with Index

use of org.structr.api.index.Index in project structr by structr.

the class Property method index.

@Override
public void index(final GraphObject entity, final Object value) {
    if (entity instanceof AbstractNode) {
        final NodeService nodeService = Services.getInstance().getService(NodeService.class);
        final AbstractNode node = (AbstractNode) entity;
        final Node dbNode = node.getNode();
        final Index<Node> index = nodeService.getNodeIndex();
        if (index != null) {
            try {
                index.remove(dbNode, dbName);
                if (value != null || isIndexedWhenEmpty()) {
                    index.add(dbNode, dbName, value, valueType());
                }
            } catch (Throwable t) {
                logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
                logger.warn("", t);
            }
        }
    } else if (entity instanceof AbstractRelationship) {
        final NodeService nodeService = Services.getInstance().getService(NodeService.class);
        final AbstractRelationship rel = (AbstractRelationship) entity;
        final Relationship dbRel = rel.getRelationship();
        final Index<Relationship> index = nodeService.getRelationshipIndex();
        if (index != null) {
            try {
                index.remove(dbRel, dbName);
                if (value != null || isIndexedWhenEmpty()) {
                    index.add(dbRel, dbName, value, valueType());
                }
            } catch (Throwable t) {
                logger.info("Unable to index property with dbName {} and value {} of type {} on {}: {}", new Object[] { dbName, value, this.getClass().getSimpleName(), entity, t });
            }
        }
    }
}
Also used : AbstractNode(org.structr.core.entity.AbstractNode) NodeService(org.structr.core.graph.NodeService) Node(org.structr.api.graph.Node) AbstractNode(org.structr.core.entity.AbstractNode) AbstractRelationship(org.structr.core.entity.AbstractRelationship) AbstractRelationship(org.structr.core.entity.AbstractRelationship) Relationship(org.structr.api.graph.Relationship) GraphObject(org.structr.core.GraphObject) AbstractCypherIndex(org.structr.bolt.index.AbstractCypherIndex) Index(org.structr.api.index.Index)

Aggregations

Node (org.structr.api.graph.Node)1 Relationship (org.structr.api.graph.Relationship)1 Index (org.structr.api.index.Index)1 AbstractCypherIndex (org.structr.bolt.index.AbstractCypherIndex)1 GraphObject (org.structr.core.GraphObject)1 AbstractNode (org.structr.core.entity.AbstractNode)1 AbstractRelationship (org.structr.core.entity.AbstractRelationship)1 NodeService (org.structr.core.graph.NodeService)1