public static void setupSchemaIndexes(GraphDatabaseService graphDb, Neo4jConfiguration config) { Map<String, Set<String>> schemaIndexes = config.getSchemaIndexes(); for (Map.Entry<String, Set<String>> entry : schemaIndexes.entrySet()) { Label label = Label.label(entry.getKey()); for (String property : entry.getValue()) { try (Transaction tx = graphDb.beginTx()) { Schema schema = graphDb.schema(); IndexDefinition indexDefinition = schema.indexFor(label).on(property).create(); tx.success(); tx.close(); Transaction tx2 = graphDb.beginTx(); schema.awaitIndexOnline(indexDefinition, 2, TimeUnit.MINUTES); tx2.success(); tx2.close(); } } } }
private WikiNerGraphConnector(String dbDir) { graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbDir); IndexDefinition indexDefinition; Schema schema; Transaction tx = graphDb.beginTx(); schema = graphDb.schema(); IndexManager index = graphDb.index(); entities = index.forNodes(entityLabel.name()); cities = index.forNodes(cityLabel.name()); try{ indexDefinition = schema.indexFor( entityLabel ).on( "nameType" ).create(); }catch(Exception e){ } tx.success(); tx.close(); }
public NeoProfile run(NeoProfiler parent) { SchemaProfile p = new SchemaProfile(); try(Transaction tx = parent.getDB().beginTx()) { Schema schema = parent.getDB().schema(); Iterator<ConstraintDefinition> constraints = schema.getConstraints().iterator(); while(constraints.hasNext()) { ConstraintDefinition c = constraints.next(); p.addConstraint(new NeoConstraint(true, false, c.getPropertyKeys(), c.getLabel(), c.getConstraintType())); } Iterator<IndexDefinition> idxs = schema.getIndexes().iterator(); while(idxs.hasNext()) { IndexDefinition idx = idxs.next(); p.addConstraint(new NeoConstraint(idx.isConstraintIndex(), true, idx.getPropertyKeys(), idx.getLabel(), null)); } } return p; }
public static void prepareSchema(GraphDatabaseService db) { try (Transaction tx = db.beginTx()) { Schema schema = db.schema(); schema.indexFor(NodeLabel.Class).on("name").create(); schema.indexFor(NodeLabel.Method).on("name").create(); schema.indexFor(NodeLabel.Annotation).on("name").create(); tx.success(); } }
@Test public void shouldLoadAndUseLuceneProvider() throws Exception { // GIVEN File storeDir = testDirectory.graphDbDir(); BatchInserter inserter = BatchInserters.inserter( storeDir ); inserter.createDeferredSchemaIndex( LABEL ).on( "name" ).create(); // WHEN inserter.createNode( map( "name", "Mattias" ), LABEL ); inserter.shutdown(); // THEN GraphDatabaseFactory graphDatabaseFactory = new TestGraphDatabaseFactory(); GraphDatabaseAPI db = (GraphDatabaseAPI) graphDatabaseFactory.newEmbeddedDatabase( storeDir ); DependencyResolver dependencyResolver = db.getDependencyResolver(); SchemaIndexProvider schemaIndexProvider = dependencyResolver.resolveDependency( SchemaIndexProvider.class, SchemaIndexProvider.HIGHEST_PRIORITIZED_OR_NONE ); // assert the indexProvider is a Lucene one try ( Transaction ignore = db.beginTx() ) { IndexDefinition indexDefinition = single( db.schema().getIndexes( LABEL ) ); assertThat( db.schema().getIndexState( indexDefinition ), is( Schema.IndexState.ONLINE ) ); assertThat( schemaIndexProvider, instanceOf( LuceneSchemaIndexProvider.class ) ); } // CLEANUP db.shutdown(); }
public void createIndexes() { try (Transaction tx = graphDb.beginTx()) { Schema schema = graphDb.schema(); schema.indexFor(DynamicLabel.label(LAB_SUBJECT)) .on(PROP_NAME).create(); tx.success(); } }
private NubDb(UsageDao dao, AuthorComparator authorComparator, boolean initialize) { this.dao = dao; authComp = authorComparator; // persistent indices? if (initialize) { try (Transaction tx = dao.beginTx()) { Schema schema = dao.getNeo().schema(); schema.indexFor(Labels.TAXON).on(NeoProperties.CANONICAL_NAME).create(); tx.success(); } } }
@Test public void testNeoIndices() throws Exception { final UUID datasetKey = datasetKey(1); Normalizer norm = Normalizer.create(cfg, datasetKey); norm.run(); openDb(datasetKey); compareStats(norm.getStats()); Set<String> taxonIndices = Sets.newHashSet(); taxonIndices.add(NeoProperties.TAXON_ID); taxonIndices.add(NeoProperties.SCIENTIFIC_NAME); taxonIndices.add(NeoProperties.CANONICAL_NAME); try (Transaction tx = beginTx()) { Schema schema = dao.getNeo().schema(); for (IndexDefinition idf : schema.getIndexes(Labels.TAXON)) { List<String> idxProps = Iterables.asList(idf.getPropertyKeys()); assertTrue(idxProps.size() == 1); assertTrue(taxonIndices.remove(idxProps.get(0))); } assertNotNull(Iterators.singleOrNull(dao.getNeo().findNodes(Labels.TAXON, NeoProperties.TAXON_ID, "1001"))); assertNotNull(Iterators.singleOrNull(dao.getNeo().findNodes(Labels.TAXON, NeoProperties.SCIENTIFIC_NAME, "Crepis bakeri Greene"))); assertNotNull(Iterators.singleOrNull(dao.getNeo().findNodes(Labels.TAXON, NeoProperties.CANONICAL_NAME, "Crepis bakeri"))); assertNull(Iterators.singleOrNull(dao.getNeo().findNodes(Labels.TAXON, NeoProperties.TAXON_ID, "x1001"))); assertNull(Iterators.singleOrNull(dao.getNeo().findNodes(Labels.TAXON, NeoProperties.SCIENTIFIC_NAME, "xCrepis bakeri Greene"))); assertNull(Iterators.singleOrNull(dao.getNeo().findNodes(Labels.TAXON, NeoProperties.CANONICAL_NAME, "xCrepis bakeri"))); } }
public void createIndex(){ try ( Transaction tx = graphDatabaseService.beginTx() ) { Schema schema = graphDatabaseService.schema(); if(schema.getIndexes(DynamicLabel.label("Variable")).iterator().hasNext()) { schema.indexFor(DynamicLabel.label("Variable")) .on("app_key") .create(); } if(schema.getIndexes(DynamicLabel.label("Method")).iterator().hasNext()) { schema.indexFor(DynamicLabel.label("Method")) .on("app_key") .create(); schema.indexFor(DynamicLabel.label("Method")) .on("is_static") .create(); } if(schema.getIndexes(DynamicLabel.label("Argument")).iterator().hasNext()) { schema.indexFor(DynamicLabel.label("Argument")) .on("app_key") .create(); schema.indexFor(DynamicLabel.label("Argument")) .on("app_key") .create(); } if(schema.getIndexes(DynamicLabel.label("ExternalClass")).iterator().hasNext()) { schema.indexFor(DynamicLabel.label("ExternalClass")) .on("app_key") .create(); } if(schema.getIndexes(DynamicLabel.label("ExternalMethod")).iterator().hasNext()) { schema.indexFor(DynamicLabel.label("ExternalMethod")) .on("app_key") .create(); } tx.success(); } try ( Transaction tx = graphDatabaseService.beginTx() ) { org.neo4j.graphdb.index.IndexManager index = graphDatabaseService.index(); if(!index.existsForRelationships("calls")) { index.forRelationships("calls"); } tx.success(); } }
private void deleteSomeSchemaIndices(final GraphDatabaseService database) throws DMPGraphException { MaintainResource.LOG.debug("start delete schema indices TX"); try (final Transaction itx = database.beginTx()) { final Schema schema = database.schema(); if (schema == null) { MaintainResource.LOG.debug("no schema available"); itx.success(); itx.close(); return; } final Iterable<IndexDefinition> indexDefinitions = schema.getIndexes(); if (indexDefinitions == null) { MaintainResource.LOG.debug("no schema indices available"); itx.success(); itx.close(); return; } for (final IndexDefinition indexDefinition : indexDefinitions) { MaintainResource.LOG.debug("drop '{}' : '{}' schema index", indexDefinition.getLabel().name(), indexDefinition.getPropertyKeys().iterator().next()); indexDefinition.drop(); } itx.success(); itx.close(); } catch (final Exception e) { final String message = "couldn't finish delete schema indices TX successfully"; MaintainResource.LOG.error(message, e); throw new DMPGraphException(message); } MaintainResource.LOG.debug("finished delete schema indices TX"); }