// example /itembase/mostPopular?count=20 @RequestMapping(value = "/itembase/mostPopular", method = RequestMethod.GET) public ModelAndView findMostPopularItems( @RequestParam(value = "count", required = false) Integer count) throws SuggestEngineException { ModelAndView mav = new ModelAndView(); mav.setViewName("home"); HashMap<String, String> map = new HashMap<String, String>(); if (null != count) map.put("size", String.valueOf(count)); else map.put("size", PropertiesUtil.getRecommendListDefalutCount()); RecommendList list = itemService.mostPopularItems(map); // throw exception RecommandResponse recommandResponse = new RecommandResponse(); List<RecommandItem> reclist = new ArrayList<RecommandItem>(); for (ArrayList<String> temp : list.getList()) { RecommandItem recommandItem = new RecommandItem(); recommandItem.setId(temp.get(0)); recommandItem.setScore(temp.get(1)); reclist.add(recommandItem); } recommandResponse.setStatus("200"); // recommandResponse.setCount(map.get("size")); // recommandResponse.setCki(map.get("cki")); recommandResponse.setRecommandlist(reclist); mav.addObject("responseList", recommandResponse); return mav; }
// example /itembase/similarItems/abc,bcd,efg @RequestMapping(value = "/itembase/similarItems/{params}", method = RequestMethod.GET) public ModelAndView findSimilarItems( @PathVariable("params") String params, @RequestParam(value = "count", required = false) Integer count) throws SuggestEngineException { ModelAndView mav = new ModelAndView(); mav.setViewName("home"); HashMap<String, String> map = new HashMap<String, String>(); StringBuilder url_param = new StringBuilder(); String[] itemId = params.split(","); logger.info("Id num " + itemId.length); map.put("item_count", String.valueOf(itemId.length)); for (int i = 0; i < itemId.length; i++) { logger.info("itemId: " + itemId[i]); url_param.append("{itemId_" + i + "}/"); map.put("itemId_" + i, itemId[i]); } if (null != count) map.put("size", String.valueOf(count)); else map.put("size", PropertiesUtil.getRecommendListDefalutCount()); logger.info("count " + count); RecommendList list = itemService.mostSimilarItems(url_param.toString(), map); // throw exception RecommandResponse recommandResponse = new RecommandResponse(); List<RecommandItem> reclist = new ArrayList<RecommandItem>(); for (ArrayList<String> temp : list.getList()) { RecommandItem recommandItem = new RecommandItem(); recommandItem.setId(temp.get(0)); recommandItem.setScore(temp.get(1)); reclist.add(recommandItem); } recommandResponse.setStatus("200"); recommandResponse.setCount(map.get("size")); // recommandResponse.setCki(map.get("cki")); recommandResponse.setRecommandlist(reclist); mav.addObject("responseList", recommandResponse); return mav; }
// example /userbase/single/12345 @RequestMapping(value = "/userbase/single/{userId}", method = RequestMethod.GET) public ModelAndView recommandToSingle( @PathVariable("userId") String userId, @RequestParam(value = "count", required = false) Integer count, @RequestParam(value = "cki", required = false) Boolean cki) throws SuggestEngineException { ModelAndView mav = new ModelAndView(); mav.setViewName("responseXml"); HashMap<String, String> map = new HashMap<String, String>(); map.put("userId", userId); if (null != count) map.put("size", String.valueOf(count)); else map.put("size", PropertiesUtil.getRecommendListDefalutCount()); if (null != cki) map.put("cki", String.valueOf(cki)); else map.put("cki", PropertiesUtil.getRecommendListDefalutCKI()); RecommendList list = recommendService.recommendToSingle(map); // throw exception RecommandResponse recommandResponse = new RecommandResponse(); List<RecommandItem> reclist = new ArrayList<RecommandItem>(); for (ArrayList<String> temp : list.getList()) { RecommandItem recommandItem = new RecommandItem(); recommandItem.setId(temp.get(0)); recommandItem.setScore(temp.get(1)); reclist.add(recommandItem); } recommandResponse.setStatus("200"); recommandResponse.setCount(map.get("size")); recommandResponse.setCki(map.get("cki")); recommandResponse.setRecommandlist(reclist); mav.addObject("responseList", recommandResponse); return mav; }