@Override @Transactional public SearchResponse search(SearchRequest searchRequest) { int totalCount = 0; int count = 0; // Getting total number of results if (searchRequest.getExactMatchBusinessCount() == 0 && searchRequest.getExactMatchDealCount() == 0 && searchRequest.getExactMatchEventCount() == 0 && searchRequest.getExactMatchCommunityCount() == 0 && searchRequest.getLikeMatchBusinessCount() == 0 && searchRequest.getLikeMatchCommunityCount() == 0 && searchRequest.getLikeMatchDealCount() == 0 && searchRequest.getLikeMatchEventCount() == 0 && searchRequest.getExactMatchEventCommunityCount() == 0 && searchRequest.getLikeMatchEventCommunityCount() == 0) { if (searchRequest.getIsDeal() || !searchRequest.getIsDeal()) { count = dealsDAO.getTotalDealsBySearchKeyWord( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating(), searchRequest.getMinPrice(), searchRequest.getMaxPrice()); logger.debug("dealtotalCount:: " + count); totalCount += count; } if (!searchRequest.getIsDeal()) { count = businessDAO.getTotalBusinessBySearchKeyWord( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating()); logger.debug("businesstotalCount:: " + count); totalCount += count; count = eventsDAO.getTotalEventsBySearchKeyWord( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating()); logger.debug("eventtotalCount:: " + count); totalCount += count; count = eventsDAO.getTotalCommunityBySearchKeyWordForBusiness( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating()); logger.debug("pagetotalCount for business:: " + count); totalCount += count; if ((searchRequest.getLocation() != null && !searchRequest.getLocation().trim().equals("")) || (searchRequest.getLatitude() != 0 && searchRequest.getLongitude() != 0)) { count = eventsDAO.getTotalCommunityBySearchKeyWordForEvent( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating()); logger.debug("pagetotalCount:: " + count); totalCount += count; logger.debug("totalCount pagetotalCount:: " + totalCount); } } } logger.debug("totalCount:: " + totalCount); SearchResponse searchResponse = new SearchResponse(); List<SearchResult> exactMatchingSearchResults = new ArrayList<SearchResult>(); List<SearchResult> likeSearchResults = new ArrayList<SearchResult>(); List<Deals> dealsList = new ArrayList<Deals>(); List<Page> pageList = new ArrayList<Page>(); List<Business> businessList = new ArrayList<Business>(); List<Events> eventsList = new ArrayList<Events>(); if (searchRequest.getIsDeal() || !searchRequest.getIsDeal()) { dealsList = dealsDAO.getDealsBySearchKeyword( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getExactMatchDealCount(), 8, searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating(), searchRequest.getMinPrice(), searchRequest.getMaxPrice(), true); } if (!searchRequest.getIsDeal()) { businessList = businessDAO.getBusinessBySearchKeyword( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getExactMatchBusinessCount(), 8, searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating(), true); pageList = eventsDAO.getCommunityBySearchKeywordForBusiness( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getExactMatchCommunityCount(), 8, searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating(), true); searchResponse.setExactMatchCommunityCount( searchRequest.getExactMatchCommunityCount() + pageList.size()); if ((searchRequest.getLocation() != null && !searchRequest.getLocation().trim().equals("")) || (searchRequest.getLatitude() != 0 && searchRequest.getLongitude() != 0)) { int limit = 0; if (pageList.size() < 8) { limit = 8 - pageList.size(); List<Page> eventsPageList = eventsDAO.getCommunityBySearchKeywordForEvents( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getExactMatchEventCommunityCount(), limit, searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating(), true); if (eventsPageList != null) { searchResponse.setExactMatchEventCommunityCount( searchRequest.getExactMatchEventCommunityCount() + eventsPageList.size()); pageList.addAll(eventsPageList); } } } eventsList = eventsDAO.getEventsBySearchKeyword( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getExactMatchEventCount(), 8, searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating(), true); } if (dealsList != null) logger.debug("dealsList:: " + dealsList.size()); if (businessList != null) logger.debug("businessList:: " + businessList.size()); if (pageList != null) logger.debug("pageList:: " + pageList.size()); if (eventsList != null) logger.debug("eventsList:: " + eventsList.size()); searchResponse.setExactMatchBusinessCount( searchRequest.getExactMatchBusinessCount() + businessList.size()); searchResponse.setExactMatchDealCount( searchRequest.getExactMatchDealCount() + dealsList.size()); searchResponse.setExactMatchEventCount( searchRequest.getExactMatchEventCount() + eventsList.size()); List<Business> LikeMatchBusinessList = new ArrayList<Business>(); List<Deals> likeMatchDealsList = new ArrayList<Deals>(); List<Page> likematchPageList = new ArrayList<Page>(); List<Events> likeMatchEventsList = new ArrayList<Events>(); // Get Exact matched results exactMatchingSearchResults = getSearchResults( searchRequest.getUserId(), businessList, dealsList, pageList, eventsList, exactMatchingSearchResults, searchRequest.getCategory(), searchRequest.getMinPrice(), searchRequest.getMaxPrice()); if (searchRequest.getSearchText() != null && !searchRequest.getSearchText().trim().equals("")) { int limit = 0; if (searchRequest.getIsDeal() || !searchRequest.getIsDeal()) { if (dealsList.size() < 8) { limit = 8 - dealsList.size(); likeMatchDealsList = dealsDAO.getDealsBySearchKeyword( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getLikeMatchDealCount(), limit, searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating(), searchRequest.getMinPrice(), searchRequest.getMaxPrice(), false); searchResponse.setLikeMatchDealCount( searchRequest.getLikeMatchDealCount() + likeMatchDealsList.size()); } } if (!searchRequest.getIsDeal()) { if (businessList.size() < 8) { limit = 8 - businessList.size(); LikeMatchBusinessList = businessDAO.getBusinessBySearchKeyword( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getLikeMatchBusinessCount(), limit, searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating(), false); searchResponse.setLikeMatchBusinessCount( searchRequest.getLikeMatchBusinessCount() + LikeMatchBusinessList.size()); } if (pageList.size() < 8) { limit = 8 - pageList.size(); likematchPageList = eventsDAO.getCommunityBySearchKeywordForBusiness( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getLikeMatchCommunityCount(), limit, searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating(), false); searchResponse.setLikeMatchCommunityCount( searchRequest.getLikeMatchCommunityCount() + likematchPageList.size()); if ((searchRequest.getLocation() != null && !searchRequest.getLocation().trim().equals("")) || (searchRequest.getLatitude() != 0 && searchRequest.getLongitude() != 0)) { if (likematchPageList.size() < 8) { limit = 8 - likematchPageList.size(); List<Page> eventsPageList = eventsDAO.getCommunityBySearchKeywordForEvents( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getLikeMatchEventCommunityCount(), limit, searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating(), false); if (eventsPageList != null) { likematchPageList.addAll(eventsPageList); searchResponse.setLikeMatchEventCommunityCount( searchRequest.getLikeMatchEventCommunityCount() + eventsPageList.size()); } } } } if (eventsList.size() < 8) { limit = 32 - (exactMatchingSearchResults.size() + LikeMatchBusinessList.size() + likeMatchDealsList.size() + likematchPageList.size()); likeMatchEventsList = eventsDAO.getEventsBySearchKeyword( searchRequest.getSearchText(), searchRequest.getCategory(), searchRequest.getLocation(), searchRequest.getLikeMatchEventCount(), limit, searchRequest.getLatitude(), searchRequest.getLongitude(), searchRequest.getDistance(), searchRequest.getRating(), false); searchResponse.setLikeMatchEventCount( searchRequest.getLikeMatchEventCount() + likeMatchEventsList.size()); } } // Get Like matched results likeSearchResults = getSearchResults( searchRequest.getUserId(), LikeMatchBusinessList, likeMatchDealsList, likematchPageList, likeMatchEventsList, likeSearchResults, searchRequest.getCategory(), searchRequest.getMinPrice(), searchRequest.getMaxPrice()); exactMatchingSearchResults.addAll(likeSearchResults); } logger.debug("dealsList11:: " + likeMatchDealsList.size()); logger.debug("businessList11:: " + LikeMatchBusinessList.size()); logger.debug("pageList11:: " + likematchPageList.size()); logger.debug("eventsList11:: " + likeMatchEventsList.size()); logger.debug("getExactMatchBusinessCount:: " + searchResponse.getExactMatchBusinessCount()); logger.debug("getExactMatchCommunityCount:: " + searchResponse.getExactMatchCommunityCount()); logger.debug( "getExactMatchEventCommunityCount:: " + searchResponse.getExactMatchEventCommunityCount()); logger.debug("getExactMatchDealCount:: " + searchResponse.getExactMatchDealCount()); logger.debug("getExactMatchEventCount:: " + searchResponse.getExactMatchEventCount()); logger.debug("getLikeBusinessCount:: " + searchResponse.getLikeMatchBusinessCount()); logger.debug("getLikeCommunityCount:: " + searchResponse.getLikeMatchCommunityCount()); logger.debug( "getLikeEventCommunityCount:: " + searchResponse.getLikeMatchEventCommunityCount()); logger.debug("getLikeDealCount:: " + searchResponse.getLikeMatchDealCount()); logger.debug("getLikeEventCount:: " + searchResponse.getLikeMatchEventCount()); logger.debug("exactMatchingSearchResults:: " + exactMatchingSearchResults.size()); searchResponse.setSearchResult(exactMatchingSearchResults); searchResponse.setTotalCount(totalCount); searchResponse.setStatus(ServiceAPIStatus.OK.getStatus()); searchResponse.setError(""); return searchResponse; }
@Override @Transactional public void filter() { List<StubhubEvent> stubhubEventsList = stubhubDAO.getStubhubEvents(); // SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // Get weekends including Friday of the current year // List<Date>weekendList = Utils.findWeekendsWithFriday(); if (stubhubEventsList != null) { List<Events> eventsList = new ArrayList<Events>(); int batch_size = 0; int pageId = 0; int count = 0, count1 = 0; try { logger.debug("stubhubEventsList:: " + stubhubEventsList.size()); for (StubhubEvent stubhubEvent : stubhubEventsList) { count++; logger.debug("Count:: " + count); // Get weekend date for Event date Date eventDate = Utils.getEventWeekendDates(stubhubEvent.getEvent_date_local()); if (eventDate != null) { count1++; logger.debug("Count1:: " + count1); batch_size++; Events events = new Events(); // events.setChannel(stubhubEvent.getChannel()); events.setCity(stubhubEvent.getCity()); events.setCurrency_code(stubhubEvent.getCurrency_code()); events.setDescription(stubhubEvent.getDescription()); events.setEvent_config_template(stubhubEvent.getEvent_config_template()); events.setEvent_config_template_id(stubhubEvent.getEvent_config_template_id()); events.setEvent_date(stubhubEvent.getEvent_date()); events.setEvent_date_local(stubhubEvent.getEvent_date_local()); events.setEvent_time_local(stubhubEvent.getEvent_time_local()); events.setEvent_date_time_local(stubhubEvent.getEvent_date_time_local()); events.setGenreUrlPath(stubhubBaseUrl + stubhubEvent.getGenreUrlPath()); events.setGeography_parent(stubhubEvent.getGeography_parent()); events.setKeywords_en_US(stubhubEvent.getKeywords_en_US()); events.setLatitude(stubhubEvent.getLatitude()); events.setLongitude(stubhubEvent.getLongitude()); events.setZip(stubhubEvent.getZip()); events.setLeaf(stubhubEvent.getLeaf()); events.setMaxPrice(stubhubEvent.getMaxPrice()); events.setMinPrice(stubhubEvent.getMinPrice()); events.setMaxSeatsTogether(stubhubEvent.getMaxSeatsTogether()); events.setMinSeatsTogether(stubhubEvent.getMinSeatsTogether()); // Get State Description for state code Countrylocation countrylocation = countryLocationDAO.getStateNameByStateCode(stubhubEvent.getState()); if (countrylocation != null) events.setState(countrylocation.getState()); else events.setState(stubhubEvent.getState()); events.setStateCode(stubhubEvent.getState()); events.setTimezone(stubhubEvent.getTimezone()); if (stubhubEvent.getTimezone_id() != null) events.setTimezone_id(Long.parseLong(stubhubEvent.getTimezone_id())); if (events.getTitle() != null && events.getTitle().equals("")) events.setTitle(stubhubEvent.getTitle()); else events.setTitle(stubhubEvent.getDescription()); events.setTotalTickets(stubhubEvent.getTotalTickets()); events.setUrlpath(stubhubBaseUrl + stubhubEvent.getUrlpath()); events.setVenue_config_name(stubhubEvent.getVenue_config_name()); events.setVenue_name(stubhubEvent.getVenue_name()); events.setAncestorGenreDescriptions(stubhubEvent.getAncestorGenreDescriptions()); // events.setPage(community); // events.setImage_url(stubhubEvent.getImage_url()); events.setEventSource("Stubhub"); events.setGenre_parent_name(stubhubEvent.getGenre_parent_name()); events.setChannel(stubhubEvent.getChannel()); Page isPageExist = eventsDAO.getPageByAbout(stubhubEvent.getGenre_parent_name()); logger.debug("Is page Exist " + isPageExist); if (isPageExist == null) { Page page = new Page(); page.setAbout(stubhubEvent.getGenre_parent_name()); page.setTag(stubhubEvent.getAncestorGenreDescriptions()); page.setCreatedtime(new Date()); page.setIsCommunity(true); page.setIsEvent(true); page.setIsOrganization(true); Pagetype pagetype = null; if (stubhubEvent.getChannel().toLowerCase().contains("sports")) { // pagetype = eventsDAO.getPageTypeByName("SPORT"); pagetype = new Pagetype(); pagetype.setPageTypeId(8); } else if (stubhubEvent.getChannel().toLowerCase().contains("theater")) { // pagetype = eventsDAO.getPageTypeByName("THEATER"); pagetype = new Pagetype(); pagetype.setPageTypeId(13); } else if (stubhubEvent.getChannel().toLowerCase().contains("concert")) { // pagetype = eventsDAO.getPageTypeByName("CONCERT"); pagetype = new Pagetype(); pagetype.setPageTypeId(14); } else { // pagetype = eventsDAO.getPageTypeByName("NIGHTLIFE"); pagetype = new Pagetype(); pagetype.setPageTypeId(15); } // User user = userDAO.getUserById(1); User user = new User(); user.setUserId(1); page.setUserByCreatorId(user); page.setUserByOwnerId(user); page.setPagetype(pagetype); page.setSource("Stubhub"); page.setPageUrl(stubhubBaseUrl + stubhubEvent.getGenreUrlPath()); page.setProfilePicture( stubhubImageUrl + stubhubEvent.getGeography_parent() + "/" + stubhubEvent.getImage_url()); // eventsDAO.savePage(page,batch_size); // pageId = eventsDAO.getPageByAbout(stubhubEvent.getGenre_parent_name()); // logger.debug("After save page:: "+pageId); // page.setPageId(pageId); events.setPage(page); } else { events.setPage(isPageExist); } // eventsList.add(events); eventsDAO.saveEvents(events, batch_size); } /*if(count1 > 100) break;*/ } // eventsDAO.saveEvents(eventsList, batch_size); } catch (Exception e) { logger.debug("Error in filter::: " + e.getMessage()); e.printStackTrace(); } } }
/** * This creates combined search result list from business,page and deals * * @param businessList * @param dealsList * @param pageList * @param searchResultList * @return */ private List<SearchResult> getSearchResults( int userId, List<Business> businessList, List<Deals> dealsList, List<Page> pageList, List<Events> eventsList, List<SearchResult> searchResultList, String category, int minPrice, int maxPrice) { // Add results for Events if (eventsList != null) { for (Events events : eventsList) { SearchResult searchResult = new SearchResult(); // Check if event is already favorite or not Eventuserlikes eventProperty = userDAO.getUserEventProperties(userId, events.getEventId()); if (eventProperty != null) { searchResult.setIsFavorite(eventProperty.getIsFavorite()); searchResult.setIsBooked(eventProperty.getIsBooked()); } Page page = events.getPage(); /*List<CommunityReview> communityReviewList = eventsDAO.getCommunityReviewByPageId(page.getPageId()); int rating = 0; int count = 0; if(communityReviewList != null && !communityReviewList.isEmpty()) { for(CommunityReview communityReview:communityReviewList) { rating = rating + communityReview.getRating(); count++; } double avg = (double)rating/count; searchResult.setRating(avg); }*/ logger.debug("events.getPage():: " + events.getPage()); double avgRating = 0.0; if (events.getPage() != null) { avgRating = eventsDAO.getCommunityReviewByPageId(events.getPage().getPageId()); } searchResult.setRating(avgRating); searchResult.setId(events.getEventId()); searchResult.setCity(events.getCity()); searchResult.setName(events.getTitle()); searchResult.setType("Event"); searchResult.setStartDate(events.getEvent_date_time_local().toString()); searchResult.setEndDate(events.getEvent_date_time_local().toString()); // searchResult.setImageUrl(events.getImage_url()); searchResult.setWebsiteUrl(events.getUrlpath()); searchResult.setCategory(page.getPagetype().getPageType()); searchResult.setSource(events.getEventSource()); searchResult.setTimeLine( Utils.getTimeLineForEvent(events.getEvent_date_local(), events.getEvent_time_local())); searchResult.setTimeSlot(events.getEvent_time_local()); String address = events.getVenue_name() + "\n" + events.getCity() + "," + events.getState() + " " + events.getZip(); searchResult.setAddress(address); searchResult.setZipCode(events.getZip()); if (events.getLatitude() != null) searchResult.setLatitude(Double.parseDouble(events.getLatitude())); if (events.getLongitude() != null) searchResult.setLongitude(Double.parseDouble(events.getLongitude())); searchResultList.add(searchResult); } } // Add results for Deals if (dealsList != null) { for (Deals deals : dealsList) { Business business = deals.getBusiness(); SearchResult searchResult = new SearchResult(); // Check if deal is already favorite or not Dealsusage dealProperty = userDAO.getUserDealProperties(userId, deals.getId()); if (dealProperty != null) { searchResult.setIsFavorite(dealProperty.getIsFavorite()); searchResult.setIsBooked(dealProperty.getIsBooked()); } searchResult.setId(deals.getId()); searchResult.setCity(deals.getBusiness().getCity()); searchResult.setName(deals.getTitle()); searchResult.setType("Deal"); searchResult.setStartDate(deals.getStartAt().toString()); searchResult.setEndDate(deals.getEndAt().toString()); searchResult.setImageUrl(deals.getLargeImageUrl()); searchResult.setWebsiteUrl(deals.getDealUrl()); searchResult.setCategory(category); if (business != null) { if (business.getRating() != null) searchResult.setRating(business.getRating()); searchResult.setMerhcantName(business.getName()); } searchResult.setSource(deals.getDealSource()); // Get price and discount Dealoption dealoption = dealsDAO.getDealOptionByDealId(deals.getId(), minPrice, maxPrice); if (dealoption != null) { if (dealoption.getFormattedOriginalPrice() != null) searchResult.setPrice(dealoption.getFormattedOriginalPrice()); else searchResult.setPrice("$" + dealoption.getOriginalPrice()); searchResult.setDiscount(dealoption.getDiscountPercent()); // Get Address of redemption location logger.debug("getting location.........."); if (dealoption.getDealredemptionlocations() != null && !dealoption.getDealredemptionlocations().isEmpty()) { Dealredemptionlocation dealredemptionlocation = (Dealredemptionlocation) dealoption.getDealredemptionlocations().iterator().next(); logger.debug("getting location.........." + dealredemptionlocation); if (dealredemptionlocation != null) { String address = dealredemptionlocation.getName() + "\n" + dealredemptionlocation.getStreetAddress1() + "\n" + dealredemptionlocation.getCity() + "," + dealredemptionlocation.getState() + " " + dealredemptionlocation.getPostalCode(); searchResult.setAddress(address); if (dealredemptionlocation.getLattitude() != null) searchResult.setLatitude(Double.parseDouble(dealredemptionlocation.getLattitude())); if (dealredemptionlocation.getLongitude() != null) searchResult.setLongitude( Double.parseDouble(dealredemptionlocation.getLongitude())); searchResult.setZipCode(dealredemptionlocation.getPostalCode()); } } else { if (business != null) { if (business.getDisplayAddress() != null) searchResult.setAddress( business.getDisplayAddress().replaceAll("[<>\\[\\],-]", "")); if (business.getLattitude() != null) searchResult.setLatitude(Double.parseDouble(business.getLattitude())); if (business.getLongitude() != null) searchResult.setLongitude(Double.parseDouble(business.getLongitude())); searchResult.setZipCode(business.getPostalCode()); } } } searchResultList.add(searchResult); } } // Add results for Community if (pageList != null) { for (Page page : pageList) { SearchResult searchResult = new SearchResult(); // Get recent event date for community Object[] event_date = eventsDAO.getRecentEventDetails(page.getPageId()); if (event_date != null) { Date date = (Date) event_date[0]; searchResult.setStartDate(date.toString()); searchResult.setEndDate(date.toString()); searchResult.setTimeLine(Utils.getTimeLineForEvent(date, event_date[1].toString())); searchResult.setTimeSlot(event_date[1].toString()); if (event_date[2] != null && !event_date[2].toString().trim().equals("")) searchResult.setLatitude(Double.parseDouble(event_date[2].toString())); if (event_date[3] != null && !event_date[3].toString().trim().equals("")) searchResult.setLongitude(Double.parseDouble(event_date[3].toString())); if (event_date[4] != null && !event_date[4].toString().trim().equals("")) searchResult.setZipCode(event_date[4].toString()); } // Check if business is already favorite or not Pageuserlikes pageuserlikes = userDAO.getUserPageProperties(userId, page.getPageId()); if (pageuserlikes != null) { searchResult.setIsFavorite(pageuserlikes.getIsFavorite()); searchResult.setIsBooked(pageuserlikes.getIsBooked()); } searchResult.setId(page.getPageId()); /*List<CommunityReview> communityReviewList = eventsDAO.getCommunityReviewByPageId(page.getPageId()); int rating = 0; int count = 0; if(communityReviewList != null && !communityReviewList.isEmpty()) { for(CommunityReview communityReview:communityReviewList) { rating = rating + communityReview.getRating(); count++; }20 double avg = (double)rating/count; logger.debug("avg rating =>"+avg); searchResult.setRating(avg); } else searchResult.setRating(0);*/ double avgRating = eventsDAO.getCommunityReviewByPageId(page.getPageId()); searchResult.setRating(avgRating); if (page.getBusiness() != null) searchResult.setCity(page.getBusiness().getCity()); searchResult.setName(page.getAbout()); searchResult.setType("Community"); searchResult.setImageUrl(page.getProfilePicture()); searchResult.setWebsiteUrl(page.getPageUrl()); searchResult.setCategory(page.getPagetype().getPageType()); searchResult.setSource(page.getSource()); searchResultList.add(searchResult); } } // Add results for business if (businessList != null) { for (Business business : businessList) { SearchResult searchResult = new SearchResult(); Page page = eventsDAO.getPageByBusinessId(business.getId()); if (page != null) { // Check if business is already favorite or not Pageuserlikes pageuserlikes = userDAO.getUserPageProperties(userId, page.getPageId()); if (pageuserlikes != null) { searchResult.setIsFavorite(pageuserlikes.getIsFavorite()); searchResult.setIsBooked(pageuserlikes.getIsBooked()); } } else { Funboard funboard = funBoardDAO.isFunBoardExists(userId, business.getId(), null); if (funboard != null) searchResult.setIsBooked(true); } searchResult.setId(business.getId()); searchResult.setCity(business.getCity()); searchResult.setName(business.getName()); searchResult.setType("Business"); searchResult.setImageUrl(business.getImageUrl()); searchResult.setWebsiteUrl(business.getWebsiteUrl()); searchResult.setCategory(category); if (business.getRating() != null) searchResult.setRating(business.getRating()); searchResult.setSource(business.getSource()); searchResult.setZipCode(business.getPostalCode()); if (business.getLattitude() != null) searchResult.setLatitude(Double.parseDouble(business.getLattitude())); if (business.getLongitude() != null) searchResult.setLongitude(Double.parseDouble(business.getLongitude())); if (business.getDisplayAddress() != null) searchResult.setAddress(business.getDisplayAddress().replaceAll("[<>\\[\\],-]", "")); searchResultList.add(searchResult); } } return searchResultList; }