use of com.github.lybgeek.shorturl.dto.ShortUrlDTO in project springboot-learning by lyb-geek.
the class CustomShortUrlEsServiceImpl method pageShortUrl.
@Override
public PageResult<ShortUrlDTO> pageShortUrl(PageQuery<ShortUrlDTO> pageQuery) {
int pageNo = ObjectUtils.isNotEmpty(pageQuery.getPageNo()) && pageQuery.getPageNo() > 0 ? pageQuery.getPageNo() : 1;
int pageSize = ObjectUtils.isNotEmpty(pageQuery.getPageSize()) ? pageQuery.getPageSize() : 10;
ShortUrlDTO queryParams = pageQuery.getQueryParams();
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
int from = (pageNo - 1) * pageSize;
searchSourceBuilder.from(from).size(pageSize).sort("id", SortOrder.DESC);
if (ObjectUtils.isNotEmpty(queryParams)) {
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);
}
searchSourceBuilder.query(boolBuilder);
// 设置高亮
HighlightBuilder highlightBuilder = new HighlightBuilder();
HighlightBuilder.Field highlightUrlName = new HighlightBuilder.Field("urlName").preTags("<strong>").postTags("</strong>");
highlightUrlName.highlighterType("unified");
highlightBuilder.field(highlightUrlName);
searchSourceBuilder.highlighter(highlightBuilder);
}
}
PageResult<ShortUrlDTO> pageResult = elasticsearchHelper.pageSearch(ElasticsearchConstant.SHORT_URL_INDEX, searchSourceBuilder, ShortUrlDTO.class);
return pageResult;
}
use of com.github.lybgeek.shorturl.dto.ShortUrlDTO 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.shorturl.dto.ShortUrlDTO in project springboot-learning by lyb-geek.
the class ElasticsearchApplicationTest method testListCustomShortUrls.
@Test
public void testListCustomShortUrls() {
ShortUrlDTO dto = new ShortUrlDTO();
dto.setUrlName("美团");
// dto.setRemark("门户");
List<ShortUrlDTO> shortUrlDTOS = customShortUrlEsService.listShortUrls(dto);
System.out.println(shortUrlDTOS);
}
use of com.github.lybgeek.shorturl.dto.ShortUrlDTO in project springboot-learning by lyb-geek.
the class ElasticsearchApplicationTest method testPage.
@Test
public void testPage() {
PageQuery pageQuery = new PageQuery<>().setPageNo(1).setPageSize(5);
ShortUrlDTO dto = new ShortUrlDTO();
dto.setUrlName("门户");
// dto.setRemark("门户");
pageQuery.setQueryParams(dto);
PageResult<ShortUrlDTO> pageResult = shortUrlService.pageShortUrl(pageQuery);
System.out.println(pageResult);
}
use of com.github.lybgeek.shorturl.dto.ShortUrlDTO in project springboot-learning by lyb-geek.
the class ElasticsearchApplicationTest method testCustomPageShortUrl.
@Test
public void testCustomPageShortUrl() {
PageQuery pageQuery = new PageQuery<>().setPageNo(5).setPageSize(5);
ShortUrlDTO dto = new ShortUrlDTO();
// dto.setUrlName("优酷");
// dto.setRemark("视频");
// pageQuery.setQueryParams(dto);
PageResult<ShortUrlDTO> pageResult = customShortUrlEsService.pageShortUrl(pageQuery);
System.out.println(pageResult);
}
Aggregations