|
@@ -43,6 +43,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
private final ContentPermission contentPermission;
|
|
private final ContentPermission contentPermission;
|
|
|
private final RedisString redisString;
|
|
private final RedisString redisString;
|
|
|
private final VideoPostQuery videoPostQuery;
|
|
private final VideoPostQuery videoPostQuery;
|
|
|
|
|
+ private boolean mysqlSearch = false;
|
|
|
|
|
|
|
|
public SearchServiceImpl(VideoPostMapper videoPostMapper, SearchRecordMapper searchRecordMapper,
|
|
public SearchServiceImpl(VideoPostMapper videoPostMapper, SearchRecordMapper searchRecordMapper,
|
|
|
ContentPermission contentPermission, RedisString redisString,
|
|
ContentPermission contentPermission, RedisString redisString,
|
|
@@ -62,23 +63,23 @@ public class SearchServiceImpl implements SearchService {
|
|
|
* @date 2021-12-08 下午7:06
|
|
* @date 2021-12-08 下午7:06
|
|
|
*/
|
|
*/
|
|
|
public List<SuggestKeyword> suggestKeyword(String keyword) {
|
|
public List<SuggestKeyword> suggestKeyword(String keyword) {
|
|
|
- return searchRecordMapper.findSuggestKeyword(keyword);
|
|
|
|
|
|
|
+ List<SuggestKeyword> list = searchRecordMapper.findSuggestKeyword(keyword);
|
|
|
|
|
+ return list;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public PageList<VideoCard> searchByKeyword(String keyword, String nextIdStr, int pageNumber) {
|
|
public PageList<VideoCard> searchByKeyword(String keyword, String nextIdStr, int pageNumber) {
|
|
|
- int type = 2;
|
|
|
|
|
|
|
+ processKeywordAsync(keyword);
|
|
|
PageList<VideoCard> pageList;
|
|
PageList<VideoCard> pageList;
|
|
|
- if (type == 1) {
|
|
|
|
|
- pageList = searchByKeyword1(keyword, nextIdStr, pageNumber);
|
|
|
|
|
|
|
+ if (mysqlSearch) {
|
|
|
|
|
+ pageList = searchKeywordInMySql(keyword, pageNumber);
|
|
|
} else {
|
|
} else {
|
|
|
- pageList = searchByKeyword2(keyword, pageNumber);
|
|
|
|
|
|
|
+ pageList = searchKeywordInLucene(keyword, pageNumber);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return pageList;
|
|
return pageList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public PageList<VideoCard> searchByKeyword1(String keyword, String nextIdStr, int pageNumber) {
|
|
|
|
|
- //processKeywordAsync(keyword);
|
|
|
|
|
|
|
+ public PageList<VideoCard> searchKeywordInMySql(String keyword, int pageNumber) {
|
|
|
List<Integer> scopes = contentPermission.getUserScopes();
|
|
List<Integer> scopes = contentPermission.getUserScopes();
|
|
|
SearchCriteria searchCriteria = new SearchCriteria.Builder().scope(scopes).title(keyword).build();
|
|
SearchCriteria searchCriteria = new SearchCriteria.Builder().scope(scopes).title(keyword).build();
|
|
|
int total = videoPostMapper.countBySearchCriteria(searchCriteria);
|
|
int total = videoPostMapper.countBySearchCriteria(searchCriteria);
|
|
@@ -96,7 +97,7 @@ public class SearchServiceImpl implements SearchService {
|
|
|
return PageList.pageList(pageNumber, pageSize, total, list1);
|
|
return PageList.pageList(pageNumber, pageSize, total, list1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public PageList<VideoCard> searchByKeyword2(String keyword, int pageNumber) {
|
|
|
|
|
|
|
+ public PageList<VideoCard> searchKeywordInLucene(String keyword, int pageNumber) {
|
|
|
long loginUser = UserContext.getUser();
|
|
long loginUser = UserContext.getUser();
|
|
|
List<Integer> userScopes = contentPermission.getUserScopes(loginUser);
|
|
List<Integer> userScopes = contentPermission.getUserScopes(loginUser);
|
|
|
PageList<VideoSummary> pageList = dataSearchService.searchVideo(keyword, userScopes, pageNumber);
|
|
PageList<VideoSummary> pageList = dataSearchService.searchVideo(keyword, userScopes, pageNumber);
|
|
@@ -121,11 +122,12 @@ public class SearchServiceImpl implements SearchService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void processKeywordAsync(String keyword) {
|
|
private void processKeywordAsync(String keyword) {
|
|
|
- int total = getTotal(keyword);
|
|
|
|
|
|
|
+ saveKeyword(keyword);
|
|
|
|
|
+ /*int total = getTotal(keyword);
|
|
|
if (total == 0) {
|
|
if (total == 0) {
|
|
|
saveKeyword(keyword);
|
|
saveKeyword(keyword);
|
|
|
setTotal(keyword, total);
|
|
setTotal(keyword, total);
|
|
|
- }
|
|
|
|
|
|
|
+ }*/
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private int getTotal(String keyword) {
|
|
private int getTotal(String keyword) {
|
|
@@ -140,11 +142,11 @@ public class SearchServiceImpl implements SearchService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void saveKeyword(String keyword) {
|
|
private void saveKeyword(String keyword) {
|
|
|
- long userId = UserContext.getUser();
|
|
|
|
|
- searchRecordMapper.save(new SearchRecord(userId, keyword));
|
|
|
|
|
|
|
+ searchRecordMapper.save(new SearchRecord(keyword));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public List<HotSearch> getHotSearch() {
|
|
public List<HotSearch> getHotSearch() {
|
|
|
- return searchRecordMapper.findHotSearch();
|
|
|
|
|
|
|
+ List<HotSearch> list = searchRecordMapper.findHotSearch();
|
|
|
|
|
+ return list;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|