com.github.wz2cool.elasticsearch.query.LogicPagingQuery Maven / Gradle / Ivy
package com.github.wz2cool.elasticsearch.query;
import com.github.wz2cool.elasticsearch.cache.EntityCache;
import com.github.wz2cool.elasticsearch.core.HighlightResultMapper;
import com.github.wz2cool.elasticsearch.helper.CommonsHelper;
import com.github.wz2cool.elasticsearch.lambda.GetLongPropertyFunction;
import com.github.wz2cool.elasticsearch.lambda.GetPropertyFunction;
import com.github.wz2cool.elasticsearch.model.ColumnInfo;
import com.github.wz2cool.elasticsearch.model.PropertyInfo;
import com.github.wz2cool.elasticsearch.model.QueryMode;
import com.github.wz2cool.elasticsearch.model.UpDown;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
import org.elasticsearch.search.sort.SortOrder;
import java.util.function.BiConsumer;
public class LogicPagingQuery extends BaseFilterGroup> {
private final Class clazz;
private final UpDown upDown;
private final SortOrder sortOrder;
private final GetLongPropertyFunction pagingPropertyFunc;
private QueryBuilder queryBuilder;
private int pageSize = 10;
private Long lastStartPageId;
private Long lastEndPageId;
private HighlightResultMapper highlightResultMapper = new HighlightResultMapper();
private HighlightBuilder highlightBuilder = new HighlightBuilder();
private final QueryMode queryMode;
private LogicPagingQuery(Class clazz, GetLongPropertyFunction pagingPropertyFunc, SortOrder sortOrder, UpDown upDown) {
this(clazz, QueryMode.QUERY, pagingPropertyFunc, sortOrder, upDown);
}
private LogicPagingQuery(Class clazz, QueryMode queryMode, GetLongPropertyFunction pagingPropertyFunc, SortOrder sortOrder, UpDown upDown) {
this.clazz = clazz;
this.upDown = upDown;
this.sortOrder = sortOrder;
this.pagingPropertyFunc = pagingPropertyFunc;
this.queryMode = queryMode;
}
public static LogicPagingQuery createQuery(
Class clazz, GetLongPropertyFunction pagingPropertyFunc, SortOrder sortOrder, UpDown upDown) {
return new LogicPagingQuery<>(clazz, pagingPropertyFunc, sortOrder, upDown);
}
public static LogicPagingQuery createQuery(
Class clazz, QueryMode queryMode, GetLongPropertyFunction pagingPropertyFunc, SortOrder sortOrder, UpDown upDown) {
return new LogicPagingQuery<>(clazz, queryMode, pagingPropertyFunc, sortOrder, upDown);
}
public LogicPagingQuery scoreMapping(BiConsumer setScorePropertyFunc) {
highlightResultMapper.registerScoreMapping(this.clazz, setScorePropertyFunc);
return this;
}
public LogicPagingQuery highlightMapping(GetPropertyFunction getSearchPropertyFunc,
BiConsumer setHighLightPropertyFunc) {
PropertyInfo propertyInfo = CommonsHelper.getPropertyInfo(getSearchPropertyFunc);
ColumnInfo columnInfo = EntityCache.getInstance().getColumnInfo(propertyInfo.getOwnerClass(), propertyInfo.getPropertyName());
highlightBuilder.field(columnInfo.getColumnName());
highlightResultMapper.registerHitMapping(this.clazz, getSearchPropertyFunc, setHighLightPropertyFunc);
return this;
}
public QueryBuilder getQueryBuilder() {
return queryBuilder != null ? queryBuilder : buildQuery();
}
public void setQueryBuilder(QueryBuilder queryBuilder) {
this.queryBuilder = queryBuilder;
}
public Class getClazz() {
return clazz;
}
public UpDown getUpDown() {
return upDown;
}
public SortOrder getSortOrder() {
return sortOrder;
}
public GetLongPropertyFunction getPagingPropertyFunc() {
return pagingPropertyFunc;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public Long getLastStartPageId() {
return lastStartPageId;
}
public void setLastStartPageId(Long lastStartPageId) {
this.lastStartPageId = lastStartPageId;
}
public Long getLastEndPageId() {
return lastEndPageId;
}
public void setLastEndPageId(Long lastEndPageId) {
this.lastEndPageId = lastEndPageId;
}
public HighlightResultMapper getHighlightResultMapper() {
return highlightResultMapper;
}
public void setHighlightResultMapper(HighlightResultMapper highlightResultMapper) {
this.highlightResultMapper = highlightResultMapper;
}
public HighlightBuilder getHighlightBuilder() {
return highlightBuilder;
}
public void setHighlightBuilder(HighlightBuilder highlightBuilder) {
this.highlightBuilder = highlightBuilder;
}
public QueryMode getQueryMode() {
return queryMode;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy