Project

General

Profile

Revision c4f7a205

IDc4f7a205397788e29a5bb8a00efc87eb41322cab
Parent 0fc610dc
Child d93004c1

Added by Katja Luther over 3 years ago

fix #6296: fix problems for simple search

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java
1486 1486
                " left join rt.name as n2" +
1487 1487
                " left join rft.type as rtype";
1488 1488

  
1489
           String doCommonNamesJoin =   "join t.descriptions d "+
1490
                   "join d.descriptionElements e " +
1491
                   "join e.feature f ";
1489
           String doCommonNamesJoin =   "join t.descriptions as description "+
1490
                   "left join description.descriptionElements as com " +
1491
                   "left join com.feature f ";
1492 1492

  
1493 1493

  
1494 1494
           String doClassificationWhere = " tn.classification = :classification";
1495 1495
           String doClassificationForMisappliedNamesWhere = " tn2 .classification = :classification";
1496 1496

  
1497 1497
           String doAreaRestrictionWhere =  " e.area.uuid in (:namedAreasUuids)";
1498
           String doCommonNamesRestrictionWhere = " f.supportsCommonTaxonName = true and e.name "+matchMode.getMatchOperator()+" :queryString";
1498
           String doCommonNamesRestrictionWhere = " (f.supportsCommonTaxonName = true and com.name "+matchMode.getMatchOperator()+" :queryString )";
1499 1499

  
1500 1500
           String doSearchFieldWhere = "%s." + searchField +  " " + matchMode.getMatchOperator() + " :queryString";
1501 1501

  
......
1529 1529
                    " WHERE " + doClassificationWhere +
1530 1530
                    " AND " + String.format(doSearchFieldWhere, "sn");
1531 1531
                    commonNameSubselect =String.format(doTaxonSubSelect, "t" )+ doCommonNamesJoin +
1532
                            " WHERE "+ doAreaRestrictionWhere +
1533
                             " AND " + doClassificationWhere +
1532
                            " WHERE " + doClassificationWhere +
1534 1533
                            " AND " + doCommonNamesRestrictionWhere;
1535 1534
                }
