@@ -14,7 +14,6 @@ import ru.soune.nocopy.entity.file.FileEntity;
|
||||
import ru.soune.nocopy.exception.NotValidFieldException;
|
||||
import ru.soune.nocopy.repository.FileEntityRepository;
|
||||
import ru.soune.nocopy.service.file.CheckCounterService;
|
||||
import ru.soune.nocopy.service.search.SearchApiToYandexResponseMapper;
|
||||
import ru.soune.nocopy.service.search.SearchImageService;
|
||||
import ru.soune.nocopy.service.search.GoogleVisionSearchService;
|
||||
import ru.soune.nocopy.service.tariff.TariffConstants;
|
||||
@@ -41,8 +40,6 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
|
||||
private final TariffInfoService tariffInfoService;
|
||||
|
||||
private final SearchApiToYandexResponseMapper mapper = new SearchApiToYandexResponseMapper();
|
||||
|
||||
@Override
|
||||
public BaseResponse handle(BaseRequest request) throws Exception {
|
||||
ImageSearchRequest imageSearchRequest = objectMapper.convertValue(request.getMessageBody(),
|
||||
@@ -88,17 +85,18 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
|
||||
checkCounterService.incrementCheckCount(fileEntity.getUserId(), fileEntity.getMimeType());
|
||||
|
||||
List<YandexSearchResponse.ImageResult> allYandexImages = mapper.getAllImagesWithoutPagination(searchResponseYandex,
|
||||
"visual_matches");
|
||||
List<YandexSearchResponse.ImageResult> allGoogleImages = mapper.getAllImagesWithoutPagination(searchResponseGoogle,
|
||||
"exact_matches");
|
||||
List<YandexSearchResponse.ImageResult> allYandexImages = searchImageService.getAllImagesWithoutPagination(
|
||||
searchResponseYandex, "visual_matches");
|
||||
List<YandexSearchResponse.ImageResult> allGoogleImages = searchImageService.getAllImagesWithoutPagination(
|
||||
searchResponseGoogle, "exact_matches");
|
||||
|
||||
List<YandexSearchResponse.ImageResult> allUniqueImages = mapper.removeDuplicateUrls(allYandexImages, allGoogleImages);
|
||||
List<YandexSearchResponse.ImageResult> allUniqueImages = searchImageService.removeDuplicateUrls(allYandexImages,
|
||||
allGoogleImages);
|
||||
|
||||
int page = imageSearchRequest.getPage() != null ? imageSearchRequest.getPage() : 1;
|
||||
int pageSize = 5;
|
||||
|
||||
List<YandexSearchResponse.ImageResult> pagedResults = mapper.paginateResults(allUniqueImages, page,
|
||||
List<YandexSearchResponse.ImageResult> pagedResults = searchImageService.paginateResults(allUniqueImages, page,
|
||||
pageSize * 2);
|
||||
|
||||
YandexSearchResponse finalResponse = new YandexSearchResponse();
|
||||
@@ -110,23 +108,5 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
|
||||
return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
MessageCode.SUCCESS.getDescription(), finalResponse);
|
||||
// int page = imageSearchRequest.getPage() != null ? imageSearchRequest.getPage() : 1;
|
||||
|
||||
//
|
||||
// YandexSearchResponse yandexSearchResponse = mapper.mapToYandexResponse(searchResponseYandex, page, 5,
|
||||
// "visual_matches");
|
||||
// YandexSearchResponse googleSearchResponse = mapper.mapToYandexResponse(searchResponseGoogle, page, 5,
|
||||
// "exact_matches");
|
||||
//
|
||||
// int totalSize = yandexSearchResponse.getImages().size() + googleSearchResponse.getImages().size();
|
||||
// List<YandexSearchResponse.ImageResult> results = new ArrayList<>(totalSize);
|
||||
// results.addAll(yandexSearchResponse.getImages());
|
||||
// results.addAll(googleSearchResponse.getImages());
|
||||
//
|
||||
// yandexSearchResponse.setImages(results);
|
||||
// yandexSearchResponse.setTotalResults(totalSize);
|
||||
//
|
||||
// return new BaseResponse(request.getMsgId(), MessageCode.SUCCESS.getCode(),
|
||||
// MessageCode.SUCCESS.getDescription(), yandexSearchResponse);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user