Project

General

Profile

Revision 5c379961

ID5c37996156a6aefec371887beb7021a6f3cc1c1b
Parent 844a678f
Child babaee94

Added by Andreas Müller over 3 years ago

rel #7478 implement pro parte synonym search in free text taxon and name search

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java
1823 1823
        }
1824 1824

  
1825 1825
        // search by misapplied names
1826
        if(searchModes.contains(TaxaAndNamesSearchMode.doMisappliedNames)) {
1826
        if(searchModes.contains(TaxaAndNamesSearchMode.doMisappliedNames) /*|| searchModes.contains(TaxaAndNamesSearchMode.doSynonyms) */) {
1827 1827
            // NOTE:
1828 1828
            // prepareFindByTaxonRelationFullTextSearch() is making use of JoinUtil.createJoinQuery()
1829 1829
            // which allows doing query time joins
1830 1830
            // finds the misapplied name (Taxon B) which is an misapplication for
1831 1831
            // a related Taxon A.
1832 1832
            //
1833
            Set<TaxonRelationshipType> relTypes = new HashSet<>();
1834
            if (searchModes.contains(TaxaAndNamesSearchMode.doMisappliedNames)){
1835
                relTypes.addAll(TaxonRelationshipType.allMisappliedNameTypes());
1836
            }
1837
//            if (searchModes.contains(TaxaAndNamesSearchMode.doSynonyms)){
1838
//                relTypes.addAll(TaxonRelationshipType.allSynonymTypes());
1839
//            }
1840

  
1833 1841
            luceneSearches.add(prepareFindByTaxonRelationFullTextSearch(
1834
                    new TaxonRelationshipEdge(TaxonRelationshipType.allMisappliedNameTypes(), Direction.relatedTo),
1842
                    new TaxonRelationshipEdge(relTypes, Direction.relatedTo),
1835 1843
                    queryString, classification, includeUnpublished, languages, highlightFragments, sortFields));
1836 1844
            idFieldMap.put(CdmBaseType.TAXON, "id");
1837 1845

  
......
1879 1887
            }
1880 1888
        }
1881 1889

  
1890
        // search by pro parte synonyms
1891
        if(searchModes.contains(TaxaAndNamesSearchMode.doSynonyms)) {
1892
            //TODO merge with misapplied name search once #7486 is fixed
1893
            Set<TaxonRelationshipType> relTypes = new HashSet<>();
1894
            relTypes.addAll(TaxonRelationshipType.allSynonymTypes());
1895

  
1896
            luceneSearches.add(prepareFindByTaxonRelationFullTextSearch(
1897
                    new TaxonRelationshipEdge(relTypes, Direction.relatedTo),
1898
                    queryString, classification, includeUnpublished, languages, highlightFragments, sortFields));
1899
            idFieldMap.put(CdmBaseType.TAXON, "id");
1900

  
1901
            if(addDistributionFilter){
1902
                String fromField = "inDescription.taxon.id"; // in DescriptionElementBase index
1903
                String toField = "relation.8a896603-0fa3-44c6-9cd7-df2d8792e577.to.id";
1904
                BooleanQuery byDistributionQuery = createByDistributionQuery(namedAreaList, distributionStatusList, distributionFilterQueryFactory);
1905
                Query taxonAreaJoinQuery = distributionFilterQueryFactory.newJoinQuery(Distribution.class,
1906
                        fromField, true, byDistributionQuery, toField, null, ScoreMode.None);
1907
                multiIndexByAreaFilterBuilder.add(taxonAreaJoinQuery, Occur.SHOULD);
1908
            }
1909
        }//end pro parte synonyms
1910

  
1882 1911

  
1883 1912
        LuceneMultiSearch multiSearch = new LuceneMultiSearch(luceneIndexToolProvider,
1884 1913
                luceneSearches.toArray(new LuceneSearch[luceneSearches.size()]));
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/service/TaxonServiceSearchTest.java
95 95
    private static final UUID D_ABIES_ALBA_UUID = UUID.fromString("ec8bba03-d993-4c85-8472-18b14942464b");
96 96
    private static final UUID D_ABIES_KAWAKAMII_SEC_KOMAROV_UUID = UUID.fromString("e9d8c2fd-6409-46d5-9c2e-14a2bbb1b2b1");
97 97
    private static final UUID ABIES_SUBALPINA_UUID = UUID.fromString("9fee273c-c819-4f1f-913a-cd910465df51");
98
    private static final UUID ABIES_LASIOCARPA_UUID = UUID.fromString("9ce1fecf-c1ad-4127-be01-85d5d9f847ce");
98 99

  
99 100
    private static final int NUM_OF_NEW_RADOM_ENTITIES = 1000;
100 101

  
......
900 901
        pager = taxonService.findTaxaAndNamesByFullText(
901 902
                EnumSet.of(TaxaAndNamesSearchMode.doSynonyms, TaxaAndNamesSearchMode.includeUnpublished),
902 903
                "Abies", null, null, null, null, true, null, null, null, null);
903
        Assert.assertEquals("Expecting 1 entity", 1, pager.getCount().intValue());
904
        Assert.assertEquals(Synonym.class, pager.getRecords().get(0).getEntity().getClass());
904
        Assert.assertEquals("Expecting 2 entity", 2, pager.getCount().intValue());
905
        Set<UUID> uuids = getTaxonUuidSet(pager);
906
        Assert.assertTrue("The real synonym should be contained", uuids.contains(ABIES_SUBALPINA_UUID));
907
        Assert.assertTrue("The pro parte synonym should be contained",uuids.contains(ABIES_LASIOCARPA_UUID));
905 908
        //without published
906 909
        pager = taxonService.findTaxaAndNamesByFullText(EnumSet.of(TaxaAndNamesSearchMode.doSynonyms),
907 910
                "Abies", null, null, null, null, true, null, null, null, null);
......
965 968
                EnumSet.of(TaxaAndNamesSearchMode.doSynonyms, TaxaAndNamesSearchMode.doMisappliedNames, TaxaAndNamesSearchMode.includeUnpublished),
966 969
                "Abies", (Classification)null, null, null, null, true, null, null, null, null);
967 970
        logFreeTextSearchResults(pager, Level.DEBUG, null);
968
        Assert.assertEquals("Expecting 2 entity", 2, pager.getCount().intValue());
971
        Assert.assertEquals("Expecting 3 entity", 3, pager.getCount().intValue());
969 972
        Set<UUID> uuids = getTaxonUuidSet(pager);
970 973
        Assert.assertTrue("The real synonym should be contained", uuids.contains(ABIES_SUBALPINA_UUID));
974
        Assert.assertTrue("The pro parte synonym should be contained",uuids.contains(ABIES_LASIOCARPA_UUID));
971 975
        Assert.assertTrue("The misapplied name should be contained",uuids.contains(D_ABIES_KAWAKAMII_SEC_KOMAROV_UUID));
972 976
    }
973 977

  
......
1078 1082
        pager = taxonService.findTaxaAndNamesByFullText(
1079 1083
                EnumSet.of(TaxaAndNamesSearchMode.doSynonyms, TaxaAndNamesSearchMode.includeUnpublished),
1080 1084
                "Abies", null, a_germany_canada_russia, present_native, null, true, null, null, null, null);
1081
        Assert.assertEquals("synonyms with matching area filter", 1, pager.getCount().intValue());
1085
        Assert.assertEquals("Synonyms with matching area filter", 2, pager.getCount().intValue());
1086
        Set<UUID> uuids = this.getTaxonUuidSet(pager);
1087
        Assert.assertTrue("Synonym of balsamea should be in", uuids.contains(ABIES_SUBALPINA_UUID));
1088
        Assert.assertTrue("Pro parte synonym of balsamea should be in", uuids.contains(ABIES_LASIOCARPA_UUID));
1082 1089

  
1083 1090
        pager = taxonService.findTaxaAndNamesByFullText(
1084 1091
                EnumSet.of(TaxaAndNamesSearchMode.doTaxa, TaxaAndNamesSearchMode.doSynonyms, TaxaAndNamesSearchMode.includeUnpublished),
1085 1092
                "Abies", null, a_germany_canada_russia, null, null, true, null, null, null, null);
1086 1093
        logFreeTextSearchResults(pager, Level.DEBUG, null);
1087
        Assert.assertEquals("taxa and synonyms with matching area filter", 3, pager.getCount().intValue());
1094
        Assert.assertEquals("taxa and synonyms with matching area filter", 4, pager.getCount().intValue());
1095
        uuids = this.getTaxonUuidSet(pager);
1096
        Assert.assertTrue("Accepted taxon with area should be in", uuids.contains(ABIES_ALBA_UUID));
1097
        Assert.assertTrue("Accepted taxon with area should be in", uuids.contains(ABIES_BALSAMEA_UUID));
1098
        Assert.assertTrue("Synonym of balsamea should be in", uuids.contains(ABIES_SUBALPINA_UUID));
1099
        Assert.assertTrue("Pro parte synonym of balsamea should be in", uuids.contains(ABIES_LASIOCARPA_UUID));
1100
        Assert.assertFalse("Misapplied name should NOT be in", uuids.contains(D_ABIES_KAWAKAMII_SEC_KOMAROV_UUID));
1088 1101

  
1089 1102
        pager = taxonService.findTaxaAndNamesByFullText(
1090 1103
                EnumSet.of(TaxaAndNamesSearchMode.doTaxa, TaxaAndNamesSearchMode.doSynonyms, TaxaAndNamesSearchMode.includeUnpublished),
1091 1104
                "Abies", null, a_germany_canada_russia, present_native, null, true, null, null, null, null);
1092
        Assert.assertEquals("taxa and synonyms with matching area & status filter 1", 3, pager.getCount().intValue());
1105
        Assert.assertEquals("taxa and synonyms with matching area & status filter 4", 4, pager.getCount().intValue());
1106
        uuids = this.getTaxonUuidSet(pager);
1107
        Assert.assertTrue("Synonym of balsamea should be in", uuids.contains(ABIES_SUBALPINA_UUID));
1108
        Assert.assertTrue("Accepted taxon with area should be in", uuids.contains(ABIES_ALBA_UUID));
1109
        Assert.assertTrue("Synonym of balsamea should be in", uuids.contains(ABIES_SUBALPINA_UUID));
1110
        Assert.assertTrue("Pro parte synonym of balsamea should be in", uuids.contains(ABIES_LASIOCARPA_UUID));
1093 1111

  
1094 1112
        pager = taxonService.findTaxaAndNamesByFullText(
1095 1113
                EnumSet.of(TaxaAndNamesSearchMode.doTaxa, TaxaAndNamesSearchMode.doSynonyms, TaxaAndNamesSearchMode.includeUnpublished),
1096 1114
                "Abies", null, a_germany_canada_russia, present, null, true, null, null, null, null);
1097
        Assert.assertEquals("taxa and synonyms with matching area & status filter 2", 2, pager.getCount().intValue());
1115
        Assert.assertEquals("taxa and synonyms with matching area & status filter 3", 3, pager.getCount().intValue());
1116
        uuids = this.getTaxonUuidSet(pager);
1117
        Assert.assertTrue("Abies balsamea (accepted taxon) should be in", uuids.contains(ABIES_BALSAMEA_UUID));
1118
        Assert.assertTrue("Synonym of balsamea should be in", uuids.contains(ABIES_SUBALPINA_UUID));
1119
        Assert.assertTrue("Pro parte synonym of balsamea should be in", uuids.contains(ABIES_LASIOCARPA_UUID));
