提交 b9f9707c authored 作者: Whispa's avatar Whispa

commit

上级 8ed71564
......@@ -43,6 +43,15 @@ public class ImageSearchController extends Controller {
return new Result<>(getItemLabels(url));
}
@GetMapping("searchUrl")
public Result searchByUrl(@RequestParam("url") String url, @RequestParam(value = "pageNo",defaultValue = "0",required = false) Integer pageNo, @RequestParam(value = "pageSize",required = false,defaultValue = "12") Integer pageSize) {
List<ItemLabel> itemLabels = getItemLabels(url);
List<String> collect = itemLabels.stream().map(ItemLabel::getDescription).collect(Collectors.toList());
String[] strings = collect.toArray(new String[]{});
Page<TbCfStationItem> itemsByImageSearch = repository.getItemsByImageSearch(strings,strings.length/2, PageRequest.of(pageNo, pageSize));
return new Result<>(itemsByImageSearch.toList());
}
@PostMapping("/upload")
......@@ -52,7 +61,7 @@ public class ImageSearchController extends Controller {
List<ItemLabel> itemLabels = getItemLabels(file.getBytes());
List<String> collect = itemLabels.stream().map(ItemLabel::getDescription).collect(Collectors.toList());
String[] strings = collect.toArray(new String[]{});
Page<TbCfStationItem> itemsByImageSearch = repository.getItemsByImageSearch(strings, PageRequest.of(pageNo, pageSize));
Page<TbCfStationItem> itemsByImageSearch = repository.getItemsByImageSearch(strings,strings.length/2, PageRequest.of(pageNo, pageSize));
return new Result<>(itemsByImageSearch.toList());
} catch (IOException e) {
System.out.println(e.getMessage());
......
......@@ -16,8 +16,8 @@ public interface TbCfStationItemRepository extends PagingAndSortingRepository<Tb
Page<TbCfStationItem> findAllByItemLabelContaining(String label, Pageable pageable);
@Query(value = "select a from #{#entityName} a WHERE a.itemId <> :itemId and (a.itemDescritionId = :descriptionId or a.itemCategorytwo = :categoryTwo or a.itemCategory = :category )")
Page<TbCfStationItem> getRecommendItems(@Param("itemId") String itemId,@Param("descriptionId") String descriptionId,@Param("categoryTwo") String categoryTwo,@Param("category") String category, Pageable pageable);
@Query(value = "select a from #{#entityName} a WHERE a in (SELECT l.item FROM ItemLabel l WHERE l.description IN :tags)")
Page<TbCfStationItem> getItemsByImageSearch(@Param("tags") String[] tags, Pageable pageable);
@Query(value = "select a from #{#entityName} a WHERE a in (SELECT l.item FROM ItemLabel l WHERE l.description IN :tags having count(l.id) >= :num)")
Page<TbCfStationItem> getItemsByImageSearch(@Param("tags") String[] tags,@Param("num") int num, Pageable pageable);
Page<TbCfStationItem> findAllByItemNameContainingOrItemTagsContaining(String itemName, String itemTags, Pageable pageable);
Page<TbCfStationItem> findByItemCategory(String itemName, Pageable pageable);
List<TbCfStationItem> findAllByItemDescritionId(String id);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论