@Test public void linkingWithIdOnlyNoPath() throws NodeFactoryException { Taxon taxonFound = new TaxonImpl(null, "some id"); taxonIndex.getOrCreateTaxon(taxonFound); resolveNames(); new LinkerTaxonIndex().index(new GraphServiceFactoryProxy(getGraphDb())); try (Transaction transaction = getGraphDb().beginTx()) { IndexHits<Node> hits = getGraphDb() .index() .forNodes(LinkerTaxonIndex.INDEX_TAXON_NAMES_AND_IDS) .query("path:\"some id\""); assertThat(hits.hasNext(), is(true)); Node next = hits.next(); assertThat(new TaxonNode(next).getExternalId(), is("some id")); assertThat(hits.hasNext(), is(false)); hits.close(); transaction.success(); } }
@Override public void index(GraphServiceFactory factory) { GraphDatabaseService graphDb = factory.getGraphService(); Transaction tx = graphDb.beginTx(); try { Index<Node> taxons = graphDb.index().forNodes("taxons"); Index<Node> ids = graphDb.index().forNodes(INDEX_TAXON_NAMES_AND_IDS, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext")); TaxonFuzzySearchIndex fuzzySearchIndex = new TaxonFuzzySearchIndex(graphDb); IndexHits<Node> hits = taxons.query("*:*"); for (Node hit : hits) { List<String> taxonIds = new ArrayList<>(); List<String> taxonPathIdsAndNames = new ArrayList<>(); TaxonNode taxonNode = new TaxonNode(hit); addTaxonId(taxonIds, taxonNode); addPathIdAndNames(taxonPathIdsAndNames, taxonNode); addToFuzzyIndex(graphDb, fuzzySearchIndex, hit, taxonNode); Iterable<Relationship> rels = hit.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.SAME_AS)); for (Relationship rel : rels) { TaxonNode sameAsTaxon = new TaxonNode(rel.getEndNode()); addTaxonId(taxonIds, sameAsTaxon); addPathIdAndNames(taxonPathIdsAndNames, sameAsTaxon); addToFuzzyIndex(graphDb, fuzzySearchIndex, hit, sameAsTaxon); } taxonPathIdsAndNames.addAll(taxonIds); String aggregateIds = StringUtils.join(taxonPathIdsAndNames.stream().distinct().sorted().collect(Collectors.toList()), CharsetConstant.SEPARATOR); ids.add(hit, PropertyAndValueDictionary.PATH, aggregateIds); hit.setProperty(PropertyAndValueDictionary.EXTERNAL_IDS, aggregateIds); String aggregateTaxonIds = StringUtils.join(taxonIds.stream().distinct().sorted().collect(Collectors.toList()), CharsetConstant.SEPARATOR); hit.setProperty(PropertyAndValueDictionary.NAME_IDS, aggregateTaxonIds); tx.success(); tx.close(); tx = graphDb.beginTx(); } hits.close(); tx.success(); } finally { tx.close(); } }
LinkerTaxonIndex implements IndexerNeo4j { @Override public void index(GraphServiceFactory factory) { GraphDatabaseService graphDb = factory.getGraphService(); Transaction tx = graphDb.beginTx(); try { Index<Node> taxons = graphDb.index().forNodes("taxons"); Index<Node> ids = graphDb.index().forNodes(INDEX_TAXON_NAMES_AND_IDS, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext")); TaxonFuzzySearchIndex fuzzySearchIndex = new TaxonFuzzySearchIndex(graphDb); IndexHits<Node> hits = taxons.query("*:*"); for (Node hit : hits) { List<String> taxonIds = new ArrayList<>(); List<String> taxonPathIdsAndNames = new ArrayList<>(); TaxonNode taxonNode = new TaxonNode(hit); addTaxonId(taxonIds, taxonNode); addPathIdAndNames(taxonPathIdsAndNames, taxonNode); addToFuzzyIndex(graphDb, fuzzySearchIndex, hit, taxonNode); Iterable<Relationship> rels = hit.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.SAME_AS)); for (Relationship rel : rels) { TaxonNode sameAsTaxon = new TaxonNode(rel.getEndNode()); addTaxonId(taxonIds, sameAsTaxon); addPathIdAndNames(taxonPathIdsAndNames, sameAsTaxon); addToFuzzyIndex(graphDb, fuzzySearchIndex, hit, sameAsTaxon); } taxonPathIdsAndNames.addAll(taxonIds); String aggregateIds = StringUtils.join(taxonPathIdsAndNames.stream().distinct().sorted().collect(Collectors.toList()), CharsetConstant.SEPARATOR); ids.add(hit, PropertyAndValueDictionary.PATH, aggregateIds); hit.setProperty(PropertyAndValueDictionary.EXTERNAL_IDS, aggregateIds); String aggregateTaxonIds = StringUtils.join(taxonIds.stream().distinct().sorted().collect(Collectors.toList()), CharsetConstant.SEPARATOR); hit.setProperty(PropertyAndValueDictionary.NAME_IDS, aggregateTaxonIds); tx.success(); tx.close(); tx = graphDb.beginTx(); } hits.close(); tx.success(); } finally { tx.close(); } } }
LinkerTaxonIndex implements IndexerNeo4j { @Override public void index(GraphServiceFactory factory) { GraphDatabaseService graphDb = factory.getGraphService(); Transaction tx = graphDb.beginTx(); try { Index<Node> taxons = graphDb.index().forNodes("taxons"); Index<Node> ids = graphDb.index().forNodes(INDEX_TAXON_NAMES_AND_IDS, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext")); TaxonFuzzySearchIndex fuzzySearchIndex = new TaxonFuzzySearchIndex(graphDb); IndexHits<Node> hits = taxons.query("*:*"); for (Node hit : hits) { List<String> taxonIds = new ArrayList<>(); List<String> taxonPathIdsAndNames = new ArrayList<>(); TaxonNode taxonNode = new TaxonNode(hit); addTaxonId(taxonIds, taxonNode); addPathIdAndNames(taxonPathIdsAndNames, taxonNode); addToFuzzyIndex(graphDb, fuzzySearchIndex, hit, taxonNode); Iterable<Relationship> rels = hit.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.SAME_AS)); for (Relationship rel : rels) { TaxonNode sameAsTaxon = new TaxonNode(rel.getEndNode()); addTaxonId(taxonIds, sameAsTaxon); addPathIdAndNames(taxonPathIdsAndNames, sameAsTaxon); addToFuzzyIndex(graphDb, fuzzySearchIndex, hit, sameAsTaxon); } taxonPathIdsAndNames.addAll(taxonIds); String aggregateIds = StringUtils.join(taxonPathIdsAndNames.stream().distinct().sorted().collect(Collectors.toList()), CharsetConstant.SEPARATOR); ids.add(hit, PropertyAndValueDictionary.PATH, aggregateIds); hit.setProperty(PropertyAndValueDictionary.EXTERNAL_IDS, aggregateIds); String aggregateTaxonIds = StringUtils.join(taxonIds.stream().distinct().sorted().collect(Collectors.toList()), CharsetConstant.SEPARATOR); hit.setProperty(PropertyAndValueDictionary.NAME_IDS, aggregateTaxonIds); tx.success(); tx.close(); tx = graphDb.beginTx(); } hits.close(); tx.success(); } finally { tx.close(); } }  }
LinkerTaxonIndex implements IndexerNeo4j { @Override public void index(GraphServiceFactory factory) { GraphDatabaseService graphDb = factory.getGraphService(); Transaction tx = graphDb.beginTx(); try { Index<Node> taxons = graphDb.index().forNodes("taxons"); Index<Node> ids = graphDb.index().forNodes(INDEX_TAXON_NAMES_AND_IDS, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext")); TaxonFuzzySearchIndex fuzzySearchIndex = new TaxonFuzzySearchIndex(graphDb); IndexHits<Node> hits = taxons.query("*:*"); for (Node hit : hits) { List<String> taxonIds = new ArrayList<>(); List<String> taxonPathIdsAndNames = new ArrayList<>(); TaxonNode taxonNode = new TaxonNode(hit); addTaxonId(taxonIds, taxonNode); addPathIdAndNames(taxonPathIdsAndNames, taxonNode); addToFuzzyIndex(graphDb, fuzzySearchIndex, hit, taxonNode); Iterable<Relationship> rels = hit.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.SAME_AS)); for (Relationship rel : rels) { TaxonNode sameAsTaxon = new TaxonNode(rel.getEndNode()); addTaxonId(taxonIds, sameAsTaxon); addPathIdAndNames(taxonPathIdsAndNames, sameAsTaxon); addToFuzzyIndex(graphDb, fuzzySearchIndex, hit, sameAsTaxon); } taxonPathIdsAndNames.addAll(taxonIds); String aggregateIds = StringUtils.join(taxonPathIdsAndNames.stream().distinct().sorted().collect(Collectors.toList()), CharsetConstant.SEPARATOR); ids.add(hit, PropertyAndValueDictionary.PATH, aggregateIds); hit.setProperty(PropertyAndValueDictionary.EXTERNAL_IDS, aggregateIds); String aggregateTaxonIds = StringUtils.join(taxonIds.stream().distinct().sorted().collect(Collectors.toList()), CharsetConstant.SEPARATOR); hit.setProperty(PropertyAndValueDictionary.NAME_IDS, aggregateTaxonIds); tx.success(); tx.close(); tx = graphDb.beginTx(); } hits.close(); tx.success(); } finally { tx.close(); } }  @Override void index(GraphServiceFactory factory); }
LinkerTaxonIndex implements IndexerNeo4j { @Override public void index(GraphServiceFactory factory) { GraphDatabaseService graphDb = factory.getGraphService(); Transaction tx = graphDb.beginTx(); try { Index<Node> taxons = graphDb.index().forNodes("taxons"); Index<Node> ids = graphDb.index().forNodes(INDEX_TAXON_NAMES_AND_IDS, MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type", "fulltext")); TaxonFuzzySearchIndex fuzzySearchIndex = new TaxonFuzzySearchIndex(graphDb); IndexHits<Node> hits = taxons.query("*:*"); for (Node hit : hits) { List<String> taxonIds = new ArrayList<>(); List<String> taxonPathIdsAndNames = new ArrayList<>(); TaxonNode taxonNode = new TaxonNode(hit); addTaxonId(taxonIds, taxonNode); addPathIdAndNames(taxonPathIdsAndNames, taxonNode); addToFuzzyIndex(graphDb, fuzzySearchIndex, hit, taxonNode); Iterable<Relationship> rels = hit.getRelationships(Direction.OUTGOING, NodeUtil.asNeo4j(RelTypes.SAME_AS)); for (Relationship rel : rels) { TaxonNode sameAsTaxon = new TaxonNode(rel.getEndNode()); addTaxonId(taxonIds, sameAsTaxon); addPathIdAndNames(taxonPathIdsAndNames, sameAsTaxon); addToFuzzyIndex(graphDb, fuzzySearchIndex, hit, sameAsTaxon); } taxonPathIdsAndNames.addAll(taxonIds); String aggregateIds = StringUtils.join(taxonPathIdsAndNames.stream().distinct().sorted().collect(Collectors.toList()), CharsetConstant.SEPARATOR); ids.add(hit, PropertyAndValueDictionary.PATH, aggregateIds); hit.setProperty(PropertyAndValueDictionary.EXTERNAL_IDS, aggregateIds); String aggregateTaxonIds = StringUtils.join(taxonIds.stream().distinct().sorted().collect(Collectors.toList()), CharsetConstant.SEPARATOR); hit.setProperty(PropertyAndValueDictionary.NAME_IDS, aggregateTaxonIds); tx.success(); tx.close(); tx = graphDb.beginTx(); } hits.close(); tx.success(); } finally { tx.close(); } }  @Override void index(GraphServiceFactory factory); static final String INDEX_TAXON_NAMES_AND_IDS; }