Skip to content

Commit

Permalink
현재 3글자단어는 1,2글자만 가능한 상태
Browse files Browse the repository at this point in the history
  • Loading branch information
mjh000526 committed Jun 4, 2024
1 parent 178ad00 commit 52264af
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 16 deletions.
Binary file modified .gradle/7.2/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/7.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/7.2/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public interface PostContentESRespository extends ElasticsearchRepository<PostDocument,Long>,
CrudRepository<PostDocument,Long> {
// List<PostDocument> findByPostContent_ContentContains(String text);
// List<PostDocument> findByPostContent_ContentContains(String text);
// List<PostDocument> findByPostContent_ContentContains(String text);

//해당 text문자열을 하나라도 포함하는 게시글 전제조회(ELK)
List<PostDocument> findByPostContentContaining(String text);
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/com/example/just/Service/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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){
Expand All @@ -69,7 +81,16 @@ public ResponseEntity searchPostContent(HttpServletRequest request,String keywor
.collect(Collectors.toList());

//검색한 키워드를 내용에 포함하는 게시글 리스트 조회
List<PostDocument> searchList = postContentESRespository.findByPostContentContaining(keyword);
// List<PostDocument> searchList = postContentESRespository.findByPostContentContaining(keyword);
NativeSearchQuery query = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.wildcardQuery("postContent", "*"+keyword+"*"))
// .withQuery(QueryBuilders.matchQuery("postContent", keyword))
.build();

SearchHits<PostDocument> searchHits = elasticsearchRestTemplate.search(query, PostDocument.class);

List<PostDocument> searchList = new ArrayList<>();
searchHits.forEach(searchHit -> searchList.add(searchHit.getContent()));
//검색한 키워드를 포함하는 게시글이 없을 경우
if(searchList.isEmpty()){
return new ResponseEntity(new ResponseMessage("해당 내용을 포함하는 게시글이 존재하지 않습니다."),
Expand Down
16 changes: 4 additions & 12 deletions src/main/resources/elastic/post-setting.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Expand Down

0 comments on commit 52264af

Please sign in to comment.