1536 1535
            }else{ //misappliedNames included
......
1585 1584
                synonymSubselect = String.format(doAreaRestrictionSubSelect, "s") + doSynonymNameJoin +
1586 1585
                " WHERE " +   doAreaRestrictionWhere +
1587 1586
                " AND " +  String.format(doSearchFieldWhere, "sn");
1588
                commonNameSubselect = String.format(doTaxonSubSelect, "t")+ doCommonNamesJoin +
1587
                commonNameSubselect = String.format(doAreaRestrictionSubSelect, "t")+ doCommonNamesJoin +
1589 1588
                        " WHERE " + doAreaRestrictionWhere +
1590 1589
                        " AND " + doCommonNamesRestrictionWhere;
1591 1590

  
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImplTest.java
258 258
    @DataSet (loadStrategy=CleanSweepInsertLoadStrategy.class, value="TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml")
259 259
    public void testGetTaxaByNameVariants(){
260 260
        List<TaxonBase> results = taxonDao.getTaxaByName(false, false, false, true, false, "c*", null, MatchMode.BEGINNING, null, null, null, null, null);
261
        Assert.assertEquals("There should be 1 Taxa", 1, results.size());
261
        Assert.assertEquals("There should be 2 Taxa",2, results.size());
262 262

  
263 263
        results = taxonDao.getTaxaByName(false, false, true, true, false, "R*", null, MatchMode.BEGINNING, null, null, null, null, null);
264 264
        Assert.assertEquals("There should be 1 Taxa", 1, results.size());
......
267 267
        Assert.assertEquals("There should be 1 Taxa", 1, results.size());
268 268

  
269 269
        results = taxonDao.getTaxaByName(false, true, false, true, false, "c*", null, MatchMode.BEGINNING, null, null, null, null, null);
270
        Assert.assertEquals("There should be 1 Taxa", 1, results.size());
270
        Assert.assertEquals("There should be 2 Taxa", 2, results.size());
271 271

  
272 272
        results = taxonDao.getTaxaByName(true, false, false, true, false, "c*", null, MatchMode.BEGINNING, null, null, null, null, null);
273
        Assert.assertEquals("There should be 2 Taxa", 2, results.size());
274
        Classification classification = classificationDao.load(classificationUuid);
275
        results = taxonDao.getTaxaByName(false, false, false, true, false, "c*", classification, MatchMode.BEGINNING, null, null, null, null, null);
276
        Assert.assertEquals("There should be 1 Taxa", 1, results.size());
277
        Set<NamedArea> namedAreas = new HashSet<>();
278
        namedAreas.add((NamedArea)definedTermDao.load(southernAmericaUuid));
279
        results = taxonDao.getTaxaByName(false, false, false, true, false, "c*", null, MatchMode.BEGINNING, namedAreas, null, null, null, null);
273 280
        Assert.assertEquals("There should be 1 Taxa", 1, results.size());
274

  
275 281
    }
276 282

  
277 283
    /**
......
353 359
        assertNotNull("getTaxaByName should return a List", results);
354 360
        assertTrue("expected to find two taxa but found "+results.size(), results.size() == 2);
355 361

  
362
        results = taxonDao.getTaxaByName(false,false, false, true, false,"com*", null, MatchMode.BEGINNING, namedAreas,
363
                null, null, null, null);
364
            assertNotNull("getTaxaByName should return a List", results);
365
            assertTrue("expected to find one taxon but found "+results.size(), results.size() == 1);
366

  
356 367
        // 2. searching for a taxon (Rethera) contained in a specific classification
357 368
        results = taxonDao.getTaxaByName(true, false, false, false, false,"Rethera", taxonmicTree, MatchMode.BEGINNING, namedAreas,
358 369
            null, null, null, null);
......
1113 1124

  
1114 1125
        assertNotNull("getTaxaByCommonName should return a list", commonNameResults);
1115 1126
        assertFalse("the list should not be empty", commonNameResults.isEmpty());
1116
        assertEquals("There should be one Taxon with common name", 1,commonNameResults.size());
1117
        assertEquals(" sec. ???", ((TaxonBase)commonNameResults.get(0)).getTitleCache());
1127
        assertEquals("There should be two taxa with common name", 2,commonNameResults.size());
1118 1128

  
1119 1129
        List<UuidAndTitleCache<IdentifiableEntity>> list = taxonDao.getTaxaByCommonNameForEditor("common%", null, MatchMode.BEGINNING, null);
1120 1130

  
1121 1131
        assertNotNull("getTaxaByCommonName should return a list", commonNameResults);
1122 1132
        assertFalse("the list should not be empty", commonNameResults.isEmpty());
1123
        assertEquals("There should be one Taxon with common name", 1,commonNameResults.size());
1124
        assertEquals(" sec. ???", ((TaxonBase)commonNameResults.get(0)).getTitleCache());
1133
        assertEquals("There should be two Taxon with common name", 2,commonNameResults.size());
1134

  
1125 1135
    }
1126 1136

  
1127 1137
    @Test
cdmlib-persistence/src/test/resources/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImplTest.testGetTaxaByNameAndArea.xml
78 78
  <DESCRIPTIONELEMENTBASE DTYPE="Distribution" ID="37" INDESCRIPTION_ID="34" CREATED="2008-12-10 09:56:07.0" UUID="c47cd33c-0fac-4ed2-83f1-27f83fdb4657" UPDATED="2008-12-10 09:56:07.253" AREA_ID="1970" STATUS_ID="1994" FEATURE_ID="936" NAME="[null]"/>
79 79
  <DESCRIPTIONELEMENTBASE DTYPE="CommonTaxonName" ID="38" INDESCRIPTION_ID="1" CREATED="2008-12-10 09:56:07.0" UUID="a837f822-30d6-4891-b917-cedd642ba919" UPDATED="2008-12-10 09:56:07.253" AREA_ID="[null]" STATUS_ID="[null]" FEATURE_ID="933" NAME="common name"/>
80 80
 <DESCRIPTIONELEMENTBASE DTYPE="CommonTaxonName" ID="39" INDESCRIPTION_ID="1" CREATED="2008-12-10 09:56:07.0" UUID="d675d475-d70a-417f-8268-e8e90991e1db" UPDATED="2008-12-10 09:56:07.253" AREA_ID="[null]" STATUS_ID="[null]" FEATURE_ID="933" NAME="commone"/>
81
 <DESCRIPTIONELEMENTBASE DTYPE="CommonTaxonName" ID="40" INDESCRIPTION_ID="19" CREATED="2008-12-10 09:56:07.0" UUID="3318c2db-740e-46bf-937d-596f5d78a00b" UPDATED="2008-12-10 09:56:07.253" AREA_ID="[null]" STATUS_ID="[null]" FEATURE_ID="933" NAME="commone"/>
81 82

  
82 83
  <DESCRIPTIONELEMENTBASE_LANGUAGESTRING TEXTDATA_ID="34" MULTILANGUAGETEXT_ID="1" MULTILANGUAGETEXT_MAPKEY_ID="406"/>
83 84
  <DESCRIPTIONELEMENTBASE_LANGUAGESTRING TEXTDATA_ID="35" MULTILANGUAGETEXT_ID="2" MULTILANGUAGETEXT_MAPKEY_ID="406"/>

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)