1098 1120

  
1099 1121
        pager = taxonService.findTaxaAndNamesByFullText(
1100 1122
                EnumSet.of(TaxaAndNamesSearchMode.doTaxa, TaxaAndNamesSearchMode.doSynonyms, TaxaAndNamesSearchMode.includeUnpublished),
......
1105 1127
                EnumSet.of(TaxaAndNamesSearchMode.doTaxaByCommonNames, TaxaAndNamesSearchMode.includeUnpublished),
1106 1128
                "Tanne", null, a_germany_canada_russia, present_native, null, true, null, null, null, null);
1107 1129
        Assert.assertEquals("ByCommonNames with area filter", 1, pager.getCount().intValue());
1130
        uuids = this.getTaxonUuidSet(pager);
1131
        Assert.assertTrue("Abies balsamea should be in", uuids.contains(ABIES_BALSAMEA_UUID));
1108 1132

  
1109 1133
        // abies_kawakamii_sensu_komarov as misapplied name for t_abies_balsamea
1110 1134
        pager = taxonService.findTaxaAndNamesByFullText(
1111 1135
                EnumSet.of(TaxaAndNamesSearchMode.doMisappliedNames, TaxaAndNamesSearchMode.includeUnpublished),
1112 1136
                "Abies", null, a_germany_canada_russia, present_native, null, true, null, null, null, null);
1113 1137
        Assert.assertEquals("misappliedNames with matching area & status filter", 1, pager.getCount().intValue());
1138
        uuids = this.getTaxonUuidSet(pager);
1139
        Assert.assertTrue("Misapplied name should  be in", uuids.contains(D_ABIES_KAWAKAMII_SEC_KOMAROV_UUID));
1114 1140

  
1115 1141

  
1116 1142
        // 1. remove existing taxon relation
1117 1143
        Taxon t_abies_balsamea = (Taxon)taxonService.find(ABIES_BALSAMEA_UUID);
1118
        Set<TaxonRelationship> relsTo = t_abies_balsamea.getRelationsToThisTaxon();
1144
        Set<TaxonRelationship> relsTo = t_abies_balsamea.getMisappliedNameRelations();
1119 1145
        Assert.assertEquals(1, relsTo.size());
1120 1146
        TaxonRelationship taxonRelation = relsTo.iterator().next();
1121 1147
        t_abies_balsamea.removeTaxonRelation(taxonRelation);
......
1127 1153
                "Abies", null, a_germany_canada_russia, present_native, null, true, null, null, null, null);
1128 1154
        Assert.assertEquals("misappliedNames with matching area & status filter, should match nothing now", 0, pager.getCount().intValue());
1129 1155

  
1130
        // 2. now add abies_kawakamii_sensu_komarov as misapplied name for t_abies_alba and search for misapplications in russia: ABSENT
1156
        // 2. now add abies_kawakamii_sensu_komarov as misapplied name for t_abies_alba and search for misapplications in Russia: ABSENT
1131 1157
        Taxon t_abies_kawakamii_sensu_komarov = (Taxon)taxonService.find(D_ABIES_KAWAKAMII_SEC_KOMAROV_UUID);
1132 1158
        Taxon t_abies_alba = (Taxon)taxonService.find(ABIES_ALBA_UUID);
1133 1159
        t_abies_alba.addMisappliedName(t_abies_kawakamii_sensu_komarov, null, null);
1134

  
1135 1160
        taxonService.update(t_abies_kawakamii_sensu_komarov);
1136

  
1137 1161
        commitAndStartNewTransaction(null);
1138 1162

  
1139 1163
        pager = taxonService.findTaxaAndNamesByFullText(
1140 1164
                EnumSet.of(TaxaAndNamesSearchMode.doMisappliedNames, TaxaAndNamesSearchMode.includeUnpublished),
1141 1165
                "Abies", null, a_germany_canada_russia, absent, null, true, null, null, null, null);
1142 1166
        Assert.assertEquals("misappliedNames with matching area & status filter, should find one", 1, pager.getCount().intValue());
1167
        uuids = this.getTaxonUuidSet(pager);
1168
        Assert.assertTrue("Misapplied name should  be in", uuids.contains(D_ABIES_KAWAKAMII_SEC_KOMAROV_UUID));
1143 1169

  
1144 1170
    }
1145 1171

  
cdmlib-services/src/test/resources/eu/etaxonomy/cdm/api/service/TaxonServiceSearchTest.xml
17 17
  <TAXONBASE DTYPE="Taxon"   ID="5008" UUID="4ee2ad82-e98f-4697-86d4-5982e6a454eb" PROTECTEDTITLECACHE="false" TITLECACHE="Achillea millefolium × Achillea nobilis sec. Maarten  (2014)"        DOUBTFUL="false" publish="true"  USENAMECACHE="false" TAXONSTATUSUNKNOWN="false"  NAME_ID="6009" SEC_ID="5000"/>  
18 18
  
19 19
  <TAXONRELATIONSHIP ID="5000" UUID="65b5d706-f454-4345-997e-95a69803baa4" DOUBTFUL="false" RELATEDFROM_ID="5006" RELATEDTO_ID="5003" TYPE_ID="888"/>
20
  <TAXONRELATIONSHIP ID="5001" UUID="d42149bd-a07a-4a0c-8188-d181a59d54c9" DOUBTFUL="false" RELATEDFROM_ID="5007" RELATEDTO_ID="5003" TYPE_ID="2066"/>
21
  <TAXONRELATIONSHIP ID="5002" UUID="70c8da10-1b00-4a2f-be18-b2a4c68b6f9d" DOUBTFUL="false" RELATEDFROM_ID="5008" RELATEDTO_ID="5003" TYPE_ID="2067"/>
20 22
    
21 23
  <TAXONNAME NAMETYPE="ICNAFP" ID="5000" UUID="5d27de55-1e77-4dd3-92a2-f887408836ff" PROTECTEDTITLECACHE="false" TITLECACHE="Abies"            FULLTITLECACHE="Abies"            PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" PROTECTEDFULLTITLECACHE="false" AUTHORSHIPCACHE="" BINOMHYBRID="false" GENUSORUNINOMIAL="[null]" HYBRIDFORMULA="false" INFRAGENERICEPITHET="[null]" INFRASPECIFICEPITHET="[null]" MONOMHYBRID="false" NAMECACHE="Abies"            PROTECTEDAUTHORSHIPCACHE="false" PROTECTEDNAMECACHE="true" SPECIFICEPITHET="[null]" TRINOMHYBRID="false" SUBGENUSAUTHORSHIP="[null]" ANAMORPHIC="false" HOMOTYPICALGROUP_ID="5000" RANK_ID="774" />
22 24
  <TAXONNAME NAMETYPE="ICNAFP" ID="5001" UUID="a418d0cc-cc6e-4e52-9740-9092a99365ff" PROTECTEDTITLECACHE="false" TITLECACHE="Abies alba"       FULLTITLECACHE="Abies alba"       PARSINGPROBLEM="0" PROBLEMENDS="-1" PROBLEMSTARTS="-1" PROTECTEDFULLTITLECACHE="false" AUTHORSHIPCACHE="" BINOMHYBRID="false" GENUSORUNINOMIAL="[null]" HYBRIDFORMULA="false" INFRAGENERICEPITHET="[null]" INFRASPECIFICEPITHET="[null]" MONOMHYBRID="false" NAMECACHE="Abies alba"       PROTECTEDAUTHORSHIPCACHE="false" PROTECTEDNAMECACHE="true" SPECIFICEPITHET="[null]" TRINOMHYBRID="false" SUBGENUSAUTHORSHIP="[null]" ANAMORPHIC="false" HOMOTYPICALGROUP_ID="5001" RANK_ID="765" />

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)