Commit be158fe1 authored by Matija Obreza's avatar Matija Obreza

Merge branch...

Merge branch '455-incorrect-results-of-search-if-user-use-full-text-filter-on-the-image-tab' into 'master'

Resolve "Incorrect results of search if user use "Full text" filter on the "Image" tab."

Closes #455

See merge request genesys-pgr/genesys-server!422
parents 0a0c5b8d e0b1574e
......@@ -202,19 +202,15 @@ public class AccessionController {
*/
@JsonView({ JsonViews.Root.class }) // same as getAccessionDetails so we get imageGallery!
@PostMapping(value = "/images", produces = { MediaType.APPLICATION_JSON_VALUE })
public AccessionSuggestionPage<AccessionService.AccessionDetails> images(@RequestParam(name = "f", required = false) String filterCode, final Pagination page,
@RequestBody(required = false) AccessionFilter filter) throws IOException, SearchException {
public AccessionSuggestionPage<AccessionService.AccessionDetails> images(@RequestParam(name = "f", required = false) final String filterCode, final Pagination page,
@RequestBody(required = false) final AccessionFilter filter) throws IOException, SearchException {
if (filterCode != null) {
filter = shortFilterService.filterByCode(filterCode, AccessionFilter.class);
} else {
filterCode = shortFilterService.getCode(filter);
}
FilterInfo<AccessionFilter> filterInfo = shortFilterService.processFilter(filterCode, filter, AccessionFilter.class);
FilteredPage<AccessionService.AccessionDetails> pageRes = new FilteredPage<>(filterInfo.filterCode, filterInfo.filter, accessionService.withImages(filterInfo.filter, page.toPageRequest(20, Sort.Direction.ASC, "seqNo")));
filter.images = true;
Map<String, TermResult> suggestionRes = accessionService.getSuggestions(filter);
filterInfo.filter.images = true;
Map<String, TermResult> suggestionRes = accessionService.getSuggestions(filterInfo.filter);
return new AccessionSuggestionPage<>(pageRes, suggestionRes);
}
......
......@@ -34,6 +34,7 @@ import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.apache.commons.lang3.time.StopWatch;
import org.genesys2.server.exception.InvalidApiUsageException;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.model.genesys.AccessionData;
import org.genesys2.server.model.genesys.AccessionHistoric;
......@@ -227,6 +228,10 @@ public class AccessionRepositoryCustomImpl implements AccessionRepositoryCustom,
@Override
public List<Accession> findAll(AccessionFilter filter, Pageable page) {
if (filter.isFulltextQuery()) {
throw new InvalidApiUsageException("Use elasticService with full-text queries!");
}
Querydsl querydsl = new Querydsl(em, pathBuilder);
QAccession qAccession = QAccession.accession;
JPQLQuery<Object> query = querydsl.createQuery(qAccession);
......
......@@ -370,30 +370,21 @@ public class AccessionServiceImpl implements AccessionService {
@Override
// @Cacheable(value = "apiResponses.accessionApi1.list", unless = "#result == null", keyGenerator = "shortFilterKeyGenerator")
public Page<Accession> list(AccessionFilter filter, Pageable page) {
if (filter.isFulltextQuery()) {
return elasticsearchService.findAll(Accession.class, filter, page);
}
List<Accession> content = accessionRepository.findAll(filter, page);
content.forEach(accession -> lazyLoad(accession));
long total = countAccessions(filter);
return new PageImpl<>(content, page, total);
Page<Accession> result = findAll(filter, page);
result.getContent().forEach(accession -> lazyLoad(accession));
return result;
}
@Override
public Page<AccessionDetails> withImages(AccessionFilter filter, Pageable page) {
filter.images = true;
Page<Accession> paged = findAll(filter, page);
paged.forEach(accession -> accession.getTaxonomy().getId());
List<Accession> content = accessionRepository.findAll(filter, page);
content.forEach(accession -> lazyLoad(accession));
List<AccessionDetails> contentWithImages = new ArrayList<>(content.size());
List<AccessionDetails> contentWithImages = new ArrayList<>(paged .getNumberOfElements());
for (Accession accession : content) {
for (Accession accession : paged ) {
AccessionDetails details = new AccessionDetails();
details.details = accession;
......@@ -408,9 +399,18 @@ public class AccessionServiceImpl implements AccessionService {
contentWithImages.add(details);
}
long total = countAccessions(filter);
return new PageImpl<>(contentWithImages, page, paged .getTotalElements());
}
return new PageImpl<>(contentWithImages, page, total);
// Utility method that uses ES as required
private Page<Accession> findAll(AccessionFilter filter, Pageable page) {
if (filter.isFulltextQuery()) {
return elasticsearchService.findAll(Accession.class, filter, page);
}
List<Accession> content = accessionRepository.findAll(filter, page);
long total = countAccessions(filter);
return new PageImpl<>(content, page, total);
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment