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 @@ -21,6 +21,8 @@
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import software.amazon.awssdk.services.s3.endpoints.internal.Value;

import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -150,4 +152,12 @@ public ApiResponse<List<Suggestion>> searchPlaceComplete(
) {
return ApiResponse.success(Success.SEARCH_COMPLETE_SUCCESS, placeAutoCompleteService.suggest(query));
}

@PostMapping("/search/autocomplete")
public ApiResponse<?> recordAutocompleteSelection(
@RequestParam String word
) {
placeAutoCompleteService.recordAutocompleteSelection(word);
return ApiResponse.success(Success.INCREASE_AUTOCOMPLETE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
package Journey.Together.domain.place.service;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.redis.connection.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.connection.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.core.RedisCallback;

import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -115,10 +102,13 @@ public List<Suggestion> suggest(String prefix) {
return paired.size() > LIMIT ? paired.subList(0, LIMIT) : paired;
}

/** 사용자가 항목을 선택했을 때 인기 점수 증가 */
public double recordSelection(String word, double inc) {
if (word == null || word.isBlank()) return 0.0;
Double v = redis.opsForZSet().incrementScore(SCORE_KEY, word, inc);
return v == null ? 0.0 : v;
/**
* 사용자가 항목을 선택했을 때 인기 점수 증가
*/
public void recordAutocompleteSelection(String word) {
String w = (word == null) ? null : word.trim();
if (w == null || w.isEmpty()) return;
redis.opsForZSet().incrementScore(SCORE_KEY, w, 0.1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public enum Success {
UPDATE_MY_PLACE_REVIEW_SUCCESS(HttpStatus.OK, "나의 여행지 후기 수정 성공"),
SEARCH_SUCCESS(HttpStatus.OK, "검색 성공"),
SEARCH_COMPLETE_SUCCESS(HttpStatus.OK, "검색어 자동완성 성공"),
INCREASE_AUTOCOMPLETE_SUCCESS(HttpStatus.OK, "자동완성 검색어 인기도 증가"),
SEARCH_PLACE_LIST_SUCCESS(HttpStatus.OK, "여행지 검색 성공"),
PARSING_OG_SUCCESS(HttpStatus.OK, "og 데이터 파싱 결과입니다. 크롤링을 막은 페이지는 기본이미지가 나옵니다."),
UPDATE_PUSH_ALLOWED_SUCCESS(HttpStatus.OK, "푸시알림 수정 성공"),
Expand Down