|
|
|
@ -1,8 +1,11 @@
|
|
|
|
|
package com.luoo.music.service;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
import net.oschina.j2cache.CacheChannel;
|
|
|
|
@ -16,6 +19,9 @@ public class SearchService {
|
|
|
|
|
public List<String> autoComplete(String query, int limit) {
|
|
|
|
|
List<String> values = (List<String>) cacheChannel.get(Constants.J2CACHE_REGION_SEARCH_AUTO_COMPLETE, query)
|
|
|
|
|
.getValue();
|
|
|
|
|
if (CollectionUtils.isEmpty(values)) {
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
return limit < values.size() ? values.subList(0, limit) : values;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|