From 6cc9be75194e5cc1904347e15ec9f115d6b71bfd Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Thu, 20 Apr 2017 01:51:56 -0500 Subject: [PATCH] check if node exists --- src/main/java/com/maxdemarzi/search/Search.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/maxdemarzi/search/Search.java b/src/main/java/com/maxdemarzi/search/Search.java index f4dedb4..c1a4228 100644 --- a/src/main/java/com/maxdemarzi/search/Search.java +++ b/src/main/java/com/maxdemarzi/search/Search.java @@ -7,10 +7,7 @@ import com.maxdemarzi.users.Users; import org.codehaus.jackson.map.ObjectMapper; import org.neo4j.collection.primitive.PrimitiveLongIterator; -import org.neo4j.graphdb.Direction; -import org.neo4j.graphdb.GraphDatabaseService; -import org.neo4j.graphdb.Node; -import org.neo4j.graphdb.Transaction; +import org.neo4j.graphdb.*; import org.neo4j.kernel.api.ReadOperations; import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException; import org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException; @@ -149,8 +146,15 @@ public Response getLatest(@QueryParam("limit") @DefaultValue("25") final Integer int counter = 0; while (counter < limit && highId > -1) { - Node post = db.getNodeById(highId); - highId--; + Node post; + try { + post = db.getNodeById(highId); + } catch (NotFoundException e) { + continue; + } finally { + highId--; + } + if (post.getLabels().iterator().next().name().equals(Labels.Post.name())) { Long time = (Long) post.getProperty("time"); if (time < latest) {