Subversion Repositories SmartDukaan

Rev

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

Rev 20261 Rev 20263
Line 24... Line 24...
24
 
24
 
25
	private static final long serialVersionUID = 1L;
25
	private static final long serialVersionUID = 1L;
26
	private String search_text;
26
	private String search_text;
27
	private String offset;
27
	private String offset;
28
	private static final int max_count = 10;
28
	private static final int max_count = 10;
29
    private static final int max_count_accesories = 5;
29
	private static final int max_count_accesories = 5;
30
    private double max_accessory_score, max_mobile_score, max_tablet_score;
30
	private double max_accessory_score, max_mobile_score, max_tablet_score;
31
    private int mobile_records, tablet_records;
31
	private int mobile_records, tablet_records;
32
    private JsonObject result_json;
32
	private JsonObject result_json;
33
 
33
 
34
 
34
 
35
	private SolrService s =  new SolrService();
35
	private SolrService s =  new SolrService();
36
 
36
 
37
 
37
 
38
	public String getSuggestions() throws URISyntaxException, IOException{
38
	public String getSuggestions() throws URISyntaxException, IOException{
39
		try{
39
		try{
40
			log.info("Calling solr service (auto suggest) for search_text "+search_text);
40
			log.info("Calling solr service (auto suggest) for search_text "+search_text);
41
			String jsonString = s.getSuggestions(search_text.trim());
41
			String jsonString = s.getSuggestions(search_text.trim());
42
			result_json = Json.parse(jsonString).asObject().get("grouped").asObject();
42
			result_json = Json.parse(jsonString).asObject().get("grouped").asObject();
43
            setResultJson(sanatizedResults().toString());
43
			setResultJson(sanatizedResults().toString());
44
		}
44
		}
45
		catch(Exception e){
45
		catch(Exception e){
46
			e.printStackTrace();
46
			e.printStackTrace();
47
			setResultJson(Json.array().asArray().toString());
47
			setResultJson(Json.array().asArray().toString());
48
		}
48
		}
Line 66... Line 66...
66
				output.add(j);
66
				output.add(j);
67
			}
67
			}
68
		}
68
		}
69
 
69
 
70
		int toFetch = temp_accesories.size() == 0 ? 10 : 5;
70
		int toFetch = temp_accesories.size() == 0 ? 10 : 5;
71
		int count = 0;
71
		int count = 1;
-
 
72
 
-
 
73
		if (max_mobile_score > max_tablet_score){
-
 
74
 
72
		for (JsonValue j : temp_mobiles){
75
			for (JsonValue j : temp_mobiles){
-
 
76
				if (count > toFetch)
-
 
77
					break;
-
 
78
				output.add(j);
-
 
79
				count++;
-
 
80
			}
-
 
81
			
-
 
82
			count = 1;
-
 
83
			
-
 
84
			for (JsonValue j : temp_tablets){
73
			if (count > toFetch)
85
				if (count > toFetch)
74
				break;
86
					break;
75
			output.add(j);
87
				output.add(j);
76
			count++;
88
				count++;
-
 
89
			}
77
		}
90
		}
-
 
91
		
-
 
92
		else{
-
 
93
			for (JsonValue j : temp_tablets){
-
 
94
				if (count > toFetch)
-
 
95
					break;
-
 
96
				output.add(j);
-
 
97
				count++;
-
 
98
			}
-
 
99
			
78
		count = 0;
100
			count = 1;
-
 
101
			
79
		for (JsonValue j : temp_tablets){
102
			for (JsonValue j : temp_mobiles){
80
			if (count > toFetch)
103
				if (count > toFetch)
81
				break;
104
					break;
82
			output.add(j);
105
				output.add(j);
83
			count++;
106
				count++;
-
 
107
			}
84
		}
108
		}
85
 
109
 
86
		if (max_accessory_score <= max_mobile_score){
110
		if (max_accessory_score <= max_mobile_score){
87
			for (JsonValue j : temp_accesories){
111
			for (JsonValue j : temp_accesories){
88
				output.add(j);
112
				output.add(j);