TaxonSolrInputDocument extends BaseSolrInputDocument { public SolrInputDocument build() { indexRank(Rank.FAMILY, "family"); indexRank(Rank.Subfamily, "subfamily"); indexRank(Rank.GENUS, "genus"); indexRank(Rank.Tribe, "tribe"); indexRank(Rank.Subtribe, "subtribe"); addField(sid, "taxon.identifier_s", taxon.getIdentifier()); addField(sid, "taxon.infraspecific_epithet_s_lower", taxon.getInfraspecificEpithet()); addField(sid, "taxon.kingdom_s_lower", taxon.getKingdom()); addField(sid, "taxon.order_s_lower", taxon.getOrder()); addField(sid, "taxon.name_published_in_year_i", taxon.getNamePublishedInYear()); addField(sid, "taxon.name_published_in_s_lower", taxon.getNamePublishedInString()); addField(sid, "taxon.scientific_name_authorship_t", taxon.getScientificNameAuthorship()); addField(sid, "taxon.scientific_name_s_lower", taxon.getScientificName()); addField(sid, "taxon.specific_epithet_s_lower", taxon.getSpecificEpithet()); addField(sid, "taxon.rank_s_lower", Objects.toString(taxon.getTaxonRank(), null)); addField(sid, "taxon.taxonomic_status_s_lower", Objects.toString(taxon.getTaxonomicStatus(), null)); addField(sid, "taxon.is_accepted_b", taxon.isAccepted()); addField(sid, "taxon.looks_accepted_b", taxon.looksAccepted()); addField(sid, "taxon.is_unplaced_b", taxon.getTaxonomicStatus() == null); if(taxon.getTaxonRank() == Rank.SPECIES){ addField(sid, "taxon.species_s_lower", taxon.getScientificName()); } if(taxon.getSynonymNameUsages() != null && !taxon.getSynonymNameUsages().isEmpty()) { Set<Taxon> synonymList = taxon.getSynonymNameUsages(); for(Taxon synonym : synonymList){ addField(sid, "taxon.synonyms_ss_lower", synonym.getScientificName()); } } if(taxon.getAcceptedNameUsage() != null) { addField(sid, "taxon.accepted.identifier_s", taxon.getAcceptedNameUsage().getIdentifier()); addField(sid, "taxon.accepted.scientific_name_s_lower", taxon.getAcceptedNameUsage().getScientificName()); addField(sid, "taxon.accepted.scientific_name_authorship_t", taxon.getAcceptedNameUsage().getScientificNameAuthorship()); addField(sid, "taxon.accepted.kingdom_s", taxon.getAcceptedNameUsage().getKingdom()); } indexDescriptions(); indexDistributions(); indexVernacularNames(); indexMeasurementOrFacts(); indexImages(); addSuggestionWeight(); for(Reference r : taxon.getReferences()) { addSource(r); } for(String source : sources) { sid.addField("searchable.sources_ss", source); sid.addField("searchable.context_ss", normalized(source)); } buildSortField(); return sid; } TaxonSolrInputDocument(Taxon taxon);  TaxonSolrInputDocument(Taxon taxon, ApplicationContext ctx); static String propertyToSolrField(String propertyName, String type); static String solrFieldToProperty(String field); SolrInputDocument build();  }
@Test public void taxonRank() { Taxon taxon = new Taxon(); taxon.setTaxonRank(Rank.KINGDOM); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); String field = "taxon.rank_s_lower"; assertTrue("Expected " + field, doc.containsKey(field)); assertEquals(Rank.KINGDOM.toString(), doc.getFieldValue(field)); }
@Test public void taxonomicStatus() { Taxon taxon = new Taxon(); taxon.setTaxonomicStatus(TaxonomicStatus.Doubtful); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); String field = "taxon.taxonomic_status_s_lower"; assertTrue("Expected " + field, doc.containsKey(field)); assertEquals(TaxonomicStatus.Doubtful.toString(), doc.getFieldValue(field)); }
@Test public void descriptions() throws Exception { TestCase[] descriptionTests = { new TestCase().withDescription("Appearance description", DescriptionType.morphologyGeneral).andSolrFieldName("taxon.description_appearance_t"), new TestCase().withDescription("Flower description", DescriptionType.morphologyReproductiveFlower).andSolrFieldName("taxon.description_flower_t"), new TestCase().withDescription("Leaf description", DescriptionType.morphologyLeaf).andSolrFieldName("taxon.description_leaf_t"), new TestCase().withDescription("Inflorescence description", DescriptionType.morphologyReproductiveInflorescence).andSolrFieldName("taxon.description_inflorescence_t"), new TestCase().withDescription("Fruit description", DescriptionType.morphologyReproductiveFruit).andSolrFieldName("taxon.description_fruit_t"), new TestCase().withDescription("Seed description", DescriptionType.morphologyReproductiveSeed).andSolrFieldName("taxon.description_seed_t"), new TestCase().withDescription("Cloning description", DescriptionType.vegetativeMultiplication).andSolrFieldName("taxon.description_vegitativePropagation_t"), new TestCase().withDescription("Use description", DescriptionType.useAnimalFoodHerbage).andSolrFieldName("taxon.description_use_t") }; for(TestCase test : descriptionTests) { Taxon taxon = new Taxon(); taxon.setDescriptions(ImmutableSet.<Description>of(test.description)); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); assertTrue("Expected " + test.solrFieldName, doc.containsKey(test.solrFieldName)); assertEquals(test.description.getDescription(), doc.getFieldValue(test.solrFieldName)); } }
@Test public void measurements() { MeasurementOrFact measurement = new MeasurementOrFact(); measurement.setMeasurementUnit(MeasurementUnit.METERS); measurement.setMeasurementType(WCSPTerm.Lifeform); measurement.setMeasurementValue("42"); Taxon taxon = new Taxon(); taxon.setMeasurementsOrFacts(ImmutableSet.<MeasurementOrFact>of(measurement)); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); String expected = "taxon.measurement_lifeform_ds"; assertTrue("Expected " + expected, doc.containsKey(expected)); assertEquals(42.0, doc.getFieldValue(expected)); }
@Test public void facts() { MeasurementOrFact measurement = new MeasurementOrFact(); measurement.setMeasurementType(WCSPTerm.Habitat); measurement.setMeasurementValue("Xeric Scrubland"); Taxon taxon = new Taxon(); taxon.setMeasurementsOrFacts(ImmutableSet.<MeasurementOrFact>of(measurement)); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); String expected = "taxon.fact_habitat_ss"; assertTrue("Expected " + expected, doc.containsKey(expected)); assertEquals("Xeric Scrubland", doc.getFieldValue(expected)); }
@Test public void level0Distribution() { Distribution level0 = new Distribution(); level0.setLocation(Location.ANTARCTICA); Taxon taxon = new Taxon(); taxon.setDistribution(ImmutableSet.<Distribution>of(level0)); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); for(String expectedKey : expectedDistributionKeys) { assertTrue("Expected " + expectedKey, doc.containsKey(expectedKey)); } Object[] expectedLocationNames = { "Amsterdam-St.Paul Is.", "Antarctic", "Antarctic Continent", "Antarctica", "Bouvet I.", "Crozet Is.", "Falkland Is.", "Heard-McDonald Is.", "Kerguelen", "Macquarie Is.", "Marion-Prince Edward Is.", "South Georgia", "South Sandwich Is.", "Subantarctic Islands", "Tristan da Cunha" }; assertThat(doc.getFieldValues(expectedDistributionKeys[0]), contains(expectedLocationNames)); }
@Test public void level1Distribution() { Distribution level1 = new Distribution(); level1.setLocation(Location.SUBANTARCTIC_ISLANDS); Taxon taxon = new Taxon(); taxon.setDistribution(ImmutableSet.<Distribution>of(level1)); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); for(String expectedKey : expectedDistributionKeys) { assertTrue("Expected " + expectedKey, doc.containsKey(expectedKey)); } Object[] expectedLocationNames = { "Amsterdam-St.Paul Is.", "Antarctic", "Bouvet I.", "Crozet Is.", "Falkland Is.", "Heard-McDonald Is.", "Kerguelen", "Macquarie Is.", "Marion-Prince Edward Is.", "South Georgia", "South Sandwich Is.", "Subantarctic Islands", "Tristan da Cunha" }; assertThat(doc.getFieldValues(expectedDistributionKeys[0]), contains(expectedLocationNames)); }
@Test public void level2Distribution() { Distribution level2 = new Distribution(); level2.setLocation(Location.SSA); Taxon taxon = new Taxon(); taxon.setDistribution(ImmutableSet.<Distribution>of(level2)); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); for(String expectedKey : expectedDistributionKeys) { assertTrue("Expected " + expectedKey, doc.containsKey(expectedKey)); } Object[] expectedLocationNames = { "Antarctic", "South Sandwich Is.","Subantarctic Islands" }; assertThat(doc.getFieldValues(expectedDistributionKeys[0]), contains(expectedLocationNames)); }
@Test public void level3Distribution() { Distribution level3 = new Distribution(); level3.setLocation(Location.SSA_OO); Taxon taxon = new Taxon(); taxon.setDistribution(ImmutableSet.<Distribution>of(level3)); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); for(String expectedKey : expectedDistributionKeys) { assertTrue("Expected " + expectedKey, doc.containsKey(expectedKey)); } Object[] expectedLocationNames = { "Antarctic", "South Sandwich Is.","Subantarctic Islands" }; assertThat(doc.getFieldValues(expectedDistributionKeys[0]), contains(expectedLocationNames)); }
@Test public void testIndexingSynonymDataUnderAcceptedName() { Taxon taxon = new Taxon(); Taxon synonym = new Taxon(); Description description = buildDescription("Blarg", DescriptionType.general); Image image = new Image(); synonym.setDescriptions(ImmutableSet.<Description>of(description)); synonym.setImages(ImmutableList.<Image>of(image)); synonym.setTaxonomicStatus(TaxonomicStatus.Synonym); taxon.setSynonymNameUsages(ImmutableSet.<Taxon>of(synonym)); SolrInputDocument taxonDoc = new TaxonSolrInputDocument(taxon).build(); SolrInputDocument synonymDoc = new TaxonSolrInputDocument(synonym).build(); assertTrue("Expected taxon.description_t", taxonDoc.containsKey("taxon.description_t")); assertTrue("Expected taxon.descriptions_not_empty_b to be true", (Boolean)taxonDoc.getFieldValue("taxon.descriptions_not_empty_b")); assertTrue("Expected taxon.images_not_empty_b to be true", (Boolean)taxonDoc.getFieldValue("taxon.images_not_empty_b")); assertFalse("Didn't expect taxon.description_t", synonymDoc.containsKey("taxon.description_t")); assertFalse("Expected taxon.descriptions_not_empty_b to be false", (Boolean)synonymDoc.getFieldValue("taxon.descriptions_not_empty_b")); assertFalse("Expected taxon.images_not_empty_b to be false", (Boolean)synonymDoc.getFieldValue("taxon.images_not_empty_b")); }
@Test public void testFamilySortable() { Taxon taxon = new Taxon(); taxon.setTaxonRank(Rank.FAMILY); taxon.setFamily("Asteraceae"); taxon.setScientificName("Asteraceae"); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); assertEquals("325Asteraceae", doc.getFieldValue("sortable")); }
@Test public void testGenusSortable() { Taxon taxon = new Taxon(); taxon.setTaxonRank(Rank.GENUS); taxon.setFamily("Asteraceae"); taxon.setScientificName("Echinacea"); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); assertEquals("425AsteraceaeEchinacea", doc.getFieldValue("sortable")); }
@Test public void testBinomialSortable() { Taxon taxon = new Taxon(); taxon.setTaxonRank(Rank.SPECIES); taxon.setFamily("Asteraceae"); taxon.setScientificName("Echinacea purpurea"); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); assertEquals("600AsteraceaeEchinaceapurpurea", doc.getFieldValue("sortable")); }
@Test public void testTrinomialSortable() { Taxon taxon = new Taxon(); taxon.setTaxonRank(Rank.Form); taxon.setFamily("Asteraceae"); taxon.setScientificName("Hieracium sabaudum f. bladonii"); SolrInputDocument doc = new TaxonSolrInputDocument(taxon).build(); assertEquals("750AsteraceaeHieraciumsabaudumf.bladonii", doc.getFieldValue("sortable")); }