kcsc-back-end <> kcsc-opensearch 통신 작업 완료

kcsc-opensearch <> opensearch 배포서버 세팅중.
thkim
강석 최 2024-04-15 17:54:20 +09:00
parent d0f17a8086
commit a7e798d5d7
17 changed files with 256 additions and 30 deletions

View File

@ -89,6 +89,10 @@ dependencies {
implementation 'org.apache.commons:commons-lang3' implementation 'org.apache.commons:commons-lang3'
// https://mvnrepository.com/artifact/org.apache.httpcomponents.client5/httpclient5
implementation group: 'org.apache.httpcomponents.client5', name: 'httpclient5', version: '5.3.1'
// https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
} }

View File

@ -89,6 +89,9 @@ public class SecurityConfig {
/* 기준코드 조회 */ /* 기준코드 조회 */
"/standardCode/**", "/standardCode/**",
/* 통합검색 요청 */
"/search/doc",
/* 관련사이트 이미지 조회 */ /* 관련사이트 이미지 조회 */
"/admin/config/get-site-image/**" "/admin/config/get-site-image/**"
}; };

View File

@ -0,0 +1,29 @@
package com.dbnt.kcscbackend.search;
import com.dbnt.kcscbackend.search.model.DocTitle;
import com.dbnt.kcscbackend.search.service.SearchService;
import lombok.RequiredArgsConstructor;
import org.json.simple.JSONArray;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/search")
public class SearchController {
private final SearchService searchService;
@RequestMapping("/doc")
public JSONArray searchDoc(
@RequestParam(value="target", required = true) String target,
@RequestParam(value="searchText", required = true) String text,
@RequestParam(value="pageNum", required = false, defaultValue = "1") Integer pageNum,
@RequestParam(value="pageSize", required = false, defaultValue = "15") Integer pageSize
){
return searchService.searchRequest(target, text, pageNum, pageSize);
}
}

View File

@ -0,0 +1,25 @@
package com.dbnt.kcscbackend.search.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class DocContent {
private Integer id;
private String kcscCd;
private String docNm;
private String docYr;
private String groupTitle;
private String tableContent;
}

View File

@ -0,0 +1,23 @@
package com.dbnt.kcscbackend.search.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class DocIndex {
private Integer id;
private String kcscCd;
private String docNm;
private String docYr;
private String groupTitle;
}

View File

@ -0,0 +1,21 @@
package com.dbnt.kcscbackend.search.model;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
public class DocTitle {
private Integer id;
private String kcscCd;
private String docNm;
private String docYr;
}

View File

