comparison src/main/java/de/mpiwg/itgroup/annotations/neo4j/AnnotationStore.java @ 101:7268c3ca025b

make admin ui view of all annotations scale better.
author casties
date Fri, 13 Feb 2015 18:10:11 +0100
parents 5a764c625290
children
comparison
equal deleted inserted replaced
100:f9ee715ee9e9 101:7268c3ca025b
59 * @author casties 59 * @author casties
60 * 60 *
61 */ 61 */
62 public class AnnotationStore { 62 public class AnnotationStore {
63 63
64 protected static Logger logger = Logger.getLogger("de.mpiwg.itgroup.annotations.neo4j.AnnotationStore"); 64 protected static Logger logger = Logger.getLogger(AnnotationStore.class.getCanonicalName());
65 65
66 protected GraphDatabaseService graphDb; 66 protected GraphDatabaseService graphDb;
67 67
68 public static enum NodeTypes { 68 public static enum NodeTypes {
69 ANNOTATION, PERSON, TARGET, GROUP, TAG, RESOURCE 69 ANNOTATION, PERSON, TARGET, GROUP, TAG, RESOURCE
254 List<Resource> targets = getUris(key, query, NodeTypes.RESOURCE); 254 List<Resource> targets = getUris(key, query, NodeTypes.RESOURCE);
255 return targets; 255 return targets;
256 } 256 }
257 257
258 /** 258 /**
259 * Returns the total number of Annotations.
260 *
261 * @return number of annotations
262 */
263 public int getAnnotationCount() {
264 int num = -1;
265 Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION);
266 try (Transaction tx = graphDb.beginTx()) {
267 IndexHits<Node> annotNodes = idx.query("id", "*");
268 num = annotNodes.size();
269 tx.success();
270 }
271 return num;
272 }
273
274 /**
259 * Returns List of Annotations. Key has to be indexed. 275 * Returns List of Annotations. Key has to be indexed.
260 * 276 *
261 * @param key 277 * @param key
262 * @param query 278 * @param query
263 * @return 279 * @param limit
264 */ 280 * @param offset
265 public List<Annotation> getAnnotations(String key, String query) { 281 * @return
282 */
283 public List<Annotation> getAnnotations(String key, String query, int limit, int offset) {
284 long ts = System.currentTimeMillis();
266 ArrayList<Annotation> annotations = new ArrayList<Annotation>(); 285 ArrayList<Annotation> annotations = new ArrayList<Annotation>();
267 Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION); 286 Index<Node> idx = getNodeIndex(NodeTypes.ANNOTATION);
268 if (key == null) { 287 if (key == null) {
269 key = "id"; 288 key = "id";
270 query = "*"; 289 query = "*";
271 } 290 }
272 try (Transaction tx = graphDb.beginTx()) { 291 try (Transaction tx = graphDb.beginTx()) {
273 IndexHits<Node> annotNodes = idx.query(key, query); 292 IndexHits<Node> annotNodes = idx.query(key, query);
293 int cnt = 0;
294 int max = offset + limit;
274 for (Node annotNode : annotNodes) { 295 for (Node annotNode : annotNodes) {
296 cnt += 1;
297 if (cnt < offset) continue;
275 Annotation annotation = createAnnotationFromNode(annotNode); 298 Annotation annotation = createAnnotationFromNode(annotNode);
276 annotations.add(annotation); 299 annotations.add(annotation);
277 } 300 if (limit > 0 && cnt >= max) {
278 tx.success(); 301 annotNodes.close();
279 } 302 break;
303 }
304 }
305 tx.success();
306 }
307 logger.finer("got "+annotations.size()+" annotations in "+(System.currentTimeMillis()-ts)+"ms");
280 return annotations; 308 return annotations;
281 } 309 }
282 310
283 /** 311 /**
284 * Returns List of Tags. Key has to be indexed. 312 * Returns List of Tags. Key has to be indexed.