@Test void explicitIndexPopulationWithBunchOfFields() { assertTimeout( ofMillis( TEST_TIMEOUT ), () -> { BatchInserter batchNode = BatchInserters.inserter( directory.databaseDir() ); LuceneBatchInserterIndexProvider provider = new LuceneBatchInserterIndexProvider( batchNode ); try { BatchInserterIndex batchIndex = provider.nodeIndex( "node_auto_index", stringMap( IndexManager.PROVIDER, "lucene", "type", "fulltext" ) ); Map<String,Object> properties = IntStream.range( 0, 2000 ) .mapToObj( i -> Pair.of( Integer.toString( i ), randomAlphabetic( 200 ) ) ) .collect( toMap( Pair::first, Pair::other ) ); long node = batchNode.createNode( properties, Label.label( "NODE" ) ); batchIndex.add( node, properties ); } finally { provider.shutdown(); batchNode.shutdown(); } } ); } }
/** * This is required before querying the index for data. * This method is not a standard Index API method and thus, be sure to typecast the index to Neo4j2BatchIndex. */ public void flush() { this.rawIndex.flush(); }
final LuceneBatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(db); phoneNumberIndex = indexProvider.nodeIndex("Caller", MapUtil.stringMap("type", "exact")); phoneNumberIndex.setCacheCapacity("Caller", 1000000); phoneNumberIndex.add(caller, map("Number", number)); phoneNumberIndex.flush(); return caller;
@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(); } }
public CloseableIterable<T> get(final String key, final Object value) { if (Vertex.class.isAssignableFrom(this.indexClass)) return (CloseableIterable<T>) new Neo4j2BatchVertexIterable(this.graph, this.rawIndex.get(key, value)); else return (CloseableIterable<T>) new Neo4j2BatchEdgeIterable(this.graph, this.rawIndex.get(key, value)); }
public CloseableIterable<T> query(final String key, final Object query) { if (Vertex.class.isAssignableFrom(this.indexClass)) return (CloseableIterable<T>) new Neo4jBatchVertexIterable(this.graph, this.rawIndex.query(key, query)); else return (CloseableIterable<T>) new Neo4jBatchEdgeIterable(this.graph, this.rawIndex.query(key, query)); }
public CloseableIterable<T> get(final String key, final Object value) { if (Vertex.class.isAssignableFrom(this.indexClass)) return (CloseableIterable<T>) new Neo4jBatchVertexIterable(this.graph, this.rawIndex.get(key, value)); else return (CloseableIterable<T>) new Neo4jBatchEdgeIterable(this.graph, this.rawIndex.get(key, value)); }
public CloseableIterable<T> query(final String key, final Object query) { if (Vertex.class.isAssignableFrom(this.indexClass)) return (CloseableIterable<T>) new Neo4j2BatchVertexIterable(this.graph, this.rawIndex.query(key, query)); else return (CloseableIterable<T>) new Neo4j2BatchEdgeIterable(this.graph, this.rawIndex.query(key, query)); }
public void indexNodeUsingBatchIndexer(BatchInserterIndexProvider indexProvider, EntityMetadata entityMetadata, long nodeId, Map<String, Object> nodeProperties, boolean nodeAutoIndexingEnabled) { BatchInserterIndex nodeIndex = null; if (!nodeAutoIndexingEnabled && entityMetadata.isIndexable()) { nodeIndex = indexProvider.nodeIndex(entityMetadata.getIndexName(), MapUtil.stringMap("type", "exact")); } else { nodeIndex = indexProvider.nodeIndex("node_auto_index", MapUtil.stringMap("type", "exact")); } if (nodeIndex != null) nodeIndex.add(nodeId, nodeProperties); }
/** * This is required before querying the index for data. * This method is not a standard Index API method and thus, be sure to typecast the index to Neo4jBatchIndex. */ public void flush() { this.rawIndex.flush(); }
private long lookup(String index,String property,Object value) { Long id = indexFor(index).get(property, value).getSingle(); return id==null ? -1 : id; }
public void indexRelationshipUsingBatchIndexer(BatchInserterIndexProvider indexProvider, EntityMetadata entityMetadata, long relationshipId, Map<String, Object> relationshipProperties, boolean relationshipAutoIndexingEnabled) { BatchInserterIndex relationshipIndex = null; if (!relationshipAutoIndexingEnabled && entityMetadata.isIndexable()) { relationshipIndex = indexProvider.relationshipIndex(entityMetadata.getIndexName(), MapUtil.stringMap("type", "exact")); } else { relationshipIndex = indexProvider.relationshipIndex("relationship_auto_index", MapUtil.stringMap("type", "exact")); } if (relationshipIndex != null) relationshipIndex.add(relationshipId, relationshipProperties); }
@Override public void flush() { index.flush(); }
public void put(final String key, final Object value, final T element) { final Map<String, Object> map = new HashMap<String, Object>(); map.put(key, value); this.rawIndex.add((Long) element.getId(), map); }
private void flushIndexes() { for (BatchInserterIndex index : indexes.values()) { index.flush(); } }
public void put(final String key, final Object value, final T element) { final Map<String, Object> map = new HashMap<String, Object>(); map.put(key, value); this.rawIndex.add((Long) element.getId(), map); }
@Override public void shutdown() { index(); nodeIndex.flush(); indexProvider.shutdown(); inserter.shutdown(); }
@Override public void add(long entityId, Map<String, Object> properties) { for (Map.Entry<String, Object> entry : properties.entrySet()) { getSet(entry.getKey()).add(Fun.t2(entry.getValue(), entityId)); } index.add(entityId,properties); }
void index() { logger.info("Starting indexing"); List<Long> ids = newArrayList(idMap.values()); //TODO: Evaluate the performance of using a BTreeMap instead of sorting here. Collections.sort(ids); for (long id: ids) { Map<String, Object> properties = inserter.getNodeProperties(id); Map<String, Object> indexProperties = collectIndexProperties(properties); if (!indexProperties.isEmpty()) { nodeIndex.add(id, indexProperties); } } logger.info("Finished indexing"); }
public void indexNodeUsingBatchIndexer(BatchInserterIndexProvider indexProvider, EntityMetadata entityMetadata, long nodeId, Map<String, Object> nodeProperties, boolean nodeAutoIndexingEnabled) { BatchInserterIndex nodeIndex = null; if (!nodeAutoIndexingEnabled && entityMetadata.isIndexable()) { nodeIndex = indexProvider.nodeIndex(entityMetadata.getIndexName(), MapUtil.stringMap("type", "exact")); } else { nodeIndex = indexProvider.nodeIndex("node_auto_index", MapUtil.stringMap("type", "exact")); } if (nodeIndex != null) nodeIndex.add(nodeId, nodeProperties); }