diff --git a/ala-name-matching-search/src/main/java/au/org/ala/names/search/ALANameSearcher.java b/ala-name-matching-search/src/main/java/au/org/ala/names/search/ALANameSearcher.java index 63559e8d..71433ba0 100644 --- a/ala-name-matching-search/src/main/java/au/org/ala/names/search/ALANameSearcher.java +++ b/ala-name-matching-search/src/main/java/au/org/ala/names/search/ALANameSearcher.java @@ -1183,16 +1183,11 @@ private List performSearch(List compulsoryValues, RankT } if (rank != null) { - int lower = rank.getId(); - int upper = rank.getId() >= RankType.SPECIES.getId() ? 9999 : rank.getId(); - BooleanQuery.Builder rankBuilder = new BooleanQuery.Builder(); - rankBuilder.add(NameIndexField.RANK_ID.searchRange(lower, upper), BooleanClause.Occur.SHOULD); - //cater for the situation where the search term could be a synonym that does not have a rank - // also ALA added concepts do NOT have ranks. - rankBuilder.add(NameIndexField.iS_SYNONYM.search("T"), BooleanClause.Occur.SHOULD); - rankBuilder.add(NameIndexField.ALA.search("T"), BooleanClause.Occur.SHOULD); + BooleanQuery.Builder rankBuilder = new BooleanQuery.Builder(); + rankBuilder.add(NameIndexField.RANK.search(rank.getRank()), BooleanClause.Occur.MUST); builder.add(rankBuilder.build(), BooleanClause.Occur.MUST); } + if (cl != null) { this.appendLuceneQuery(cl, builder, true); } diff --git a/ala-name-matching-search/src/test/java/au/org/ala/names/search/ALANameSearcherTest.java b/ala-name-matching-search/src/test/java/au/org/ala/names/search/ALANameSearcherTest.java index fcd6d480..7a7bdcb1 100644 --- a/ala-name-matching-search/src/test/java/au/org/ala/names/search/ALANameSearcherTest.java +++ b/ala-name-matching-search/src/test/java/au/org/ala/names/search/ALANameSearcherTest.java @@ -2205,4 +2205,20 @@ public void testPreferredVernacular2() throws Exception { assertEquals("Orange Roughy", metrics.getResult().getVernacularName()); } + @Test + // https://github.com/AtlasOfLivingAustralia/Taxonomic-Issues-Register_new/issues/161 + public void testSearchEucalyptus() throws Exception { + LinnaeanRankClassification cl = new LinnaeanRankClassification(); + cl.setGenus("Eucalyptus"); + cl.setSpecificEpithet("`hammonds rd'"); + cl.setScientificName("Eucalyptus `hammonds rd'"); + cl.setSubspecies("Eucalyptus pauciflora subsp. debeuzevillei"); + cl.setRank("species"); + + MetricsResultDTO metrics = searcher.searchForRecordMetrics(cl, true); + + assertNotNull(metrics); + // Without patching it returns "Eucalyptus de beuzevillei" + assertEquals("Eucalyptus", metrics.getResult().getRankClassification().getScientificName()); + } }