|
@ -6,7 +6,7 @@ import com.yihu.ehr.hbase.HBaseDao;
|
|
import com.yihu.ehr.profile.core.ResourceCore;
|
|
import com.yihu.ehr.profile.core.ResourceCore;
|
|
import com.yihu.ehr.profile.family.ResourceCells;
|
|
import com.yihu.ehr.profile.family.ResourceCells;
|
|
import com.yihu.ehr.resource.constants.MicroServiceApi;
|
|
import com.yihu.ehr.resource.constants.MicroServiceApi;
|
|
import com.yihu.ehr.resource.service.ProfileSearchService;
|
|
|
|
|
|
import com.yihu.ehr.resource.service.TextSearchService;
|
|
import com.yihu.ehr.solr.SolrUtil;
|
|
import com.yihu.ehr.solr.SolrUtil;
|
|
import com.yihu.ehr.util.rest.Envelop;
|
|
import com.yihu.ehr.util.rest.Envelop;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
@ -20,10 +20,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author progr1mmer.
|
|
* @author progr1mmer.
|
|
@ -39,30 +36,33 @@ public class TextSearchEndPoint extends EnvelopRestEndPoint {
|
|
@Autowired
|
|
@Autowired
|
|
private HBaseDao hBaseDao;
|
|
private HBaseDao hBaseDao;
|
|
@Autowired
|
|
@Autowired
|
|
private ProfileSearchService profileSearchService;
|
|
|
|
|
|
private TextSearchService textSearchService;
|
|
|
|
|
|
@ApiOperation(value = "全文检索")
|
|
@ApiOperation(value = "全文检索")
|
|
@RequestMapping(value = MicroServiceApi.TextSearch.TextSearch, method = RequestMethod.GET)
|
|
@RequestMapping(value = MicroServiceApi.TextSearch.TextSearch, method = RequestMethod.GET)
|
|
public Envelop countEhrCenter(
|
|
public Envelop countEhrCenter(
|
|
@ApiParam(name = "keyword", value = "关键词")
|
|
@ApiParam(name = "keyword", value = "关键词")
|
|
@RequestParam(value = "keyword", required = false) String keyword,
|
|
@RequestParam(value = "keyword", required = false) String keyword,
|
|
@ApiParam(name = "page", value = "页数", required = true)
|
|
|
|
|
|
@ApiParam(name = "filters", value = "过滤条件")
|
|
|
|
@RequestParam(value = "filters", required = false) String filters,
|
|
|
|
@ApiParam(name = "page", value = "页数", defaultValue = "1", required = true)
|
|
@RequestParam(value = "page") Integer page,
|
|
@RequestParam(value = "page") Integer page,
|
|
@ApiParam(name = "size", value = "分页大小", required = true)
|
|
|
|
|
|
@ApiParam(name = "size", value = "分页大小", defaultValue = "15", required = true)
|
|
@RequestParam(value = "size") Integer size) throws Exception {
|
|
@RequestParam(value = "size") Integer size) throws Exception {
|
|
if (page == 0) {
|
|
|
|
|
|
if (0 == page) {
|
|
page ++;
|
|
page ++;
|
|
}
|
|
}
|
|
//更新热搜
|
|
//更新热搜
|
|
profileSearchService.saveOrUpdateHotWords(keyword, 1);
|
|
|
|
|
|
textSearchService.saveOrUpdateHotWords(keyword, 1);
|
|
Map<String, String> sortMap = new HashMap<>(1);
|
|
Map<String, String> sortMap = new HashMap<>(1);
|
|
sortMap.put(ResourceCells.EVENT_DATE, "desc");
|
|
sortMap.put(ResourceCells.EVENT_DATE, "desc");
|
|
QueryResponse queryResponse = solrUtil.highlight(ResourceCore.MasterTable, generateQ(keyword), null, sortMap, page - 1, size, ResourceCells.SEARCH_FIELD, null);
|
|
|
|
|
|
QueryResponse queryResponse = solrUtil.highlight(ResourceCore.MasterTable, generateQ(keyword, filters), null, sortMap, page - 1, size, ResourceCells.SEARCH_FIELD, null);
|
|
List<Map<String, Object>> dataList = new ArrayList<>(queryResponse.getHighlighting().size());
|
|
List<Map<String, Object>> dataList = new ArrayList<>(queryResponse.getHighlighting().size());
|
|
queryResponse.getResults().forEach(document -> {
|
|
queryResponse.getResults().forEach(document -> {
|
|
Map<String, Object> result = new HashMap<>();
|
|
Map<String, Object> result = new HashMap<>();
|
|
String rowkey = (String) document.get(ResourceCells.ROWKEY);
|
|
String rowkey = (String) document.get(ResourceCells.ROWKEY);
|
|
Map<String, Object> data = hBaseDao.getResultMap(ResourceCore.MasterTable, rowkey);
|
|
Map<String, Object> data = hBaseDao.getResultMap(ResourceCore.MasterTable, rowkey);
|
|
|
|
result.put(ResourceCells.DEMOGRAPHIC_ID, data.get(ResourceCells.DEMOGRAPHIC_ID));
|
|
result.put(ResourceCells.ROWKEY, data.get(ResourceCells.ROWKEY));
|
|
result.put(ResourceCells.ROWKEY, data.get(ResourceCells.ROWKEY));
|
|
result.put(ResourceCells.EVENT_DATE, data.get(ResourceCells.EVENT_DATE));
|
|
result.put(ResourceCells.EVENT_DATE, data.get(ResourceCells.EVENT_DATE));
|
|
result.put(ResourceCells.EVENT_TYPE, data.get(ResourceCells.EVENT_TYPE));
|
|
result.put(ResourceCells.EVENT_TYPE, data.get(ResourceCells.EVENT_TYPE));
|
|
@ -76,6 +76,13 @@ public class TextSearchEndPoint extends EnvelopRestEndPoint {
|
|
} else {
|
|
} else {
|
|
result.put("dept_name", "");
|
|
result.put("dept_name", "");
|
|
}
|
|
}
|
|
|
|
if (data.get("EHR_000079") != null) {
|
|
|
|
result.put("doctor", data.get("EHR_000079"));
|
|
|
|
} else if (data.get("EHR_000172") != null) {
|
|
|
|
result.put("doctor", data.get("EHR_000172"));
|
|
|
|
} else {
|
|
|
|
result.put("doctor", "");
|
|
|
|
}
|
|
result.put(ResourceCells.ORG_NAME, data.get(ResourceCells.ORG_NAME));
|
|
result.put(ResourceCells.ORG_NAME, data.get(ResourceCells.ORG_NAME));
|
|
if (queryResponse.getHighlighting().get(rowkey).get(ResourceCells.SEARCH_FIELD) != null) {
|
|
if (queryResponse.getHighlighting().get(rowkey).get(ResourceCells.SEARCH_FIELD) != null) {
|
|
result.put("hl", queryResponse.getHighlighting().get(rowkey).get(ResourceCells.SEARCH_FIELD).get(0));
|
|
result.put("hl", queryResponse.getHighlighting().get(rowkey).get(ResourceCells.SEARCH_FIELD).get(0));
|
|
@ -94,7 +101,7 @@ public class TextSearchEndPoint extends EnvelopRestEndPoint {
|
|
@RequestParam(value = "reCount") int reCount,
|
|
@RequestParam(value = "reCount") int reCount,
|
|
@ApiParam(name = "type", value = "类型,1:病人档案热搜", required = true)
|
|
@ApiParam(name = "type", value = "类型,1:病人档案热搜", required = true)
|
|
@RequestParam(value = "type") int type){
|
|
@RequestParam(value = "type") int type){
|
|
List<String> hotWords = profileSearchService.getHotWords(type,reCount);
|
|
|
|
|
|
List<String> hotWords = textSearchService.getHotWords(type, reCount);
|
|
return hotWords;
|
|
return hotWords;
|
|
}
|
|
}
|
|
|
|
|
|
@ -105,10 +112,10 @@ public class TextSearchEndPoint extends EnvelopRestEndPoint {
|
|
@RequestParam(value = "searchText") String searchText,
|
|
@RequestParam(value = "searchText") String searchText,
|
|
@ApiParam(name = "type", value = "类型,1:病人档案热搜", required = true)
|
|
@ApiParam(name = "type", value = "类型,1:病人档案热搜", required = true)
|
|
@RequestParam(value = "type") int type){
|
|
@RequestParam(value = "type") int type){
|
|
return profileSearchService.saveOrUpdateHotWords(searchText,type);
|
|
|
|
|
|
return textSearchService.saveOrUpdateHotWords(searchText, type);
|
|
}
|
|
}
|
|
|
|
|
|
private String generateQ(String keyword) {
|
|
|
|
|
|
private String generateQ(String keyword, String filters) {
|
|
if (StringUtils.isEmpty(keyword)) {
|
|
if (StringUtils.isEmpty(keyword)) {
|
|
return "*:*";
|
|
return "*:*";
|
|
}
|
|
}
|
|
@ -136,6 +143,29 @@ public class TextSearchEndPoint extends EnvelopRestEndPoint {
|
|
} else {
|
|
} else {
|
|
q.append(ResourceCells.SEARCH_FIELD + ":" + keyword);
|
|
q.append(ResourceCells.SEARCH_FIELD + ":" + keyword);
|
|
}
|
|
}
|
|
|
|
if (StringUtils.isNotEmpty(filters)) {
|
|
|
|
filters.split(":");
|
|
|
|
}
|
|
|
|
return getQuery(filters, q);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getQuery(String filters, StringBuilder q) {
|
|
|
|
if (!StringUtils.isEmpty(filters)) {
|
|
|
|
String [] conditions = filters.split(";");
|
|
|
|
for (String condition : conditions) {
|
|
|
|
if (condition.split("=").length == 2) {
|
|
|
|
String key = condition.split("=")[0];
|
|
|
|
String value = condition.split("=")[1];
|
|
|
|
q.append(" AND " + key + ":" + value);
|
|
|
|
}
|
|
|
|
if (condition.split("\\?").length == 2) {
|
|
|
|
String key = condition.split("\\?")[0];
|
|
|
|
String value = condition.split("\\?")[1];
|
|
|
|
q.append(" AND " + key + ":*" + value + "*");
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
return q.toString();
|
|
return q.toString();
|
|
}
|
|
}
|
|
}
|
|
}
|