public void verify(String dbPath) {
   EmbeddedGraphDatabase graphDb = new EmbeddedGraphDatabase(dbPath);
   assertEquals(
       "Reference node did not have zero relationships.",
       0,
       IteratorUtil.count(graphDb.getReferenceNode().getRelationships()));
   assertEquals("There was more than one node.", 1, IteratorUtil.count(graphDb.getAllNodes()));
   graphDb.shutdown();
 }
  @Override
  protected OperationResult executeOperation(
      IndexQueryNodeOnNeoPinEntertainmentVideoIndexOperation operation) {
    int resultCode;
    int result;

    Neo4jConnectionStateEmbedded connection = (Neo4jConnectionStateEmbedded) getDbConnectionState();
    Transaction tx = connection.getDb().beginTx();
    try {
      Iterator<Node> nodes =
          connection
              .getDb()
              .index()
              .forNodes(operation.getIndexName())
              .query(operation.getIndexQuery());

      resultCode = 0;
      result = IteratorUtil.count(nodes);
    } catch (Exception e) {
      resultCode = -1;
      result = 0;
    } finally {
      tx.finish();
    }

    return operation.buildResult(resultCode, result);
  }
Beispiel #3
0
  public static int getDocumentSizeForFeature(GraphDatabaseService db, Long id) {
    int documentSize;

    String cacheKey = "DOCUMENT_SIZE_FEATURE_" + id;

    if (vectorSpaceModelCache.getIfPresent(cacheKey) == null) {
      Node startNode = db.getNodeById(id);

      Iterator<Node> classes =
          db.traversalDescription()
              .depthFirst()
              .relationships(withName("HAS_CLASS"), Direction.OUTGOING)
              .evaluator(Evaluators.fromDepth(1))
              .evaluator(Evaluators.toDepth(1))
              .traverse(startNode)
              .nodes()
              .iterator();

      documentSize = IteratorUtil.count(classes);

      vectorSpaceModelCache.put(cacheKey, documentSize);
    } else {
      documentSize = (Integer) vectorSpaceModelCache.getIfPresent(cacheKey);
    }

    return documentSize;
  }
 private void countRelationships(Node node) {
   Transaction transaction = db.beginTx();
   try {
     count(node.getRelationships());
   } finally {
     transaction.finish();
   }
 }
 @Test
 public void createAndClearCacheBeforeCommit() {
   Node node = getGraphDb().createNode();
   clearCache();
   node.createRelationshipTo(getGraphDb().createNode(), TEST);
   clearCache();
   assertEquals(1, IteratorUtil.count(node.getRelationships()));
 }
 @Test
 public void listing3_10_node_labels() {
   usersAndMovies.addLabelToMovies();
   try (Transaction tx = graphDb.beginTx()) {
     ResourceIterable<Node> movies =
         GlobalGraphOperations.at(graphDb).getAllNodesWithLabel(DynamicLabel.label("MOVIES"));
     assertEquals(3, IteratorUtil.count(movies));
     tx.success();
   }
 }
Beispiel #7
0
 public static int getDocumentSize(GraphDatabaseService db) {
   int documentSize;
   String cacheKey = "GLOBAL_DOCUMENT_SIZE";
   if (vectorSpaceModelCache.getIfPresent(cacheKey) == null) {
     documentSize =
         IteratorUtil.count(
             GlobalGraphOperations.at(db).getAllNodesWithLabel(DynamicLabel.label("Class")));
     vectorSpaceModelCache.put(cacheKey, documentSize);
   } else {
     documentSize = (Integer) vectorSpaceModelCache.getIfPresent(cacheKey);
   }
   return documentSize;
 }
 @Test
 public void listing3_11_node_labels_and_property() {
   try {
     usersAndMovies.addLabelToMovies();
   } catch (Exception e) {
     // ignore if index already exist
   }
   try (Transaction tx = graphDb.beginTx()) {
     ResourceIterable<Node> movies =
         graphDb.findNodesByLabelAndProperty(DynamicLabel.label("MOVIES"), "name", "Fargo");
     assertEquals(1, IteratorUtil.count(movies));
     tx.success();
   }
 }
Beispiel #9
0
  @Ignore
  @Test
  public void testInsertionSpeed() {
    BatchInserter inserter = BatchInserters.inserter(new File(PATH, "3").getAbsolutePath());
    BatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider(inserter);
    BatchInserterIndex index = provider.nodeIndex("yeah", EXACT_CONFIG);
    index.setCacheCapacity("key", 1000000);
    long t = currentTimeMillis();
    for (int i = 0; i < 1000000; i++) {
      Map<String, Object> properties = map("key", "value" + i);
      long id = inserter.createNode(properties);
      index.add(id, properties);
    }
    System.out.println("insert:" + (currentTimeMillis() - t));
    index.flush();

    t = currentTimeMillis();
    for (int i = 0; i < 1000000; i++) {
      count((Iterator<Long>) index.get("key", "value" + i));
    }
    System.out.println("get:" + (currentTimeMillis() - t));
  }
 @Test
 @Transactional
 public void testFindAllGroupsByNonNumericIndexedNumber() {
   final Group group = new Group();
   final byte value = (byte) 100;
   group.setSecret(value);
   groupRepository.save(group);
   final PropertyContainer node = neo4jTemplate.getPersistentState(group);
   final Iterable<Group> found = this.groupRepository.findAllByPropertyValue("secret", value);
   assertEquals(1, IteratorUtil.count(found));
   final Node foundWithTemplate =
       neo4jTemplate.lookup("Group", "secret", value).to(Node.class).singleOrNull();
   assertEquals(node, foundWithTemplate);
   final Node foundGroup =
       neo4jTemplate
           .getGraphDatabaseService()
           .index()
           .forNodes("Group")
           .get("secret", value)
           .getSingle();
   assertEquals(node, foundGroup);
 }
 private void loadNode(GraphDatabaseAPI db, Node node) {
   try (Transaction ignored = db.beginTx()) {
     count(node.getRelationships());
   }
 }