Subversion Repositories SmartDukaan

Rev

Rev 21287 | Rev 21291 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21287 Rev 21290
Line 53... Line 53...
53
		String jsonString = null;
53
		String jsonString = null;
54
		try {
54
		try {
55
			jsonString = solrService.getSearchResults(search_text.trim(), offset);
55
			jsonString = solrService.getSearchResults(search_text.trim(), offset);
56
		} catch (URISyntaxException | IOException e) {
56
		} catch (URISyntaxException | IOException e) {
57
			logger.error("Error while gettting search results from solr",e);
57
			logger.error("Error while gettting search results from solr",e);
58
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SEARCH , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, new JsonArray());
58
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SEARCH , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, new JsonArray().toString());
59
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
59
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
60
		}
60
		}
61
		JsonArray result_json = Json.parse(jsonString).asObject().get("response").asObject().get("docs").asArray();
61
		JsonArray result_json = Json.parse(jsonString).asObject().get("response").asObject().get("docs").asArray();
62
		for (JsonValue j : result_json ){
62
		for (JsonValue j : result_json ){
63
			j.asObject().add("productUrl", j.asObject().get("ids").asArray().get(0)+"/"+j.asObject().get("id").asString());
63
			j.asObject().add("productUrl", j.asObject().get("ids").asArray().get(0)+"/"+j.asObject().get("id").asString());
64
		}
64
		}
65
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SEARCH , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, result_json);
65
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SEARCH , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, result_json.toString());
66
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
66
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
67
	}
67
	}
68
 
68
 
69
 
69
 
70
	@RequestMapping(value = ProfitMandiConstants.URL_SOLR_SUGGESTION, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
70
	@RequestMapping(value = ProfitMandiConstants.URL_SOLR_SUGGESTION, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
Line 78... Line 78...
78
		String jsonString;
78
		String jsonString;
79
		try {
79
		try {
80
			jsonString = solrService.getSuggestions(search_text.trim());
80
			jsonString = solrService.getSuggestions(search_text.trim());
81
		} catch (URISyntaxException | IOException e) {
81
		} catch (URISyntaxException | IOException e) {
82
			logger.error("Error while getting suggestions from solr",e);
82
			logger.error("Error while getting suggestions from solr",e);
83
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SUGGESTION , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, new JsonArray());
83
			final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SUGGESTION , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, new JsonArray().toString());
84
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
84
			return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
85
		}
85
		}
86
		result_json = Json.parse(jsonString).asObject().get("grouped").asObject();
86
		result_json = Json.parse(jsonString).asObject().get("grouped").asObject();
87
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SUGGESTION , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, sanatizedResults());
87
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SUGGESTION , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, sanatizedResults().toString());
88
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
88
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
89
	}
89
	}
90
 
90
 
91
	private JsonArray sanatizedResults(){
91
	private JsonArray sanatizedResults(){
92
 
92