|
@@ -18,23 +18,17 @@ package org.codelibs.fess.service;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
-import org.codelibs.core.beans.util.BeanUtil;
|
|
|
-import org.codelibs.fess.client.FessEsClient;
|
|
|
import org.codelibs.fess.crud.CommonConstants;
|
|
|
import org.codelibs.fess.crud.CrudMessageException;
|
|
|
-import org.codelibs.fess.entity.BoostDocumentRule;
|
|
|
-import org.codelibs.fess.helper.FieldHelper;
|
|
|
+import org.codelibs.fess.es.cbean.BoostDocumentRuleCB;
|
|
|
+import org.codelibs.fess.es.exbhv.BoostDocumentRuleBhv;
|
|
|
+import org.codelibs.fess.es.exentity.BoostDocumentRule;
|
|
|
import org.codelibs.fess.pager.BoostDocumentRulePager;
|
|
|
import org.dbflute.cbean.result.PagingResultBean;
|
|
|
-import org.elasticsearch.action.search.SearchResponse;
|
|
|
-import org.elasticsearch.index.query.QueryBuilders;
|
|
|
-import org.elasticsearch.search.SearchHit;
|
|
|
-import org.elasticsearch.search.SearchHits;
|
|
|
-import org.elasticsearch.search.sort.SortBuilders;
|
|
|
-import org.elasticsearch.search.sort.SortOrder;
|
|
|
import org.seasar.framework.beans.util.Beans;
|
|
|
|
|
|
public class BoostDocumentRuleService implements Serializable {
|
|
@@ -42,47 +36,18 @@ public class BoostDocumentRuleService implements Serializable {
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
@Resource
|
|
|
- protected FessEsClient fessEsClient;
|
|
|
+ protected BoostDocumentRuleBhv boostDocumentRuleBhv;
|
|
|
|
|
|
- @Resource
|
|
|
- protected FieldHelper fieldHelper;
|
|
|
+ public BoostDocumentRuleService() {
|
|
|
+ super();
|
|
|
+ }
|
|
|
|
|
|
public List<BoostDocumentRule> getBoostDocumentRuleList(final BoostDocumentRulePager boostDocumentRulePager) {
|
|
|
- final PagingResultBean<BoostDocumentRule> boostDocumentRuleList =
|
|
|
- fessEsClient.search(getIndex(), getType(), searchRequestBuilder -> {
|
|
|
- if (boostDocumentRulePager.id != null) {
|
|
|
- searchRequestBuilder.setQuery(QueryBuilders.idsQuery(getType()).addIds(boostDocumentRulePager.id));
|
|
|
- }
|
|
|
- searchRequestBuilder.addSort(SortBuilders.fieldSort("sortOrder").order(SortOrder.ASC));
|
|
|
- searchRequestBuilder.setVersion(true);
|
|
|
-
|
|
|
- final int size = boostDocumentRulePager.getPageSize();
|
|
|
- final int pageNum = boostDocumentRulePager.getCurrentPageNumber();
|
|
|
- // TODO modify size/pageNum
|
|
|
- searchRequestBuilder.setFrom(size * (pageNum - 1));
|
|
|
- searchRequestBuilder.setSize(size);
|
|
|
- return true;
|
|
|
- }, (searchRequestBuilder, execTime, searchResponse) -> {
|
|
|
- return searchResponse.map(response -> {
|
|
|
- final PagingResultBean<BoostDocumentRule> list = new PagingResultBean<>();
|
|
|
- list.setTableDbName(getType());
|
|
|
- final SearchHits searchHits = response.getHits();
|
|
|
- searchHits.forEach(hit -> {
|
|
|
- list.add(createEntity(response, hit));
|
|
|
- });
|
|
|
- list.setAllRecordCount((int) searchHits.totalHits());
|
|
|
- list.setPageSize(boostDocumentRulePager.getPageSize());
|
|
|
- list.setCurrentPageNumber(boostDocumentRulePager.getCurrentPageNumber());
|
|
|
- return list;
|
|
|
- }).orElseGet(() -> {
|
|
|
- final PagingResultBean<BoostDocumentRule> emptyList = new PagingResultBean<>();
|
|
|
- emptyList.setTableDbName(getType());
|
|
|
- emptyList.setAllRecordCount(0);
|
|
|
- emptyList.setPageSize(boostDocumentRulePager.getPageSize());
|
|
|
- emptyList.setCurrentPageNumber(1);
|
|
|
- return emptyList;
|
|
|
- });
|
|
|
- });
|
|
|
+
|
|
|
+ final PagingResultBean<BoostDocumentRule> boostDocumentRuleList = boostDocumentRuleBhv.selectPage(cb -> {
|
|
|
+ cb.paging(boostDocumentRulePager.getPageSize(), boostDocumentRulePager.getCurrentPageNumber());
|
|
|
+ setupListCondition(cb, boostDocumentRulePager);
|
|
|
+ });
|
|
|
|
|
|
// update pager
|
|
|
Beans.copy(boostDocumentRuleList, boostDocumentRulePager).includes(CommonConstants.PAGER_CONVERSION_RULE).execute();
|
|
@@ -93,41 +58,72 @@ public class BoostDocumentRuleService implements Serializable {
|
|
|
return boostDocumentRuleList;
|
|
|
}
|
|
|
|
|
|
- public BoostDocumentRule getBoostDocumentRule(final String id) {
|
|
|
- return fessEsClient.getDocument(getIndex(), getType(), searchRequestBuilder -> {
|
|
|
- searchRequestBuilder.setQuery(QueryBuilders.idsQuery(getType()).addIds(id));
|
|
|
- searchRequestBuilder.setVersion(true);
|
|
|
- return true;
|
|
|
- }, this::createEntity).get();
|
|
|
+ public BoostDocumentRule getBoostDocumentRule(final Map<String, String> keys) {
|
|
|
+ final BoostDocumentRule boostDocumentRule = boostDocumentRuleBhv.selectEntity(cb -> {
|
|
|
+ cb.query().docMeta().setId_Equal(keys.get("id"));
|
|
|
+ setupEntityCondition(cb, keys);
|
|
|
+ }).orElse(null);//TODO
|
|
|
+ if (boostDocumentRule == null) {
|
|
|
+ // TODO exception?
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return boostDocumentRule;
|
|
|
}
|
|
|
|
|
|
- protected String getType() {
|
|
|
- return fieldHelper.boostDocumentRuleType;
|
|
|
+ public void store(final BoostDocumentRule boostDocumentRule) throws CrudMessageException {
|
|
|
+ setupStoreCondition(boostDocumentRule);
|
|
|
+
|
|
|
+ boostDocumentRuleBhv.insertOrUpdate(boostDocumentRule, op -> {
|
|
|
+ op.setRefresh(true);
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- protected String getIndex() {
|
|
|
- return fieldHelper.configIndex;
|
|
|
+ public void delete(final BoostDocumentRule boostDocumentRule) throws CrudMessageException {
|
|
|
+ setupDeleteCondition(boostDocumentRule);
|
|
|
+
|
|
|
+ boostDocumentRuleBhv.delete(boostDocumentRule, op -> {
|
|
|
+ op.setRefresh(true);
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- public void store(final BoostDocumentRule boostDocumentRule) throws CrudMessageException {
|
|
|
- fessEsClient.store(getIndex(), getType(), boostDocumentRule);
|
|
|
+ protected void setupListCondition(final BoostDocumentRuleCB cb, final BoostDocumentRulePager boostDocumentRulePager) {
|
|
|
+ if (boostDocumentRulePager.id != null) {
|
|
|
+ cb.query().docMeta().setId_Equal(boostDocumentRulePager.id);
|
|
|
+ }
|
|
|
+ // TODO Long, Integer, String supported only.
|
|
|
+
|
|
|
+ // setup condition
|
|
|
+ cb.query().addOrderBy_SortOrder_Asc();
|
|
|
+
|
|
|
+ // search
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- public void delete(final BoostDocumentRule boostDocumentRule) throws CrudMessageException {
|
|
|
- fessEsClient.delete(getIndex(), getType(), boostDocumentRule.getId(), boostDocumentRule.getVersion());
|
|
|
+ protected void setupEntityCondition(final BoostDocumentRuleCB cb, final Map<String, String> keys) {
|
|
|
+
|
|
|
+ // setup condition
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- public List<BoostDocumentRule> getAvailableBoostDocumentRuleList() {
|
|
|
- return fessEsClient.getDocumentList(getIndex(), getType(), searchRequestBuilder -> {
|
|
|
- return true;
|
|
|
- }, this::createEntity);
|
|
|
+ protected void setupStoreCondition(final BoostDocumentRule boostDocumentRule) {
|
|
|
+
|
|
|
+ // setup condition
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- protected BoostDocumentRule createEntity(SearchResponse response, SearchHit hit) {
|
|
|
- final BoostDocumentRule boostDocumentRule = BeanUtil.copyMapToNewBean(hit.getSource(), BoostDocumentRule.class);
|
|
|
- boostDocumentRule.setId(hit.getId());
|
|
|
- boostDocumentRule.setVersion(hit.getVersion());
|
|
|
- return boostDocumentRule;
|
|
|
+ protected void setupDeleteCondition(final BoostDocumentRule boostDocumentRule) {
|
|
|
+
|
|
|
+ // setup condition
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<BoostDocumentRule> getAvailableBoostDocumentRuleList() {
|
|
|
+ return boostDocumentRuleBhv.selectList(cb -> {
|
|
|
+ cb.query().addOrderBy_SortOrder_Asc();
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+}
|