@Override public IndexHits<T> query( Object queryOrQueryObject ) { return delegate.query( queryOrQueryObject ); }
@Override public IndexHits<T> query( String key, Object queryOrQueryObject ) { return delegate.query( key, queryOrQueryObject ); }
public ListRepresentation getAutoIndexedRelationshipsByQuery( String query ) { final ReadableIndex<Relationship> index = graphDb.index().getRelationshipAutoIndexer().getAutoIndex(); final IndexHits<Relationship> results = query != null ? index.query( query ) : null; return toListRelationshipRepresentation( results, null ); }
public ListRepresentation getAutoIndexedNodesByQuery( String query ) { if ( query != null ) { ReadableIndex<Node> index = graphDb.index().getNodeAutoIndexer().getAutoIndex(); return toListNodeRepresentation( index.query( query ), null ); } return toListNodeRepresentation(); }
@Override public IndexHits<T> query( Object queryOrQueryObject ) { return delegate.query( queryOrQueryObject ); }
@Override public IndexHits<T> query( String key, Object queryOrQueryObject ) { return delegate.query( key, queryOrQueryObject ); }
/** * Execute lucene query. * * @param m * the m * @param luceneQuery * the lucene query * @return the list */ public List<Object> executeLuceneQuery(EntityMetadata m, String luceneQuery) { log.info("Executing Lucene Query on Neo4J:" + luceneQuery); GraphDatabaseService graphDb = getConnection(); List<Object> entities = new ArrayList<Object>(); if (!indexer.isNodeAutoIndexingEnabled(graphDb) && m.isIndexable()) { Index<Node> nodeIndex = graphDb.index().forNodes(m.getIndexName()); IndexHits<Node> hits = nodeIndex.query(luceneQuery); addEntityFromIndexHits(m, entities, hits); } else { ReadableIndex<Node> autoNodeIndex = graphDb.index().getNodeAutoIndexer().getAutoIndex(); IndexHits<Node> hits = autoNodeIndex.query(luceneQuery); addEntityFromIndexHits(m, entities, hits); } return entities; }
public ListRepresentation getAutoIndexedRelationshipsByQuery( String query ) { final ReadableIndex<Relationship> index = graphDb.index().getRelationshipAutoIndexer().getAutoIndex(); final IndexHits<Relationship> results = query != null ? index.query( query ) : null; return toListRelationshipRepresentation( results, null ); }
public ListRepresentation getAutoIndexedNodesByQuery( String query ) { if ( query != null ) { ReadableIndex<Node> index = graphDb.index().getNodeAutoIndexer().getAutoIndex(); return toListNodeRepresentation( index.query( query ), null ); } return toListNodeRepresentation(); }
@Test public void testMultiplePropertyValueIndex() { graph.addNodeProperty(foo, "prop1", "foo"); graph.addNodeProperty(foo, "prop1", "bar"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:foo"); assertThat(hits.size(), is(1)); hits = nodeIndex.query("prop1:bar"); assertThat(hits.size(), is(1)); }
@Test public void testMultiplePropertyNameIndex() { graph.addNodeProperty(foo, "prop1", "foo"); graph.addNodeProperty(foo, "prop2", "bar"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:foo"); assertThat(hits.size(), is(1)); hits = nodeIndex.query("prop2:bar"); assertThat(hits.size(), is(1)); }
@Test public void testReplacePropertyIndex() { graph.setNodeProperty(foo, "prop1", "foo"); graph.setNodeProperty(foo, "prop1", "bar"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:foo"); assertThat(hits.size(), is(0)); hits = nodeIndex.query("prop1:bar"); assertThat(hits.size(), is(1)); }
@Test public void testNodeCreation() { GraphDatabaseService graphDb = getGraphDB(); assertThat(size(graphDb.getAllNodes()), is(1)); //IndexHits<Node> hits = nodeIndex.query(CommonProperties.IRI + ":http\\://example.org/foo"); IndexHits<Node> hits = nodeIndex.query(CommonProperties.IRI + ":http\\:\\/\\/example.org\\/foo"); assertThat(hits.getSingle().getId(), is(foo)); }
@Test public void testPropertyIndex() { graph.addNodeProperty(foo, "prop1", "foo"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:foo"); assertThat(hits.getSingle().getId(), is(foo)); }
@Test public void testExactPropertyIndex() { graph.addNodeProperty(foo, "prop1", "foo"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1" + LuceneUtils.EXACT_SUFFIX + ":foo"); assertThat(hits.getSingle().getId(), is(foo)); }
@Test public void testPropertySetting() { graph.addNodeProperty(foo, "prop1", "foo"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:foo"); assertThat((String)hits.getSingle().getProperty("prop1"), is("foo")); }
@Test public void testMultiplePropertySetting() { graph.addNodeProperty(foo, "prop1", "bar"); graph.addNodeProperty(foo, "prop1", "baz"); getGraphDB(); IndexHits<Node> hits = nodeIndex.query("prop1:bar"); assertThat((String[])hits.getSingle().getProperty("prop1"), is(arrayContaining("bar", "baz"))); }
/** * Execute lucene query. * * @param m * the m * @param luceneQuery * the lucene query * @return the list */ public List<Object> executeLuceneQuery(EntityMetadata m, String luceneQuery) { log.info("Executing Lucene Query on Neo4J:" + luceneQuery); GraphDatabaseService graphDb = getConnection(); List<Object> entities = new ArrayList<Object>(); if (!indexer.isNodeAutoIndexingEnabled(graphDb) && m.isIndexable()) { Index<Node> nodeIndex = graphDb.index().forNodes(m.getIndexName()); IndexHits<Node> hits = nodeIndex.query(luceneQuery); addEntityFromIndexHits(m, entities, hits); } else { ReadableIndex<Node> autoNodeIndex = graphDb.index().getNodeAutoIndexer().getAutoIndex(); IndexHits<Node> hits = autoNodeIndex.query(luceneQuery); addEntityFromIndexHits(m, entities, hits); } return entities; }
IndexHits<Node> hits = null; try (Transaction tx = graph.beginTx()) { hits = graph.index().getNodeAutoIndexer().getAutoIndex().query(finalQuery); tx.success(); return limitHits(hits, query);
@Test public void testBatchIndexToAutoIndex() throws IOException { BatchInserter inserter = BatchInserters.inserter(new File(path)); BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter); BatchInserterIndex index = indexProvider.nodeIndex("node_auto_index", MapUtil.stringMap("type", "exact")); long node = inserter.createNode(MapUtil.map("foo", "bar")); index.add(node, MapUtil.map("foo", "bar")); index.flush(); assertThat("Batch indexed node can be retrieved", index.get("foo", "bar").next(), is(node)); indexProvider.shutdown(); inserter.shutdown(); graphDb = getGraphDb(); try (Transaction tx = graphDb.beginTx()) { assertThat("AutoIndex is not enabled after reopening the graph", graphDb.index() .getNodeAutoIndexer().isEnabled(), is(false)); assertThat("AutoIndexed properties are not maintained after closing the graph", graphDb .index().getNodeAutoIndexer().getAutoIndexedProperties(), is(empty())); assertThat("Batch index properties are in the index", graphDb.index().getNodeAutoIndexer() .getAutoIndex().query("foo", "bar").size(), is(1)); tx.success(); } }