Package org.neo4j.graphdb.index

Examples of org.neo4j.graphdb.index.IndexManager


        return setProperties(startNode.createRelationshipTo(endNode,type),props);
    }

    @Override
    public <T extends PropertyContainer> Index<T> getIndex(String indexName) {
        IndexManager indexManager = delegate.index();
        if (indexManager.existsForNodes(indexName)) return (Index<T>) indexManager.forNodes(indexName);
        if (indexManager.existsForRelationships(indexName)) return (Index<T>) indexManager.forRelationships(indexName);
        throw new IllegalArgumentException("Index "+indexName+" does not exist.");
    }
View Full Code Here


    }

    // TODO handle existing indexes
    @Override
    public <T extends PropertyContainer> Index<T> createIndex(Class<T> type, String indexName, boolean fullText) {
        IndexManager indexManager = delegate.index();
        if (isNode(type)) {
            if (indexManager.existsForNodes(indexName))
                return (Index<T>) checkAndGetExistingIndex(indexName, fullText, indexManager.forNodes(indexName));
            return (Index<T>) indexManager.forNodes(indexName, indexConfigFor(fullText));
        } else {
            if (indexManager.existsForRelationships(indexName))
                return (Index<T>) checkAndGetExistingIndex(indexName, fullText, indexManager.forRelationships(indexName));
            return (Index<T>) indexManager.forRelationships(indexName, indexConfigFor(fullText));
        }
    }
View Full Code Here

            }
        }
    }

    private static void clearIndex(GraphDatabaseService gds) {
        IndexManager indexManager = gds.index();
        for (String ix : indexManager.nodeIndexNames()) {
            indexManager.forNodes(ix).delete();
        }
        for (String ix : indexManager.relationshipIndexNames()) {
            indexManager.forRelationships(ix).delete();
        }
    }
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

     */
    @Test
    public void testLoadIndex() {
        Map<String, String> config = SpatialIndexProvider.SIMPLE_POINT_CONFIG;
        try (Transaction tx = db.beginTx()) {
            IndexManager indexMan = db.index();
            Index<Node> index;
            index = indexMan.forNodes("layer1", config);
            assertNotNull(index);

            //Load the an existing index again
            index = indexMan.forNodes("layer1", config);
            assertNotNull(index);

            //Try a different config
            Map<String, String> config2 = SpatialIndexProvider.SIMPLE_WKT_CONFIG;
            index = indexMan.forNodes("layer2", config2);
            assertNotNull(index);

            //Load the index again
            index = indexMan.forNodes("layer2", config2);
            assertNotNull(index);

            //Try loading the same index with a different config
            boolean exceptionThrown = false;
            try {
                index = indexMan.forNodes("layer2", config);
            } catch (IllegalArgumentException iae) {
                exceptionThrown = true;
            }
            assertTrue(exceptionThrown);

            config = SpatialIndexProvider.SIMPLE_WKT_CONFIG;
            index = indexMan.forNodes("layer2", config);
            assertNotNull(index);

            config = SpatialIndexProvider.SIMPLE_WKB_CONFIG;
            index = indexMan.forNodes("layer3", config);
            assertNotNull(index);
            tx.success();
        }
    }
View Full Code Here

        // Use transaction just in case it matters (not that I can tell)
        Transaction tx = db.beginTx();
        System.out.println("testInvalidConfig: Begun transaction");

        // Try to create the index, ignore IllegalArgumentException to continue
        IndexManager indexMan = db.index();
        try {
            Index<Node> index = indexMan.forNodes("layer1", config);
            System.out.println("testInvalidConfig: invalid index requested, did not throw exception.");
            tx.success();    // Won't happen currently
        } catch (IllegalArgumentException e) {
            // Bail out
            tx.failure();
            System.out.println("testInvalidConfig: invalid index creation failed, good, let the tx rollback");
        }
        tx.close();
        System.out.println("testInvalidConfig: tx done.");
        // Assert index isn't referenced in the manager
        assertFalse("Index should not exist", indexMan.existsForNodes("layer1"));
    }
View Full Code Here

    @Ignore
    //TODO: fix this, issue #70
    public void testDeleteIndex() {
        // Create an index
        Map<String, String> config = SpatialIndexProvider.SIMPLE_POINT_CONFIG;
        IndexManager indexMan = db.index();
        Index<Node> index = indexMan.forNodes("layer1", config);
        assertNotNull(index);
        Transaction transaction = db.beginTx();

        Node node = null;
        try {
            node = db.createNode();
            node.setProperty("lat", 56.2);
            node.setProperty("lon", 15.3);
            transaction.success();
            transaction.finish();
        } catch (Exception e) {
            e.printStackTrace()//To change body of catch statement use File | Settings | File Templates.
        }


        try {
            transaction = db.beginTx();
            index.add(node, "", "");
            transaction.success();
            transaction.finish();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // Request deletion
        index.delete();
        // Assert deletion
        assertFalse(indexMan.existsForNodes("layer1"));
        // TODO: we should probably check the internal structure was also cleanly deleted
    }
View Full Code Here

    }

    @Test
    public void testNodeIndex() throws SyntaxException, Exception {
        Map<String, String> config = SpatialIndexProvider.SIMPLE_POINT_CONFIG;
        IndexManager indexMan = db.index();
        Index<Node> index;
        Transaction tx = db.beginTx();
        index = indexMan.forNodes("layer1", config);
        assertNotNull(index);
        ExecutionEngine engine = new ExecutionEngine(db);
        ExecutionResult result1 = engine.execute("create (malmo{name:'Malmö',lat:56.2, lon:15.3})-[:TRAIN]->(stockholm{name:'Stockholm',lat:59.3,lon:18.0}) return malmo");
        Node malmo = (Node) result1.iterator().next().get("malmo");
        index.add(malmo, "dummy", "value");
View Full Code Here

    }

    @Test
    public void testWithinDistanceIndex() {
        Map<String, String> config = SpatialIndexProvider.SIMPLE_WKT_CONFIG;
        IndexManager indexMan = db.index();
        Index<Node> index;
        Transaction tx;
        tx = db.beginTx();
        index = indexMan.forNodes("layer2", config);
        Node batman = db.createNode();
        String wktPoint = "POINT(41.14 37.88 )";
        batman.setProperty("wkt", wktPoint);
        String batman1 = "batman";
        batman.setProperty("name", batman1);
View Full Code Here

    }

    @Test
    public void testWithinDistanceIndexViaCypher() {
        Map<String, String> config = SpatialIndexProvider.SIMPLE_WKT_CONFIG;
        IndexManager indexMan = db.index();
        Index<Node> index;
        try (Transaction tx = db.beginTx()) {
            index = indexMan.forNodes("layer3", config);
            Node robin = db.createNode();
            robin.setProperty("wkt", "POINT(44.44 33.33)");
            robin.setProperty("name", "robin");
            index.add(robin, "dummy", "value");
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.