Revision b8784167
Added by Katja Luther over 3 years ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/TaxonServiceImpl.java | ||
---|---|---|
33 | 33 |
import org.apache.lucene.search.grouping.TopGroups; |
34 | 34 |
import org.apache.lucene.search.join.ScoreMode; |
35 | 35 |
import org.apache.lucene.util.BytesRef; |
36 |
import org.hibernate.criterion.Criterion; |
|
36 | 37 |
import org.springframework.beans.factory.annotation.Autowired; |
37 | 38 |
import org.springframework.stereotype.Service; |
38 | 39 |
import org.springframework.transaction.annotation.Transactional; |
... | ... | |
1512 | 1513 |
return new DefaultPagerImpl<>(pageNumber, totalHits, pageSize, searchResults); |
1513 | 1514 |
} |
1514 | 1515 |
|
1516 |
|
|
1517 |
|
|
1518 |
@Transactional(readOnly = true) |
|
1519 |
@Override |
|
1520 |
public <S extends TaxonBase> Pager<S> findByTitleWithRestrictions(Class<S> clazz, String queryString, MatchMode matchmode, List<Restriction<?>> restrictions, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) { |
|
1521 |
long numberOfResults = dao.countByTitleWithRestrictions(clazz, queryString, matchmode, restrictions); |
|
1522 |
numberOfResults = numberOfResults + dao.countByTitleWithRestrictions(clazz, "?".concat(queryString), matchmode, restrictions); |
|
1523 |
|
|
1524 |
List<S> results = new ArrayList<>(); |
|
1525 |
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize) |
|
1526 |
|
|
1527 |
results = dao.findByTitleWithRestrictions(clazz, queryString, matchmode, restrictions, pageSize, pageNumber, orderHints, propertyPaths); |
|
1528 |
results.addAll(dao.findByTitleWithRestrictions(clazz, "?".concat(queryString), matchmode, restrictions, pageSize, pageNumber, orderHints, propertyPaths)); |
|
1529 |
} |
|
1530 |
|
|
1531 |
return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results); |
|
1532 |
} |
|
1533 |
|
|
1534 |
|
|
1535 |
@Transactional(readOnly = true) |
|
1536 |
@Override |
|
1537 |
public <S extends TaxonBase> Pager<S> findByTitle(Class<S> clazz, String queryString,MatchMode matchmode, List<Criterion> criteria, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) { |
|
1538 |
long numberOfResults = dao.countByTitle(clazz, queryString, matchmode, criteria); |
|
1539 |
//check whether there are doubtful taxa matching |
|
1540 |
long numberOfResults_doubtful = dao.countByTitle(clazz, "?".concat(queryString), matchmode, criteria); |
|
1541 |
List<S> results = new ArrayList<>(); |
|
1542 |
if(numberOfResults > 0 || numberOfResults_doubtful > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize) |
|
1543 |
if (numberOfResults > 0){ |
|
1544 |
results = dao.findByTitle(clazz, queryString, matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths); |
|
1545 |
}else{ |
|
1546 |
results = new ArrayList<>(); |
|
1547 |
} |
|
1548 |
if (numberOfResults_doubtful > 0){ |
|
1549 |
results.addAll(dao.findByTitle(clazz, "?".concat(queryString), matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths)); |
|
1550 |
} |
|
1551 |
} |
|
1552 |
|
|
1553 |
return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results); |
|
1554 |
} |
|
1555 |
|
|
1556 |
|
|
1515 | 1557 |
@Override |
1516 | 1558 |
public Pager<SearchResult<TaxonBase>> findByDistribution(List<NamedArea> areaFilter, List<PresenceAbsenceTerm> statusFilter, |
1517 | 1559 |
Classification classification, TaxonNode subtree, |
Also available in: Unified diff
ref #9171: search for pattern and ?+pattern to find doubtful taxa