@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(); } } ); } }
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); }
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); }
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); }
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 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"); }
phoneNumberIndex.add(caller, map("Number", number)); phoneNumberIndex.flush(); return caller;
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); }
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); }
void importIndex(String indexName, BatchInserterIndex index, Reader reader) throws IOException { final LineData data = createLineData(reader, 1); report.reset(); while (data.processLine(null)) { final Map<String, Object> properties = data.getProperties(); index.add(id(data.getValue(0)), properties); report.dots(); } report.finishImport("Done inserting into " + indexName + " Index"); }
void importRelationships(Reader reader) throws IOException { final int offset = 3; final LineData data = createLineData(reader, offset); final RelType relType = new RelType(); long skipped=0; report.reset(); while (data.processLine(null)) { final Map<String, Object> properties = data.getProperties(); final long start = id(data, 0); final long end = id(data, 1); if (start==-1 || end==-1) { skipped++; continue; } final RelType type = relType.update(data.getRelationshipTypeLabel()); final long id = db.createRelationship(start, end, type, properties); for (Map.Entry<String, Map<String, Object>> entry : data.getIndexData().entrySet()) { indexFor(entry.getKey()).add(id, entry.getValue()); } report.dots(); } String msg = "Relationships"; if (skipped > 0) msg += " skipped (" + skipped + ")"; report.finishImport(msg); }
void importNodes(Reader reader) throws IOException { final LineData data = createLineData(reader, 0); report.reset(); boolean hasId = data.hasId(); while (data.processLine(null)) { String[] labels = data.getTypeLabels(); long id; if (hasId) { id = data.getId(); db.createNode(id, data.getProperties(),labelsFor(labels)); } else { id = db.createNode(data.getProperties(),labelsFor(labels)); } for (Map.Entry<String, Map<String, Object>> entry : data.getIndexData().entrySet()) { final BatchInserterIndex index = indexFor(entry.getKey()); if (index==null) throw new IllegalStateException("Index "+entry.getKey()+" not configured."); index.add(id, entry.getValue()); } report.dots(); if (report.getCount() % BATCH == 0) flushIndexes(); } flushIndexes(); report.finishImport("Nodes"); }
@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(); } }