Skip to content
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 @@ -31,7 +31,7 @@ Optional<ArticleKeyword> findByKeywordAndCategoryIncludingDeleted(

Optional<ArticleKeyword> findById(Integer id);

List<ArticleKeyword> findAllByCategory(KeywordCategory category, Pageable pageable);
List<ArticleKeyword> findAllByCategory(KeywordCategory category);

@Query("""
SELECT new in.koreatech.koin.domain.community.article.dto.ArticleKeywordResult(k.id, k.keyword, COUNT(u))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.ArrayList;
import java.util.List;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -18,27 +16,16 @@
@Transactional(readOnly = true)
public class KeywordExtractor {

private static final int KEYWORD_BATCH_SIZE = 100;

private final ArticleKeywordRepository articleKeywordRepository;

public List<String> matchKeywords(String title, KeywordCategory category) {
List<String> matchedKeywords = new ArrayList<>();
int offset = 0;

while (true) {
Pageable pageable = PageRequest.of(offset / KEYWORD_BATCH_SIZE, KEYWORD_BATCH_SIZE);
List<ArticleKeyword> keywords = articleKeywordRepository.findAllByCategory(category, pageable);
List<ArticleKeyword> keywords = articleKeywordRepository.findAllByCategory(category);

if (keywords.isEmpty()) {
break;
}
for (ArticleKeyword keyword : keywords) {
if (title.contains(keyword.getKeyword())) {
matchedKeywords.add(keyword.getKeyword());
}
for (ArticleKeyword keyword : keywords) {
if (title.contains(keyword.getKeyword())) {
matchedKeywords.add(keyword.getKeyword());
}
offset += KEYWORD_BATCH_SIZE;
}

return matchedKeywords;
Expand Down
Loading