| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.common.solr;
|
1 |
package com.spice.profitmandi.common.solr;
|
| 2 |
|
2 |
|
| 3 |
import java.util.ArrayList;
|
3 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 4 |
import java.util.Arrays;
|
4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 5 |
import java.util.HashMap;
|
5 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 6 |
import java.util.List;
|
- |
|
| 7 |
import java.util.Map;
|
- |
|
| 8 |
|
- |
|
| 9 |
import org.apache.commons.lang3.StringUtils;
|
6 |
import org.apache.commons.lang3.StringUtils;
|
| 10 |
import org.apache.http.conn.HttpHostConnectException;
|
7 |
import org.apache.http.conn.HttpHostConnectException;
|
| 11 |
import org.apache.logging.log4j.LogManager;
|
8 |
import org.apache.logging.log4j.LogManager;
|
| 12 |
import org.apache.logging.log4j.Logger;
|
9 |
import org.apache.logging.log4j.Logger;
|
| 13 |
import org.json.JSONArray;
|
10 |
import org.json.JSONArray;
|
| 14 |
import org.json.JSONObject;
|
11 |
import org.json.JSONObject;
|
| 15 |
import org.springframework.beans.factory.annotation.Autowired;
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 16 |
import org.springframework.beans.factory.annotation.Value;
|
13 |
import org.springframework.beans.factory.annotation.Value;
|
| 17 |
import org.springframework.stereotype.Service;
|
14 |
import org.springframework.stereotype.Service;
|
| 18 |
|
15 |
|
| 19 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
16 |
import java.util.*;
|
| 20 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
- |
|
| 21 |
import com.spice.profitmandi.common.web.client.RestClient;
|
- |
|
| 22 |
|
17 |
|
| 23 |
@Service("solrServiceCommon")
|
18 |
@Service("solrServiceCommon")
|
| 24 |
public class SolrService {
|
19 |
public class SolrService {
|
| 25 |
|
20 |
|
| 26 |
private static final Logger logger = LogManager.getLogger(SolrService.class);
|
21 |
private static final Logger logger = LogManager.getLogger(SolrService.class);
|
| Line 29... |
Line 24... |
| 29 |
private String solrUrl;
|
24 |
private String solrUrl;
|
| 30 |
|
25 |
|
| 31 |
@Autowired
|
26 |
@Autowired
|
| 32 |
private RestClient restClient;
|
27 |
private RestClient restClient;
|
| 33 |
|
28 |
|
| 34 |
public String getContent(String queryTerm, int categoryId, List<String> brands, int limit) throws Exception {
|
29 |
public String getContent(String queryTerm, int categoryId, List<String> brands, int limit, boolean activeOnly) throws Exception {
|
| 35 |
Map<String, String> params = new HashMap<>();
|
30 |
Map<String, String> params = new HashMap<>();
|
| 36 |
List<String> mandatoryQ = new ArrayList<>();
|
31 |
List<String> mandatoryQ = new ArrayList<>();
|
| 37 |
if (queryTerm != null && !queryTerm.equals("null")) {
|
32 |
if (queryTerm != null && !queryTerm.equals("null")) {
|
| 38 |
mandatoryQ.add(String.format("+(%s)", "*" + queryTerm + "*"));
|
33 |
mandatoryQ.add(String.format("+(%s)", "*" + queryTerm + "*"));
|
| 39 |
} else {
|
34 |
} else {
|
| Line 44... |
Line 39... |
| 44 |
params.put("q", params.get("q") + " +filter(categoryId_i:" + categoryId + ")");
|
39 |
params.put("q", params.get("q") + " +filter(categoryId_i:" + categoryId + ")");
|
| 45 |
}
|
40 |
}
|
| 46 |
if (brands.size() > 0) {
|
41 |
if (brands.size() > 0) {
|
| 47 |
params.put("q", params.get("q") + " AND brand_ss:(" + StringUtils.join(brands, " ") + ")");
|
42 |
params.put("q", params.get("q") + " AND brand_ss:(" + StringUtils.join(brands, " ") + ")");
|
| 48 |
}
|
43 |
}
|
| - |
|
44 |
if (activeOnly) {
|
| - |
|
45 |
params.put("q", params.get("q") + " AND active_b:true");
|
| - |
|
46 |
}
|
| 49 |
params.put("fl", "*");
|
47 |
params.put("fl", "*");
|
| 50 |
if (queryTerm == null) {
|
48 |
if (queryTerm == null) {
|
| 51 |
params.put("sort", "create_s desc");
|
49 |
params.put("sort", "create_s desc");
|
| 52 |
}
|
50 |
}
|
| 53 |
params.put("start", String.valueOf(0));
|
51 |
params.put("start", String.valueOf(0));
|