mirror of
https://github.com/JeffLi1993/springboot-learning-example.git
synced 2026-03-13 13:33:44 +08:00
spring-data-elasticsearch - 实战案例详解
This commit is contained in:
@@ -14,53 +14,5 @@ import java.util.List;
|
||||
* Created by bysocket on 20/06/2017.
|
||||
*/
|
||||
public interface CityRepository extends ElasticsearchRepository<City, Long> {
|
||||
/**
|
||||
* AND 语句查询
|
||||
*
|
||||
* @param description
|
||||
* @param score
|
||||
* @return
|
||||
*/
|
||||
List<City> findByDescriptionAndScore(String description, Integer score);
|
||||
|
||||
/**
|
||||
* OR 语句查询
|
||||
*
|
||||
* @param description
|
||||
* @param score
|
||||
* @return
|
||||
*/
|
||||
List<City> findByDescriptionOrScore(String description, Integer score);
|
||||
|
||||
/**
|
||||
* 查询城市描述
|
||||
*
|
||||
* 等同于下面代码
|
||||
* @Query("{\"bool\" : {\"must\" : {\"term\" : {\"description\" : \"?0\"}}}}")
|
||||
* Page<City> findByDescription(String description, Pageable pageable);
|
||||
*
|
||||
* @param description
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
Page<City> findByDescription(String description, Pageable page);
|
||||
|
||||
/**
|
||||
* NOT 语句查询
|
||||
*
|
||||
* @param description
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
Page<City> findByDescriptionNot(String description, Pageable page);
|
||||
|
||||
/**
|
||||
* LIKE 语句查询
|
||||
*
|
||||
* @param description
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
Page<City> findByDescriptionLike(String description, Pageable page);
|
||||
|
||||
}
|
||||
|
||||
@@ -29,15 +29,15 @@ public class CityESServiceImpl implements CityService {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CityESServiceImpl.class);
|
||||
|
||||
/* 分页参数 */
|
||||
Integer PAGE_SIZE = 12; // 每页数量
|
||||
Integer PAGE_SIZE = 12; // 每页数量
|
||||
Integer DEFAULT_PAGE_NUMBER = 0; // 默认当前页码
|
||||
|
||||
/* 搜索模式 */
|
||||
String SCORE_MODE_SUM = "sum"; // 权重分求和模式
|
||||
Float MIN_SCORE = 10.0F; // 由于无相关性的分值默认为 1 ,设置权重分最小值为 10
|
||||
Float MIN_SCORE = 10.0F; // 由于无相关性的分值默认为 1 ,设置权重分最小值为 10
|
||||
|
||||
@Autowired
|
||||
CityRepository cityRepository;// ES 操作类
|
||||
CityRepository cityRepository; // ES 操作类
|
||||
|
||||
public Long saveCity(City city) {
|
||||
City cityResult = cityRepository.save(city);
|
||||
|
||||
Reference in New Issue
Block a user