Skip to content

Commit

Permalink
Merge pull request #34 from sen2y/feature/seny
Browse files Browse the repository at this point in the history
Feature/seny
  • Loading branch information
sen2y authored Jul 7, 2024
2 parents 347a1ea + b0daccd commit f38ee50
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/routes/word/word.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports.getSearchWords = async (req, res) => {
// 검색어 검증
const validData = validateRequest(searchTermSchema, req.params);
// 요청 파라미터에서 검색어 추출
const searchTerm = validData.searchTerm;
let searchTerm = validData.searchTerm;
// 검색어 조회
const data = await wordService.getSearchWords(searchTerm);
if (_id) {
Expand Down
5 changes: 3 additions & 2 deletions src/routes/word/word.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ const Word = require('./word.model');
exports.getSearchWords = async (searchTerm) => {
try {
// 대소문자 구분 없이 검색어를 찾기 위한 정규 표현식 사용
const searchWords = await Word.findOne({ word: new RegExp(`^${searchTerm}$`, 'i') });
const escapedSearchTerm = searchTerm.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
const searchWords = await Word.findOne({ word: { $regex: `^${escapedSearchTerm}$`, $options: 'i' } });

if (!searchWords) {
console.log('Search term not found in Word collection');
}

console.log(888, searchWords);
return searchWords;
} catch (error) {
console.log('Error while getting search words:', error);
Expand Down

0 comments on commit f38ee50

Please sign in to comment.