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

Unify search results when we get the same article many times(#1064) #1110

Open
wants to merge 1 commit into
base: v1
Choose a base branch
from
Open
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 @@ -771,11 +771,15 @@ private List<KnowledgesEntity> getKnowledgeDatas(List<SearchResultValue> list) {
LOG.trace("ナレッジ情報取得完了");

List<KnowledgesEntity> knowledges = new ArrayList<>();
Map<Long, Long> knowledgeIdToList = new HashMap<Long, Long>();

for (SearchResultValue searchResultValue : list) {
KnowledgesEntity entity = null;

if (searchResultValue.getType() == TYPE_KNOWLEDGE) {
Long key = new Long(searchResultValue.getId());
if (map.containsKey(key)) {
KnowledgesEntity entity = map.get(key);
entity = map.get(key);
if (StringUtils.isNotEmpty(searchResultValue.getHighlightedTitle())) {
entity.setTitle(searchResultValue.getHighlightedTitle());
}
Expand All @@ -787,17 +791,15 @@ private List<KnowledgesEntity> getKnowledgeDatas(List<SearchResultValue> list) {
// entity.setContent(org.apache.commons.lang.StringUtils.abbreviate(entity.getContent(),
// LuceneSearcher.CONTENTS_LIMIT_LENGTH));
}

entity.setScore(searchResultValue.getScore());
knowledges.add(entity);
}
} else if (searchResultValue.getType() == TYPE_FILE) {
// TODO 1件づつ処理しているので、パフォーマンスが悪いので後で処理を検討
String id = searchResultValue.getId().substring(FileParseBat.ID_PREFIX.length());
Long fileNo = new Long(id);
KnowledgeFilesEntity filesEntity = filesDao.selectOnKeyWithoutBinary(fileNo);
if (filesEntity != null && filesEntity.getKnowledgeId() != null) {
KnowledgesEntity entity = knowledgesDao.selectOnKeyWithUserName(filesEntity.getKnowledgeId());
entity = knowledgesDao.selectOnKeyWithUserName(filesEntity.getKnowledgeId());
if (entity == null) {
// 添付ファイルの情報が検索エンジン内にあり、検索にHitしたが、それに紐づくナレッジデータは削除されていた
break;
Expand All @@ -818,15 +820,14 @@ private List<KnowledgesEntity> getKnowledgeDatas(List<SearchResultValue> list) {
}
entity.setContent(builder.toString());
entity.setScore(searchResultValue.getScore());
knowledges.add(entity);
}
} else if (searchResultValue.getType() == TYPE_COMMENT) {
// TODO 1件づつ処理しているので、パフォーマンスが悪いので後で処理を検討
String id = searchResultValue.getId().substring(COMMENT_ID_PREFIX.length());
Long commentNo = new Long(id);
CommentsEntity commentsEntity = CommentsDao.get().selectOnKey(commentNo);
if (commentsEntity != null && commentsEntity.getKnowledgeId() != null) {
KnowledgesEntity entity = knowledgesDao.selectOnKeyWithUserName(commentsEntity.getKnowledgeId());
entity = knowledgesDao.selectOnKeyWithUserName(commentsEntity.getKnowledgeId());
if (entity == null) {
// コメントの情報が検索エンジン内にあり、検索にHitしたが、それに紐づくナレッジデータは削除されていた
break;
Expand All @@ -840,13 +841,12 @@ private List<KnowledgesEntity> getKnowledgeDatas(List<SearchResultValue> list) {
}
entity.setContent(builder.toString());
entity.setScore(searchResultValue.getScore());
knowledges.add(entity);
}
} else if (searchResultValue.getType() == IndexType.bookmarkContent.getValue()) {
// TODO 1件づつ処理しているので、パフォーマンスが悪いので後で処理を検討
String id = searchResultValue.getId().substring(FileParseBat.WEB_ID_PREFIX.length());
Long knowledgeId = new Long(id);
KnowledgesEntity entity = knowledgesDao.selectOnKeyWithUserName(knowledgeId);
entity = knowledgesDao.selectOnKeyWithUserName(knowledgeId);
if (entity != null && entity.getKnowledgeId() != null) {
StringBuilder builder = new StringBuilder();
builder.append("[Bookmark Content] ");
Expand All @@ -859,9 +859,20 @@ private List<KnowledgesEntity> getKnowledgeDatas(List<SearchResultValue> list) {
}
entity.setContent(builder.toString());
entity.setScore(searchResultValue.getScore());
knowledges.add(entity);
}
}

if(entity == null) continue;

if(knowledgeIdToList.containsKey(entity.getKnowledgeId())) {
int listId = knowledgeIdToList.get(entity.getKnowledgeId()).intValue();
KnowledgesEntity updateEntity = knowledges.get(listId);
String content = updateEntity.getContent();
updateEntity.setContent(content + entity.getContent());
} else {
knowledges.add(entity);
knowledgeIdToList.put(entity.getKnowledgeId(), new Long(knowledges.size() - 1));
}
}

// 以下の付加情報は、ナレッジテーブルに持ち各テーブルに再取得しない
Expand Down