use of com.github.lybgeek.elasticsearch.model.ShortUrlVO in project springboot-learning by lyb-geek.
the class ShortUrlEsServiceImpl method pageShortUrl.
@Override
public PageResult<ShortUrlVO> pageShortUrl(PageQuery<ShortUrlDTO> pageQuery) {
int pageNo = ObjectUtils.isNotEmpty(pageQuery.getPageNo()) ? pageQuery.getPageNo() - 1 : 0;
int pageSize = ObjectUtils.isNotEmpty(pageQuery.getPageSize()) ? pageQuery.getPageSize() : 10;
Sort sort = new Sort(Direction.DESC, "id");
Pageable pageable = PageRequest.of(pageNo, pageSize, sort);
ShortUrlDTO queryParams = pageQuery.getQueryParams();
BoolQueryBuilder boolBuilder = QueryBuilders.boolQuery();
if (queryParams != null) {
if (StringUtils.isNotBlank(queryParams.getLongUrl())) {
QueryBuilder builder = QueryBuilders.matchQuery("longUrl", queryParams.getLongUrl());
boolBuilder.must(builder);
}
if (StringUtils.isNotBlank(queryParams.getRemark())) {
QueryBuilder builder = QueryBuilders.matchQuery("remark", queryParams.getRemark());
boolBuilder.must(builder);
}
if (StringUtils.isNotBlank(queryParams.getUrlName())) {
QueryBuilder builder = QueryBuilders.matchQuery("urlName", queryParams.getUrlName());
boolBuilder.must(builder);
}
}
Page<ShortUrlVO> page = shortUrlEsRepository.search(boolBuilder, pageable);
return PageUtil.INSTANCE.getPage(page, page.getContent());
}
use of com.github.lybgeek.elasticsearch.model.ShortUrlVO in project springboot-learning by lyb-geek.
the class ElasticsearchApplicationTest method testSaveShortUrlEs.
@Test
public void testSaveShortUrlEs() {
ShortUrlDTO shortUrlDTO = ShortUrlDTO.builder().longUrl("https://www.baidu.com").urlName("百度").remark("百度一下,你就知道").build();
ShortUrlVO shortUrlVO = shortUrlEsService.save(shortUrlDTO);
Assert.assertNotNull(shortUrlVO);
System.out.println(shortUrlVO);
}
Aggregations