@ -0,0 +1,46 @@
package com.dbnt.kcscbackend.search.service;
import lombok.RequiredArgsConstructor;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.json.simple.JSONArray;
import org.json.simple.parser.JSONParser;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
@Service
@RequiredArgsConstructor
public class SearchService {
public JSONArray searchRequest(String target, String text, Integer pageNum, Integer pageSize) {
String uri = "http://localhost:8090";
switch (target){
case "title": uri+="/doc-search/doc-title?";break;
case "index": uri+="/doc-search/doc-index?";break;
case "content": uri+="/doc-search/doc-content?";break;
}
String param = "searchText="+URLEncoder.encode(text, StandardCharsets.UTF_8)+"&pageNum="+pageNum+"&pageSize="+pageSize;
try{
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(uri+param);
httpGet.addHeader("User-Agent", "Mozilla/5.0");
httpGet.addHeader("Content-type", "application/json;charset=UTF-8");
CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
String json = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
return (JSONArray)new JSONParser().parse(json);
} catch (IOException | ParseException e) {
throw new RuntimeException(e);
} catch (org.json.simple.parser.ParseException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -33,3 +33,8 @@ logging.level.com.atoz_develop.mybatissample.repository=TRACE
Globals.posblAtchFileSize=5242880 Globals.posblAtchFileSize=5242880
Globals.fileStorePath=D:\\kcscUploadFiles Globals.fileStorePath=D:\\kcscUploadFiles
Globals.addedOptions=false Globals.addedOptions=false
#JWT
# redisConfig
spring.redis.host=localhost
spring.redis.port=6379

View File

@ -36,3 +36,8 @@ logging.level.com.atoz_develop.mybatissample.repository=info
Globals.posblAtchFileSize=5242880 Globals.posblAtchFileSize=5242880
Globals.fileStorePath=/kcscUploadFiles Globals.fileStorePath=/kcscUploadFiles
Globals.addedOptions=false Globals.addedOptions=false
#JWT
# redisConfig
spring.redis.host=localhost
spring.redis.port=6479

View File

@ -6,10 +6,6 @@ spring.mvc.pathmatch.matching-strategy=ant_path_matcher
Globals.pageUnit=10 Globals.pageUnit=10
Globals.pageSize=10 Globals.pageSize=10
#JWT
# redisConfig
spring.redis.host=localhost
spring.redis.port=6379
# secret key # secret key
Globals.jwt.secret = qWwMroux3QtiIJcPSIZARNTZEBBnWVH0jZ2Lx7tfFChCYi0ViZllo1bekZdiU0B3FRjJI7g90n0ha120dwlz8JZU8rOkmNCe9Uq0 Globals.jwt.secret = qWwMroux3QtiIJcPSIZARNTZEBBnWVH0jZ2Lx7tfFChCYi0ViZllo1bekZdiU0B3FRjJI7g90n0ha120dwlz8JZU8rOkmNCe9Uq0

View File

@ -0,0 +1,59 @@
package com.dbnt.kcscopensearch.indexing;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocContentView;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocIndexView;
import com.dbnt.kcscopensearch.kcsc.docView.model.DocTitleView;
import com.dbnt.kcscopensearch.kcsc.docView.service.DocViewService;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocContent;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocIndex;
import com.dbnt.kcscopensearch.opensearch.docSearch.model.DocTitle;
import com.dbnt.kcscopensearch.opensearch.docSearch.service.DocSearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequiredArgsConstructor
@RequestMapping("/indexing")
public class IndexingController {
private final DocViewService docViewService;
private final DocSearchService docSearchService;
@GetMapping("/doc-title")
public String getTitleIndexing(){
List<DocTitleView> titleViewList = docViewService.selectAllDocTitle();
List<DocTitle> titleList = new ArrayList<>();
for(DocTitleView view: titleViewList){
titleList.add(new DocTitle(view));
}
docSearchService.saveDocTitle(titleList);
return "OK";
}
@GetMapping("/doc-index")
public String getIndexIndexing(){
List<DocIndexView> indexViewList = docViewService.selectAllDocIndex();
List<DocIndex> indexList = new ArrayList<>();
for(DocIndexView view: indexViewList){
indexList.add(new DocIndex(view));
}
docSearchService.saveDocIndex(indexList);
return "OK";
}
@GetMapping("/doc-content")
public String getContentIndexing(){
List<DocContentView> contentViewList = docViewService.selectAllDocContent();
List<DocContent> contentList = new ArrayList<>();
for(DocContentView view: contentViewList){
contentList.add(new DocContent(view));
}
docSearchService.saveDocContent(contentList);
return "OK";
}
}

View File

@ -20,15 +20,24 @@ public class DocSearchController {
private final DocSearchService docSearchService; private final DocSearchService docSearchService;
@GetMapping(value="/doc-title", produces = MediaType.APPLICATION_JSON_VALUE) @GetMapping(value="/doc-title", produces = MediaType.APPLICATION_JSON_VALUE)
public List<DocTitle> searchTitle (@RequestParam(value="searchText", required = true) String text, @RequestParam(value="pageNum", required = true) Integer pageNum){ public List<DocTitle> searchTitle (
return docSearchService.selectDocTitle(text, pageNum); @RequestParam(value="searchText", required = true) String text,
@RequestParam(value="pageNum", required = false, defaultValue = "1") Integer pageNum,
@RequestParam(value="pageSize", required = false, defaultValue = "15") Integer pageSize){
return docSearchService.selectDocTitle(text, pageNum, pageSize);
} }
@GetMapping(value="/doc-index", produces = MediaType.APPLICATION_JSON_VALUE) @GetMapping(value="/doc-index", produces = MediaType.APPLICATION_JSON_VALUE)
public List<DocIndex> searchIndex (@RequestParam(value="searchText", required = true) String text, @RequestParam(value="pageNum", required = true) Integer pageNum){ public List<DocIndex> searchIndex (
return docSearchService.selectDocIndex(text, pageNum); @RequestParam(value="searchText", required = true) String text,
@RequestParam(value="pageNum", required = false, defaultValue = "1") Integer pageNum,
@RequestParam(value="pageSize", required = false, defaultValue = "15") Integer pageSize){
return docSearchService.selectDocIndex(text, pageNum, pageSize);
} }
@GetMapping(value="/doc-content", produces = MediaType.APPLICATION_JSON_VALUE) @GetMapping(value="/doc-content", produces = MediaType.APPLICATION_JSON_VALUE)
public List<DocContent> searchContent (@RequestParam(value="searchText", required = true) String text, @RequestParam(value="pageNum", required = true) Integer pageNum){ public List<DocContent> searchContent (
return docSearchService.selectDocContent(text, pageNum); @RequestParam(value="searchText", required = true) String text,
@RequestParam(value="pageNum", required = false, defaultValue = "1") Integer pageNum,
@RequestParam(value="pageSize", required = false, defaultValue = "15") Integer pageSize){
return docSearchService.selectDocContent(text, pageNum, pageSize);
} }
} }

View File

@ -123,15 +123,15 @@ public class DocSearchService {
log.info("contentIndexing end"); log.info("contentIndexing end");
} }
public List<DocTitle> selectDocTitle(String text, Integer pageNum) { public List<DocTitle> selectDocTitle(String text, Integer pageNum, Integer pageSize) {
return titleRepository.findByDocNmContains(text, PageRequest.of(pageNum, 20)); return titleRepository.findByDocNmContains(text, PageRequest.of(pageNum, pageSize));
} }
public List<DocIndex> selectDocIndex(String text, Integer pageNum){ public List<DocIndex> selectDocIndex(String text, Integer pageNum, Integer pageSize){
return indexRepository.findByGroupTitleContains(text, PageRequest.of(pageNum, 20)); return indexRepository.findByGroupTitleContains(text, PageRequest.of(pageNum, pageSize));
} }
public List<DocContent> selectDocContent(String text, Integer pageNum){ public List<DocContent> selectDocContent(String text, Integer pageNum, Integer pageSize){
return contentRepository.findByTableContentContains(text, PageRequest.of(pageNum, 20)); return contentRepository.findByTableContentContains(text, PageRequest.of(pageNum, pageSize));
} }
} }

