Subversion Repositories SmartDukaan

Rev

Rev 20193 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 20193 Rev 20194
Line 27... Line 27...
27
	private String search_text;
27
	private String search_text;
28
 
28
 
29
	public String index() throws URISyntaxException, IOException{
29
	public String index() throws URISyntaxException, IOException{
30
		JsonArray outputJson = Json.array().asArray();
30
		JsonArray outputJson = Json.array().asArray();
31
		URIBuilder b = new URIBuilder("http://192.168.194.109:8983/solr/collection1/select");
31
		URIBuilder b = new URIBuilder("http://192.168.194.109:8983/solr/collection1/select");
32
		String[] search_terms_array = search_text.split(" ");
32
		String[] search_terms_array = search_text.split("\\s+");
33
		//iphone AND apple AND 5s
33
		//iphone AND apple AND 5s
34
 
34
 
35
		StringBuilder sb = new StringBuilder();
35
		StringBuilder sb = new StringBuilder();
36
 
36
 
37
		int c = 0;
37
		int c = 1;
38
		for (String s : search_terms_array){
38
		for (String s : search_terms_array){
39
 
39
			
40
			if (c==search_terms_array.length){
40
			if (c==search_terms_array.length){
41
				sb.append(s.trim());
41
				sb.append(s.trim());
42
			}
42
			}
43
			else{
43
			else{
44
				sb.append(s.trim()+" AND ");
44
				sb.append(s.trim()+" AND ");
45
			}
45
			}
46
			c++;
46
			c++;
47
		}
47
		}
48
 
48
 
49
 
49
 
50
		//b.addParameter("q", "\"*"+search_text.trim()+"*\"");
50
		b.addParameter("q", sb.toString());
51
		b.addParameter("fl", "title,subCategoryId,category_id,category,subCategory");
51
		b.addParameter("fl", "title,subCategoryId,category_id,category,subCategory");
52
		b.addParameter("wt", "json");
52
		b.addParameter("wt", "json");
53
		b.addParameter("group", "true");
53
		b.addParameter("group", "true");
54
		b.addParameter("group.query", "category_id:3");
54
		b.addParameter("group.query", "category_id:3");
55
		b.addParameter("group.query", "category_id:5");
55
		b.addParameter("group.query", "category_id:5");
Line 138... Line 138...
138
		return search_text;
138
		return search_text;
139
	}
139
	}
140
 
140
 
141
	public static void main(String[] args) throws URISyntaxException, IOException{
141
	public static void main(String[] args) throws URISyntaxException, IOException{
142
		AutoSuggestController a =  new AutoSuggestController();
142
		AutoSuggestController a =  new AutoSuggestController();
143
		a.setSearch_text("apple");
143
		a.setSearch_text("iphone");
144
		a.index();
144
		a.index();
145
		System.out.println(a.getResultJson());
145
		System.out.println(a.getResultJson());
146
	}
146
	}
147
 
147
 
148
}
148
}