Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

사진첩 검색 추가 시, 게시물 검색 영향 미치는 현상 수정. #118

Merged
merged 1 commit into from
Sep 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
*/

@Slf4j
@Api(tags = "게시판", description = "게시판 관련")
@Api(tags = "BoardFree", description = "자유게시판 API")
@RestController
@RequestMapping("/api/board")
public class BoardRestController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public SearchResultResponse getSearch(
SearchResult result = searchService.searchDocumentGallery(q, from, tempSize);

if (result.isSucceeded())
response.setPosts(objectMapper.readValue(result.getJsonString(), Map.class));
response.setGalleries(objectMapper.readValue(result.getJsonString(), Map.class));

}
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.jakduk.core.model.elasticsearch;

import com.jakduk.core.common.CommonConst;
import com.jakduk.core.model.db.BoardFree;
import com.jakduk.core.model.embedded.CommonWriter;
import io.searchbox.annotations.JestId;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.Optional;

/**
* @author <a href="mailto:phjang1983@daum.net">Jang,Pyohwan</a>
Expand All @@ -11,7 +18,8 @@
* @desc :
*/

@Data
@Getter
@Setter
public class BoardFreeOnES {

@JestId
Expand All @@ -26,4 +34,22 @@ public class BoardFreeOnES {
private int seq;

private String categoryName;

public BoardFreeOnES(BoardFree boardFree) {

String subjectEL = Optional.ofNullable(boardFree.getSubject()).orElse("");
subjectEL = StringUtils.replacePattern(subjectEL, CommonConst.REGEX_FIND_HTML_TAG, "");
subjectEL = StringUtils.replacePattern(subjectEL, CommonConst.REGEX_FIND_HTML_WHITESPACE, "");

String contentEL = Optional.ofNullable(boardFree.getContent()).orElse("");
contentEL = StringUtils.replacePattern(contentEL, CommonConst.REGEX_FIND_HTML_TAG, "");
contentEL = StringUtils.replacePattern(contentEL, CommonConst.REGEX_FIND_HTML_WHITESPACE, "");

this.id = boardFree.getId();
this.writer = boardFree.getWriter();
this.subject = subjectEL;
this.content = contentEL;
this.seq = boardFree.getSeq();
this.categoryName = boardFree.getCategory().name();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package com.jakduk.core.model.elasticsearch;

import com.jakduk.core.common.CommonConst;
import com.jakduk.core.model.db.BoardFreeComment;
import com.jakduk.core.model.embedded.BoardItem;
import com.jakduk.core.model.embedded.CommonWriter;
import io.searchbox.annotations.JestId;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.util.Optional;

/**
* @author <a href="mailto:phjang1983@daum.net">Jang,Pyohwan</a>
Expand All @@ -12,7 +18,8 @@
* @desc :
*/

@Data
@Getter
@Setter
public class CommentOnES {

@JestId
Expand All @@ -23,4 +30,16 @@ public class CommentOnES {
private CommonWriter writer;

private String content;

public CommentOnES(BoardFreeComment boardFreeComment) {

String contentES = Optional.ofNullable(boardFreeComment.getContent()).orElse("");
contentES = StringUtils.replacePattern(contentES, CommonConst.REGEX_FIND_HTML_TAG, "");
contentES = StringUtils.replacePattern(contentES, CommonConst.REGEX_FIND_HTML_WHITESPACE, "");

this.id = boardFreeComment.getId();
this.boardItem = boardFreeComment.getBoardItem();
this.writer = boardFreeComment.getWriter();
this.content = contentES;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.jakduk.core.model.elasticsearch;

import com.jakduk.core.model.db.Gallery;
import com.jakduk.core.model.embedded.CommonWriter;
import io.searchbox.annotations.JestId;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
* @author <a href="mailto:phjang1983@daum.net">Jang,Pyohwan</a>
* @company : http://jakduk.com
* @date : 2015. 8. 27.
* @desc :
*/

@Getter
public class GalleryOnES {

@JestId
Expand All @@ -18,33 +25,9 @@ public class GalleryOnES {

private CommonWriter writer;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
public GalleryOnES(Gallery gallery) {
this.id = gallery.getId();
this.name = gallery.getName();
this.writer = gallery.getWriter();
}

public CommonWriter getWriter() {
return writer;
}

public void setWriter(CommonWriter writer) {
this.writer = writer;
}

@Override
public String toString() {
return "GalleryOnES [id=" + id + ", name=" + name + ", writer=" + writer + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import com.jakduk.core.model.db.BoardFree;
import com.jakduk.core.model.db.BoardFreeComment;
import com.jakduk.core.model.db.Gallery;
import com.jakduk.core.model.elasticsearch.BoardFreeOnES;
import com.jakduk.core.model.elasticsearch.CommentOnES;
import com.jakduk.core.model.elasticsearch.GalleryOnES;
import com.jakduk.core.model.embedded.*;
import com.jakduk.core.model.etc.BoardFreeOnBest;
import com.jakduk.core.model.etc.GalleryOnBoard;
Expand All @@ -24,7 +21,6 @@
import com.jakduk.core.repository.BoardFreeRepository;
import com.jakduk.core.repository.GalleryRepository;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
Expand All @@ -33,6 +29,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.time.Instant;
import java.time.LocalDate;
Expand Down Expand Up @@ -137,15 +134,18 @@ public Integer insertFreePost(String subject, String content, CommonConst.BOARD_
GalleryStatus status = updateGallery.getStatus();
List<BoardItem> posts = updateGallery.getPosts();

if (Objects.isNull(posts)) {
if (Objects.isNull(posts))
posts = new ArrayList<>();
}

// 연관된 글이 겹침인지 검사하고, 연관글로 등록한다.
long itemCount = 0;

if (! posts.isEmpty())
itemCount = posts.stream().filter(item -> item.getId().equals(boardItem.getId())).count();
if (! posts.isEmpty()) {
itemCount = posts.stream()
.filter(item -> item.getId().equals(boardItem.getId()))
.count();
}


if (itemCount == 0) {
posts.add(boardItem);
Expand All @@ -163,33 +163,11 @@ public Integer insertFreePost(String subject, String content, CommonConst.BOARD_
updateGallery.setStatus(status);
galleryRepository.save(updateGallery);

// 엘라스틱 서치 gallery 도큐먼트 생성을 위한 객체.
GalleryOnES galleryOnES = new GalleryOnES();
galleryOnES.setId(updateGallery.getId());
galleryOnES.setWriter(updateGallery.getWriter());
galleryOnES.setName(updateGallery.getName());

searchService.createDocumentGallery(galleryOnES);
searchService.createDocumentGallery(updateGallery);
}
}

// 엘라스틱 서치 도큐먼트 생성을 위한 객체.

BoardFreeOnES boardFreeOnEs = new BoardFreeOnES();
boardFreeOnEs.setId(boardFree.getId());
boardFreeOnEs.setSeq(boardFree.getSeq());
boardFreeOnEs.setWriter(boardFree.getWriter());
boardFreeOnEs.setCategoryName(boardFree.getCategory().toString());

String subjectEL = Optional.ofNullable(boardFree.getSubject()).orElse("");
subjectEL = StringUtils.replacePattern(subjectEL, CommonConst.REGEX_FIND_HTML_TAG, "");
boardFree.setSubject(StringUtils.replacePattern(subjectEL, CommonConst.REGEX_FIND_HTML_WHITESPACE, ""));

String contentEL = Optional.ofNullable(boardFree.getContent()).orElse("");
contentEL = StringUtils.replacePattern(contentEL, CommonConst.REGEX_FIND_HTML_TAG, "");
boardFree.setContent(StringUtils.replacePattern(contentEL, CommonConst.REGEX_FIND_HTML_WHITESPACE, ""));

searchService.createDocumentBoard(boardFreeOnEs);
searchService.createDocumentBoard(boardFree);


/*
Expand Down Expand Up @@ -305,33 +283,12 @@ public Integer updateFreePost(Integer seq, String subject, String content, Commo
updateGallery.setStatus(status);
galleryRepository.save(updateGallery);

// 엘라스틱 서치 gallery 도큐먼트 생성을 위한 객체.
GalleryOnES galleryOnES = new GalleryOnES();
galleryOnES.setId(galleryOnBoard.getId());
galleryOnES.setWriter(updateGallery.getWriter());
galleryOnES.setName(galleryOnBoard.getName());

searchService.createDocumentGallery(galleryOnES);
searchService.createDocumentGallery(updateGallery);
}

}

// 엘라스틱 서치 도큐먼트 생성을 위한 객체.
BoardFreeOnES boardFreeOnEs = new BoardFreeOnES();
boardFreeOnEs.setId(boardFree.getId());
boardFreeOnEs.setSeq(boardFree.getSeq());
boardFreeOnEs.setWriter(boardFree.getWriter());
boardFreeOnEs.setCategoryName(boardFree.getCategory().toString());

String subjectEL = Optional.ofNullable(boardFree.getSubject()).orElse("");
subjectEL = StringUtils.replacePattern(subjectEL, CommonConst.REGEX_FIND_HTML_TAG, "");
boardFree.setSubject(StringUtils.replacePattern(subjectEL, CommonConst.REGEX_FIND_HTML_WHITESPACE, ""));

String contentEL = Optional.ofNullable(boardFree.getContent()).orElse("");
contentEL = StringUtils.replacePattern(contentEL, CommonConst.REGEX_FIND_HTML_TAG, "");
boardFree.setContent(StringUtils.replacePattern(contentEL, CommonConst.REGEX_FIND_HTML_WHITESPACE, ""));

searchService.createDocumentBoard(boardFreeOnEs);
searchService.createDocumentBoard(boardFree);

if (log.isInfoEnabled()) {
log.info("post was edited. post seq=" + boardFree.getSeq() + ", subject=" + boardFree.getSubject());
Expand Down Expand Up @@ -535,28 +492,17 @@ public BoardFreeComment addFreeComment(Integer seq, String contents, CommonConst

boardFreeCommentRepository.save(boardFreeComment);

// 엘라스틱 서치 도큐먼트 생성을 위한 객체.
CommentOnES commentOnES = new CommentOnES();
commentOnES.setId(boardFreeComment.getId());
commentOnES.setWriter(boardFreeComment.getWriter());
commentOnES.setBoardItem(boardFreeComment.getBoardItem());

String contentES = Optional.ofNullable(contents).orElse("");
contentES = StringUtils.replacePattern(contentES, CommonConst.REGEX_FIND_HTML_TAG, "");
commentOnES.setContent(StringUtils.replacePattern(contentES, CommonConst.REGEX_FIND_HTML_WHITESPACE, ""));

searchService.createDocumentComment(commentOnES);
searchService.createDocumentComment(boardFreeComment);

return boardFreeComment;
}

// 게시판 댓글 목록
public List<BoardFreeComment> getFreeComments(Integer seq, String commentId) {
BoardFreeOfMinimum boardFreeOnComment = boardFreeRepository.findBoardFreeOfMinimumBySeq(seq);

List<BoardFreeComment> comments;

if (commentId != null && !commentId.isEmpty()) {
if (! ObjectUtils.isEmpty(commentId)) {
comments = boardDAO.getBoardFreeComment(seq, new ObjectId(commentId));
} else {
comments = boardDAO.getBoardFreeComment(seq, null);
Expand Down
Loading