View File

@ -21,7 +21,7 @@ public class IndexingScheduler {
private final DocViewService docViewService; private final DocViewService docViewService;
private final DocSearchService docSearchService; private final DocSearchService docSearchService;
@Scheduled(cron = "40 18 23 * * *") /*@Scheduled(cron = "40 18 23 * * *")
public void viewIndexing(){ public void viewIndexing(){
Map<String, List<?>> viewDataMap = docViewService.selectAllView(); Map<String, List<?>> viewDataMap = docViewService.selectAllView();
Map<String, List<?>> indexingDataMap = new HashMap<>(); Map<String, List<?>> indexingDataMap = new HashMap<>();
@ -57,12 +57,10 @@ public class IndexingScheduler {
} }
docSearchService.save(indexingDataMap); docSearchService.save(indexingDataMap);
}*/
//docSearchService.save(indexingDataMap); @Scheduled(cron = "40 1 2 * * *")
} public void ScheduledTitleIndexing(){
@Scheduled(cron = "40 20 23 * * *")
public void titleIndexing(){
List<DocTitleView> titleViewList = docViewService.selectAllDocTitle(); List<DocTitleView> titleViewList = docViewService.selectAllDocTitle();
List<DocTitle> titleList = new ArrayList<>(); List<DocTitle> titleList = new ArrayList<>();
for(DocTitleView view: titleViewList){ for(DocTitleView view: titleViewList){
@ -70,8 +68,8 @@ public class IndexingScheduler {
} }
docSearchService.saveDocTitle(titleList); docSearchService.saveDocTitle(titleList);
} }
@Scheduled(cron = "40 21 23 * * *") @Scheduled(cron = "40 2 2 * * *")
public void indexIndexing(){ public void ScheduledIndexIndexing(){
List<DocIndexView> indexViewList = docViewService.selectAllDocIndex(); List<DocIndexView> indexViewList = docViewService.selectAllDocIndex();
List<DocIndex> indexList = new ArrayList<>(); List<DocIndex> indexList = new ArrayList<>();
for(DocIndexView view: indexViewList){ for(DocIndexView view: indexViewList){
@ -79,8 +77,8 @@ public class IndexingScheduler {
} }
docSearchService.saveDocIndex(indexList); docSearchService.saveDocIndex(indexList);
} }
@Scheduled(cron = "40 25 23 * * *") @Scheduled(cron = "40 7 2 * * *")
public void contentIndexing(){ public void ScheduledContentIndexing(){
List<DocContentView> contentViewList = docViewService.selectAllDocContent(); List<DocContentView> contentViewList = docViewService.selectAllDocContent();
List<DocContent> contentList = new ArrayList<>(); List<DocContent> contentList = new ArrayList<>();
for(DocContentView view: contentViewList){ for(DocContentView view: contentViewList){

View File

@ -0,0 +1,3 @@
opensearch.uris=https://localhost:9200
opensearch.username=admin
opensearch.password=kpbP7ECsaTlgvfmaGNBtORH75QHf7TmJhHZdW7Z7

View File

@ -0,0 +1,3 @@
opensearch.uris=https://kcsc.dbnt.co.kr:9200
opensearch.username=admin
opensearch.password=kpbP7ECsaTlgvfmaGNBtORH75QHf7TmJhHZdW7Z7

View File

@ -1,8 +1,5 @@
spring.application.name=kcsc-opensearch spring.application.name=kcsc-opensearch
server.port=8090
opensearch.uris=https://localhost:9200
opensearch.username=admin
opensearch.password=kpbP7ECsaTlgvfmaGNBtORH75QHf7TmJhHZdW7Z7
spring.datasource-kcsc.driverClassName=org.postgresql.Driver spring.datasource-kcsc.driverClassName=org.postgresql.Driver
spring.datasource-kcsc.jdbcUrl=jdbc:postgresql://118.219.150.34:50503/kcsc spring.datasource-kcsc.jdbcUrl=jdbc:postgresql://118.219.150.34:50503/kcsc