Skip to content

Commit

Permalink
Search mods
Browse files Browse the repository at this point in the history
Mods to seach functionality
  • Loading branch information
Mike Chandler committed Jun 19, 2012
1 parent 88e75cc commit 0302cf4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
@@ -1,26 +1,27 @@
package com.rmwebfx.citygridsearch.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.rmwebfx.citygridsearch.config.Constants;
import com.rmwebfx.citygridsearch.helper.CategoryHelper;
import com.rmwebfx.citygridsearch.resources.PlacesSearch;

@Controller
public class SearchController {

@RequestMapping(value = "/categorysearch.do")
public ModelAndView getPlace(@RequestParam("cat") int categoryId, @RequestParam("page") int page) {

ModelAndView view = new ModelAndView();
view.setViewName("category_results");

PlacesSearch search = new PlacesSearch(categoryId, Constants.SITEWIDE_CITY_STATE, "", page);
view.addObject("matches", search.getPlaces());

return view;
@RequestMapping(value = "/category/{category}")
public ModelAndView getPlaceNoPage(@PathVariable("category") String category) {
return getPlace(category, 1);
}

@RequestMapping(value = "/category/{category}/{page}")
public ModelAndView getPlace(@PathVariable("category") String category, @PathVariable("page") int page) {
int categoryId = CategoryHelper.getCategory(category);
return doSearch(categoryId, page);
}

@RequestMapping(value = "/search")
Expand All @@ -30,4 +31,14 @@ public ModelAndView search() {
return view;
}

private ModelAndView doSearch(int categoryId, int page) {
ModelAndView view = new ModelAndView();
view.setViewName("category_results");

PlacesSearch search = new PlacesSearch(categoryId, Constants.SITEWIDE_CITY_STATE, "", page);
view.addObject("matches", search.getPlaces());

return view;
}

}
Expand Up @@ -48,4 +48,32 @@ public static CGPlacesSearchType category(int type) {
return catType;
}

public static int getCategory(String category) {
if (category.toLowerCase().equals("barclub")) {
return 1;
}

if (category.toLowerCase().equals("hotel")) {
return 2;
}

if (category.toLowerCase().equals("restaurant")) {
return 5;
}

if (category.toLowerCase().equals("shopping")) {
return 6;
}

if (category.toLowerCase().equals("spabeauty")) {
return 7;
}

if (category.toLowerCase().equals("travel")) {
return 8;
}

return 5;
}

}
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/views/category_results.jsp
Expand Up @@ -8,7 +8,7 @@
<h1>Search Results</h1>

<c:forEach var="match" items='${requestScope.matches}'>
<b><a href='places/<c:out value="${match.getLocationId()}" />/<c:out value="${match.getPublicId()}" />'><c:out value="${match.getName()}" /></a></b><br />
<b><a href='../../places/<c:out value="${match.getLocationId()}" />/<c:out value="${match.getPublicId()}" />'><c:out value="${match.getName()}" /></a></b><br />
<c:out value="${match.getCategories()}" /><br />
<c:out value="${match.getAddress().toString()}" /><br /><br />
</c:forEach>
Expand Down

0 comments on commit 0302cf4

Please sign in to comment.