diff --git a/.gradle/7.2/executionHistory/executionHistory.bin b/.gradle/7.2/executionHistory/executionHistory.bin index 15804b86..44ba1af6 100644 Binary files a/.gradle/7.2/executionHistory/executionHistory.bin and b/.gradle/7.2/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.2/executionHistory/executionHistory.lock b/.gradle/7.2/executionHistory/executionHistory.lock index c2ff3345..0f43e7d0 100644 Binary files a/.gradle/7.2/executionHistory/executionHistory.lock and b/.gradle/7.2/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.2/fileHashes/fileHashes.bin b/.gradle/7.2/fileHashes/fileHashes.bin index db11a353..99ae9bce 100644 Binary files a/.gradle/7.2/fileHashes/fileHashes.bin and b/.gradle/7.2/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.2/fileHashes/fileHashes.lock b/.gradle/7.2/fileHashes/fileHashes.lock index de060487..5c02d361 100644 Binary files a/.gradle/7.2/fileHashes/fileHashes.lock and b/.gradle/7.2/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.2/fileHashes/resourceHashesCache.bin b/.gradle/7.2/fileHashes/resourceHashesCache.bin index 492e6a84..48fcdcc8 100644 Binary files a/.gradle/7.2/fileHashes/resourceHashesCache.bin and b/.gradle/7.2/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 773790f4..e5ea8758 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java b/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java index 99859d20..649b7f0b 100644 --- a/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java +++ b/src/main/generated/com/example/just/Mapper/MemberMapperImpl.java @@ -10,7 +10,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2024-06-03T09:49:05+0900", + date = "2024-06-04T15:55:41+0900", comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 11.0.11 (AdoptOpenJDK)" ) @Component diff --git a/src/main/generated/com/example/just/Mapper/PostMapperImpl.java b/src/main/generated/com/example/just/Mapper/PostMapperImpl.java index 331c018c..027fcd09 100644 --- a/src/main/generated/com/example/just/Mapper/PostMapperImpl.java +++ b/src/main/generated/com/example/just/Mapper/PostMapperImpl.java @@ -10,7 +10,7 @@ @Generated( value = "org.mapstruct.ap.MappingProcessor", - date = "2024-06-03T09:49:06+0900", + date = "2024-06-04T15:55:41+0900", comments = "version: 1.5.3.Final, compiler: IncrementalProcessingEnvironment from gradle-language-java-7.2.jar, environment: Java 11.0.11 (AdoptOpenJDK)" ) @Component diff --git a/src/main/java/com/example/just/Repository/PostContentESRespository.java b/src/main/java/com/example/just/Repository/PostContentESRespository.java index 26d71177..deaf24f9 100644 --- a/src/main/java/com/example/just/Repository/PostContentESRespository.java +++ b/src/main/java/com/example/just/Repository/PostContentESRespository.java @@ -13,7 +13,7 @@ public interface PostContentESRespository extends ElasticsearchRepository, CrudRepository { // List findByPostContent_ContentContains(String text); - // List findByPostContent_ContentContains(String text); +// List findByPostContent_ContentContains(String text); //해당 text문자열을 하나라도 포함하는 게시글 전제조회(ELK) List findByPostContentContaining(String text); diff --git a/src/main/java/com/example/just/Service/SearchService.java b/src/main/java/com/example/just/Service/SearchService.java index da31c976..bb328fa5 100644 --- a/src/main/java/com/example/just/Service/SearchService.java +++ b/src/main/java/com/example/just/Service/SearchService.java @@ -15,13 +15,19 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; +import javax.management.Query; import javax.servlet.http.HttpServletRequest; +import org.elasticsearch.index.query.QueryBuilders; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Direction; +import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; +import org.springframework.data.elasticsearch.core.SearchHits; +import org.springframework.data.elasticsearch.core.query.NativeSearchQuery; +import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -47,6 +53,12 @@ public class SearchService { //검색(ELK) 관련 서비스 @Autowired MemberRepository memberRepository; + private final ElasticsearchRestTemplate elasticsearchRestTemplate; + + public SearchService(ElasticsearchRestTemplate elasticsearchRestTemplate) { + this.elasticsearchRestTemplate = elasticsearchRestTemplate; + } + //게시글 내용 검색 public ResponseEntity searchPostContent(HttpServletRequest request,String keyword,int page){ @@ -69,7 +81,16 @@ public ResponseEntity searchPostContent(HttpServletRequest request,String keywor .collect(Collectors.toList()); //검색한 키워드를 내용에 포함하는 게시글 리스트 조회 - List searchList = postContentESRespository.findByPostContentContaining(keyword); +// List searchList = postContentESRespository.findByPostContentContaining(keyword); + NativeSearchQuery query = new NativeSearchQueryBuilder() + .withQuery(QueryBuilders.wildcardQuery("postContent", "*"+keyword+"*")) +// .withQuery(QueryBuilders.matchQuery("postContent", keyword)) + .build(); + + SearchHits searchHits = elasticsearchRestTemplate.search(query, PostDocument.class); + + List searchList = new ArrayList<>(); + searchHits.forEach(searchHit -> searchList.add(searchHit.getContent())); //검색한 키워드를 포함하는 게시글이 없을 경우 if(searchList.isEmpty()){ return new ResponseEntity(new ResponseMessage("해당 내용을 포함하는 게시글이 존재하지 않습니다."), diff --git a/src/main/resources/elastic/post-setting.json b/src/main/resources/elastic/post-setting.json index 72c2684f..5f72a3f0 100644 --- a/src/main/resources/elastic/post-setting.json +++ b/src/main/resources/elastic/post-setting.json @@ -1,23 +1,15 @@ { "analysis": { "tokenizer": { - "nori_none": { + "nori_tokenizer": { "type": "nori_tokenizer", - "decompound_mode": "none" - }, - "nori_discard": { - "type": "nori_tokenizer", - "decompound_mode": "discard" - }, - "nori_mixed": { - "type": "nori_tokenizer", - "decompound_mo de": "mixed" + "decompound_mode": "mixed" } }, "analyzer": { "korean": { - "type": "nori", - "stopwords": "_korean_" + "type": "custom", + "tokenizer": "nori_tokenizer" } } }