Package org.neo4j.graphdb.index

Examples of org.neo4j.graphdb.index.IndexManager


    @Test
    public void testLoadIndex() {
        db.beginTx();
        Map<String, String> config = TimelineNodeIndex.CONFIG;
        IndexManager indexMan = db.index();
        Index<Node> index = indexMan.forNodes("timeline1", config);
        assertNotNull(index);

    }
View Full Code Here


    public void testLoadIndexWithRootNode() {
        db.beginTx();
        Map<String, String> config = new HashMap<String, String>(TimelineNodeIndex.CONFIG);
        final Node startNode = ReferenceNodes.getReferenceNode(db);
        config.put(TimelineNodeIndex.START_NODE_ID, String.valueOf(startNode.getId()));
        IndexManager indexMan = db.index();
        Index<Node> index = indexMan.forNodes("timeline1", config);
        final Timeline timeline = ((TimelineNodeIndex) index).getTimeline();
        assertEquals(startNode, timeline.getUnderlyingNode());
        assertNotNull(index);

    }
View Full Code Here

    @Test
    public void testAddToIndex() throws Exception {
        Transaction tx = db.beginTx();
        Map<String, String> config = TimelineNodeIndex.CONFIG;
        IndexManager indexMan = db.index();
        Index<Node> index = indexMan.forNodes("timeline1", config);
        assertNotNull(index);
        Node n1 = db.createNode();
        n1.setProperty("time", 123);
        index.add(n1, "timestamp", 123L);
        Node n2 = db.createNode();
View Full Code Here

        result.put("relationships", relationships);

    }

    private void clearIndex(Map<String, Object> result) {
        IndexManager indexManager = graph.index();
        result.put("node-indexes", Arrays.asList(indexManager.nodeIndexNames()));
        result.put("relationship-indexes", Arrays.asList(indexManager.relationshipIndexNames()));
        try {
            for (String ix : indexManager.nodeIndexNames()) {
                final Index<Node> index = indexManager.forNodes(ix);
                getMutableIndex(index).delete();
            }
            for (String ix : indexManager.relationshipIndexNames()) {
                final RelationshipIndex index = indexManager.forRelationships(ix);
                getMutableIndex(index).delete();
            }
        } catch (UnsupportedOperationException uoe) {
            throw new RuntimeException("Implementation detail assumption failed for cleaning readonly indexes, please make sure that the version of this extension and the Neo4j server align");
        }
View Full Code Here

    }

    private void createData(GraphDatabaseAPI db, int max) {
        Transaction tx = db.beginTx();
        try {
            final IndexManager indexManager = db.index();
            Node[] nodes = new Node[max];
            for (int i = 0; i < max; i++) {
                nodes[i] = db.createNode();
                final Index<Node> index = indexManager.forNodes("node_index_" + String.valueOf(i % 5));
                index.add(nodes[i],"ID",i);
            }
            Random random = new Random();
            for (int i = 0; i < max * 2; i++) {
                int from = random.nextInt(max);
                final int to = (from + 1 + random.nextInt(max - 1)) % max;
                final Relationship relationship = nodes[from].createRelationshipTo(nodes[to], DynamicRelationshipType.withName("TEST_" + i));
                final Index<Relationship> index = indexManager.forRelationships("rel_index_" + String.valueOf(i % 5));
                index.add(relationship, "ID", i);
            }
            tx.success();
        } finally {
            tx.finish();
View Full Code Here

            throw new RuntimeException(e.getMessage(), e);
        }
    }

    private void generateIndex(final Parameter<Object, Object>... indexParameters) {
        final IndexManager manager = this.graph.getRawGraph().index();
        if (Vertex.class.isAssignableFrom(this.indexClass)) {
            if (indexParameters.length > 0)
                this.rawIndex = (org.neo4j.graphdb.index.Index<S>) manager.forNodes(this.indexName, generateParameterMap(indexParameters));
            else
                this.rawIndex = (org.neo4j.graphdb.index.Index<S>) manager.forNodes(this.indexName);
        } else {
            if (indexParameters.length > 0)
                this.rawIndex = (org.neo4j.graphdb.index.Index<S>) manager.forRelationships(this.indexName, generateParameterMap(indexParameters));
            else
                this.rawIndex = (org.neo4j.graphdb.index.Index<S>) manager.forRelationships(this.indexName);
        }
    }
View Full Code Here

        }
    }

    private void generateIndex(final Parameter<Object, Object>... indexParameters) {
        this.graph.autoStartTransaction(true);
        final IndexManager manager = this.graph.getRawGraph().index();
        if (Vertex.class.isAssignableFrom(this.indexClass)) {
            if (indexParameters.length > 0)
                this.rawIndex = (org.neo4j.graphdb.index.Index<S>) manager.forNodes(this.indexName, generateParameterMap(indexParameters));
            else
                this.rawIndex = (org.neo4j.graphdb.index.Index<S>) manager.forNodes(this.indexName);
        } else {
            if (indexParameters.length > 0)
                this.rawIndex = (org.neo4j.graphdb.index.Index<S>) manager.forRelationships(this.indexName, generateParameterMap(indexParameters));
            else
                this.rawIndex = (org.neo4j.graphdb.index.Index<S>) manager.forRelationships(this.indexName);
        }
    }
View Full Code Here

        result.put("relationships", relationships);

    }

    private void clearIndex(Map<String, Object> result) {
        IndexManager indexManager = graph.index();
        result.put("node-indexes", Arrays.asList(indexManager.nodeIndexNames()));
        result.put("relationship-indexes", Arrays.asList(indexManager.relationshipIndexNames()));
        for (String ix : indexManager.nodeIndexNames()) {
            indexManager.forNodes(ix).delete();
        }
        for (String ix : indexManager.relationshipIndexNames()) {
            indexManager.forRelationships(ix).delete();
        }
    }
View Full Code Here

        removeFromIndexes(relationship);
        relationship.delete();
    }

    private void removeFromIndexes(Node node) {
        IndexManager indexManager = getIndexManager();
        for (String indexName : indexManager.nodeIndexNames()) {
            indexManager.forNodes(indexName).remove(node);
        }
    }
View Full Code Here

            indexManager.forNodes(indexName).remove(node);
        }
    }

    private void removeFromIndexes(Relationship relationship) {
        IndexManager indexManager = getIndexManager();
        for (String indexName : indexManager.relationshipIndexNames()) {
            indexManager.forRelationships(indexName).remove(relationship);
        }
    }
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.index.IndexManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.