| Line 24... |
Line 24... |
| 24 |
import com.google.gson.Gson;
|
24 |
import com.google.gson.Gson;
|
| 25 |
import com.google.gson.reflect.TypeToken;
|
25 |
import com.google.gson.reflect.TypeToken;
|
| 26 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
26 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 27 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
27 |
import com.spice.profitmandi.common.model.ProfitMandiResponse;
|
| 28 |
import com.spice.profitmandi.common.model.ResponseStatus;
|
28 |
import com.spice.profitmandi.common.model.ResponseStatus;
|
| - |
|
29 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 29 |
import com.spice.profitmandi.web.res.SolrSearchResultResponse;
|
30 |
import com.spice.profitmandi.web.res.SolrSearchResultResponse;
|
| 30 |
import com.spice.profitmandi.web.res.SolrSuggestionResponse;
|
31 |
import com.spice.profitmandi.web.res.SolrSuggestionResponse;
|
| 31 |
import com.spice.profitmandi.web.services.SolrService;
|
32 |
import com.spice.profitmandi.web.services.SolrService;
|
| 32 |
|
33 |
|
| 33 |
import io.swagger.annotations.ApiImplicitParam;
|
34 |
import io.swagger.annotations.ApiImplicitParam;
|
| Line 38... |
Line 39... |
| 38 |
public class SolrSearchController {
|
39 |
public class SolrSearchController {
|
| 39 |
|
40 |
|
| 40 |
private static final Logger logger=LoggerFactory.getLogger(SolrSearchController.class);
|
41 |
private static final Logger logger=LoggerFactory.getLogger(SolrSearchController.class);
|
| 41 |
|
42 |
|
| 42 |
@Autowired
|
43 |
@Autowired
|
| 43 |
SolrService solrService;
|
44 |
private SolrService solrService;
|
| - |
|
45 |
|
| - |
|
46 |
@Autowired
|
| - |
|
47 |
private ResponseSender<?> responseSender;
|
| 44 |
|
48 |
|
| 45 |
private static final int max_count = 10;
|
49 |
private static final int max_count = 10;
|
| 46 |
private static final int max_count_accesories = 5;
|
50 |
private static final int max_count_accesories = 5;
|
| 47 |
private double max_accessory_score, max_mobile_score, max_tablet_score;
|
51 |
private double max_accessory_score, max_mobile_score, max_tablet_score;
|
| 48 |
private int mobile_records, tablet_records;
|
52 |
private int mobile_records, tablet_records;
|
| Line 69... |
Line 73... |
| 69 |
for (JsonValue j : result_json ){
|
73 |
for (JsonValue j : result_json ){
|
| 70 |
j.asObject().add("productUrl", j.asObject().get("ids").asArray().get(0)+"/"+j.asObject().get("id").asString());
|
74 |
j.asObject().add("productUrl", j.asObject().get("ids").asArray().get(0)+"/"+j.asObject().get("id").asString());
|
| 71 |
}
|
75 |
}
|
| 72 |
Gson gson = new Gson();
|
76 |
Gson gson = new Gson();
|
| 73 |
List<SolrSearchResultResponse> solrSearchResultResponse = gson.fromJson(result_json.toString(), new TypeToken<List<SolrSearchResultResponse>>(){}.getType());
|
77 |
List<SolrSearchResultResponse> solrSearchResultResponse = gson.fromJson(result_json.toString(), new TypeToken<List<SolrSearchResultResponse>>(){}.getType());
|
| 74 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SEARCH , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, solrSearchResultResponse);
|
- |
|
| 75 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
78 |
return responseSender.ok(solrSearchResultResponse);
|
| 76 |
}
|
79 |
}
|
| 77 |
|
80 |
|
| 78 |
|
81 |
|
| 79 |
@RequestMapping(value = ProfitMandiConstants.URL_SOLR_SUGGESTION, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
82 |
@RequestMapping(value = ProfitMandiConstants.URL_SOLR_SUGGESTION, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
| 80 |
@ApiImplicitParams({
|
83 |
@ApiImplicitParams({
|
| Line 93... |
Line 96... |
| 93 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
96 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
| 94 |
}
|
97 |
}
|
| 95 |
result_json = Json.parse(jsonString).asObject().get("grouped").asObject();
|
98 |
result_json = Json.parse(jsonString).asObject().get("grouped").asObject();
|
| 96 |
Gson gson = new Gson();
|
99 |
Gson gson = new Gson();
|
| 97 |
List<SolrSuggestionResponse> solrSearchResultResponse = gson.fromJson(sanatizedResults().toString(), new TypeToken<List<SolrSuggestionResponse>>(){}.getType());
|
100 |
List<SolrSuggestionResponse> solrSearchResultResponse = gson.fromJson(sanatizedResults().toString(), new TypeToken<List<SolrSuggestionResponse>>(){}.getType());
|
| 98 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), ProfitMandiConstants.URL_SOLR_SUGGESTION , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS,solrSearchResultResponse);
|
- |
|
| 99 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
101 |
return responseSender.ok(solrSearchResultResponse);
|
| 100 |
}
|
102 |
}
|
| 101 |
|
103 |
|
| 102 |
private JsonArray sanatizedResults(){
|
104 |
private JsonArray sanatizedResults(){
|
| 103 |
//Need to re-write this section.This sucks badly
|
105 |
//Need to re-write this section.This sucks badly
|
| 104 |
JsonArray output = Json.array().asArray();
|
106 |
JsonArray output = Json.array().asArray();
|