提交 674c1719 编写于 作者: O o2null

Merge branch 'feature/index' into 'develop'

delete index

See merge request o2oa/o2oa!1252
......@@ -6,7 +6,6 @@ import javax.ws.rs.ApplicationPath;
import com.x.base.core.project.jaxrs.AbstractActionApplication;
import com.x.query.assemble.surface.jaxrs.importmodel.ImportModelAction;
import com.x.query.assemble.surface.jaxrs.index.IndexAction;
import com.x.query.assemble.surface.jaxrs.morelikethis.MoreLikeThisAction;
import com.x.query.assemble.surface.jaxrs.neural.NeuralAction;
import com.x.query.assemble.surface.jaxrs.query.QueryAction;
......@@ -28,7 +27,6 @@ public class ActionApplication extends AbstractActionApplication {
classes.add(StatementAction.class);
classes.add(ImportModelAction.class);
classes.add(SearchAction.class);
classes.add(IndexAction.class);
classes.add(MoreLikeThisAction.class);
return classes;
}
......
package com.x.query.assemble.surface.jaxrs;
import javax.servlet.annotation.WebFilter;
import com.x.base.core.project.jaxrs.CipherManagerUserJaxrsFilter;
@WebFilter(urlPatterns = "/jaxrs/index/*", asyncSupported = true)
public class IndexJaxrsFilter extends CipherManagerUserJaxrsFilter {
}
package com.x.query.assemble.surface.jaxrs.index;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.lucene.index.MultiReader;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopFieldCollector;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.google.common.collect.Streams;
import com.google.gson.JsonElement;
import com.hankcs.lucene.HanLPAnalyzer;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.bean.tuple.Pair;
import com.x.base.core.project.bean.tuple.Quadruple;
import com.x.base.core.project.bean.tuple.Quintuple;
import com.x.base.core.project.bean.tuple.Triple;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.DateTools;
import com.x.base.core.project.tools.ListTools;
import com.x.general.core.entity.GeneralFile;
import com.x.query.assemble.surface.Business;
import com.x.query.assemble.surface.ThisApplication;
import com.x.query.core.express.assemble.surface.jaxrs.index.ActionExportWi;
import com.x.query.core.express.index.Indexs;
import com.x.query.core.express.index.WoField;
import io.swagger.v3.oas.annotations.media.Schema;
class ActionExport extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionExport.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
LOGGER.info("execute:{}.", effectivePerson::getDistinguishedName);
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
result.setData(wo);
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Set<String> readers = new TreeSet<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
String person = business.index().who(effectivePerson, wi.getPerson());
wi.getDirectoryList().stream().forEach(o -> {
try {
readers.addAll(business.index().determineReaders(person, o.getCategory(), o.getKey()));
} catch (Exception e) {
LOGGER.error(e);
}
});
}
List<String> categories = this.categories(wi.getDirectoryList());
Optional<Query> searchQuery = searchQuery(wi.getQuery(), new HanLPAnalyzer());
Optional<Query> readersQuery = Indexs.readersQuery(readers);
List<Query> filterQueries = Indexs.filterQueries(wi.getFilterList());
BooleanQuery.Builder builder = new BooleanQuery.Builder();
Stream.of(searchQuery, readersQuery).filter(Optional::isPresent)
.forEach(o -> builder.add(o.get(), BooleanClause.Occur.MUST));
filterQueries.stream().forEach(o -> builder.add(o, BooleanClause.Occur.MUST));
Query query = builder.build();
LOGGER.debug("index export lucene query:{}.", query::toString);
try (MultiReader multiReader = new MultiReader(indexReaders(wi.getDirectoryList()));
Workbook workbook = new XSSFWorkbook()) {
List<Triple<String, String, String>> outFields = outFields(
this.getFixedFieldList(categories),
wi.getFixedFieldList(),
wi.getDynamicFieldList());
IndexSearcher searcher = new IndexSearcher(multiReader);
TopFieldCollector topFieldCollector = TopFieldCollector.create(sort(wi.getSort()),
Config.query().index().getSearchMaxHits(), Config.query().index().getSearchMaxHits());
searcher.search(query, topFieldCollector);
Sheet sheet = createSheet(workbook, outFields);
ScoreDoc[] scoreDocs = topFieldCollector.topDocs().scoreDocs;
if (null != scoreDocs) {
CellStyle cellStyle = valueCellStyle(workbook);
Arrays.stream(
scoreDocs).<Quadruple<List<Triple<String, String, String>>, org.apache.lucene.document.Document, Sheet, CellStyle>>map(
o -> {
try {
org.apache.lucene.document.Document document = searcher.doc(o.doc);
return Quadruple.of(outFields, document, sheet, cellStyle);
} catch (Exception e) {
LOGGER.error(e);
}
return Quadruple.of(outFields, null, sheet, cellStyle);
})
.filter(o -> !Objects.isNull(o.second())).forEach(documentExportConsumer);
}
sheet.setAutobreaks(true);
for (int i = 0; i < outFields.size(); i++) {
sheet.autoSizeColumn(i);
}
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create();
ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
workbook.write(baos);
String name = DateTools.format(new Date(), DateTools.formatCompact_yyyyMMddHHmmss) + ".xlsx";
StorageMapping mapping = ThisApplication.context().storageMappings().random(GeneralFile.class);
GeneralFile generalFile = new GeneralFile(mapping.getName(), name,
effectivePerson.getDistinguishedName());
generalFile.saveContent(mapping, baos.toByteArray(), name);
emc.beginTransaction(GeneralFile.class);
emc.persist(generalFile, CheckPersistType.all);
emc.commit();
wo.setId(generalFile.getId());
}
}
return result;
}
private List<Triple<String, String, String>> outFields(List<WoField> woFields, List<String> fixedFieldList,
List<String> dynamicFieldList) {
List<Triple<String, String, String>> list = new ArrayList<>();
if (ListTools.isEmpty(fixedFieldList) && ListTools.isEmpty(dynamicFieldList)) {
list.addAll(woFields.stream()
.map(o -> Triple.of(o.getField(), o.getName(), o.getFieldType())).collect(Collectors.toList()));
} else {
if (!ListTools.isEmpty(fixedFieldList)) {
fixedFieldList.stream().forEach(o -> list.add(Indexs.judgeField(o)));
}
if (!ListTools.isEmpty(dynamicFieldList)) {
dynamicFieldList.stream().forEach(o -> list.add(Indexs.judgeField(o)));
}
}
return list;
}
private static CellStyle valueCellStyle(Workbook workbook) {
CellStyle cellStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBold(false);
cellStyle.setFont(font);
cellStyle.setWrapText(true);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle.setAlignment(HorizontalAlignment.LEFT);
return cellStyle;
}
private static Sheet createSheet(Workbook workbook, List<Triple<String, String, String>> list) {
Sheet sheet = workbook.createSheet();
Row row = sheet.createRow(0);
CellStyle cellStyle = workbook.createCellStyle();
Font font = workbook.createFont();
font.setBold(true);
cellStyle.setFont(font);
cellStyle.setWrapText(true);
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
cellStyle.setAlignment(HorizontalAlignment.CENTER);
Streams.mapWithIndex(list.stream(), Pair::of).forEach(p -> {
Cell cell = row.createCell(p.second().intValue());
cell.setCellValue(p.first().second());
cell.setCellStyle(cellStyle);
});
// auto row size
row.setHeight((short) 0);
return sheet;
}
private static Consumer<Quadruple<List<Triple<String, String, String>>, org.apache.lucene.document.Document, Sheet, CellStyle>> documentExportConsumer = param -> {
final Row row = param.third().createRow(param.third().getLastRowNum() + 1);
Streams.mapWithIndex(param.first().stream(), Pair::of)
.map(o -> Quintuple.of(o.first().first(), o.first().second(), o.first().third(), o.second(),
param.second().getFields(o.first().first())))
.filter(o -> o.fifth().length > 0).forEach(o -> {
Object value = Indexs.indexableFieldValue(o.fifth(), o.third());
Cell cell = row.createCell(o.fourth().intValue());
if ((null != value) && (Date.class.isAssignableFrom(value.getClass()))) {
cell.setCellValue(DateTools.format((Date) value));
} else {
cell.setCellValue(Objects.toString(value, ""));
}
cell.setCellStyle(param.fourth());
});
};
@Schema(name = "com.x.custom.index.assemble.control.jaxrs.search.ActionExport$Wo")
public static class Wo extends WoId {
private static final long serialVersionUID = 902681475422445346L;
}
@Schema(name = "com.x.custom.index.assemble.control.jaxrs.search.ActionExport$Wi")
public class Wi extends ActionExportWi {
private static final long serialVersionUID = -4646809016933808952L;
}
}
\ No newline at end of file
package com.x.query.assemble.surface.jaxrs.index;
import org.apache.commons.lang3.StringUtils;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.config.StorageMapping;
import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoFile;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.general.core.entity.GeneralFile;
import com.x.query.assemble.surface.ThisApplication;
import io.swagger.v3.oas.annotations.media.Schema;
class ActionExportResult extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionExportResult.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String flag) throws Exception {
LOGGER.debug("execute:{}. flag:{}.", effectivePerson::getDistinguishedName, () -> flag);
ActionResult<Wo> result = new ActionResult<>();
Wo wo = null;
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
GeneralFile generalFile = emc.find(flag, GeneralFile.class);
if (generalFile != null) {
if (!StringUtils.equals(effectivePerson.getDistinguishedName(), generalFile.getPerson())) {
throw new ExceptionAccessDenied(effectivePerson);
}
StorageMapping gfMapping = ThisApplication.context().storageMappings().get(GeneralFile.class,
generalFile.getStorage());
wo = new Wo(generalFile.readContent(gfMapping), this.contentType(true, generalFile.getName()),
this.contentDisposition(true, generalFile.getName()));
result.setData(wo);
} else {
throw new ExceptionEntityNotExist(flag, GeneralFile.class);
}
}
result.setData(wo);
return result;
}
@Schema(name = "com.x.custom.index.assemble.control.jaxrs.index.ActionExportResult$Wo")
public static class Wo extends WoFile {
private static final long serialVersionUID = 863645073714444828L;
public Wo(byte[] bytes, String contentType, String contentDisposition) {
super(bytes, contentType, contentDisposition);
}
}
}
package com.x.query.assemble.surface.jaxrs.index;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.project.annotation.FieldDescribe;
import com.x.base.core.project.cache.Cache.CacheKey;
import com.x.base.core.project.cache.CacheManager;
import com.x.base.core.project.gson.GsonPropertyObject;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.cms.core.entity.AppInfo;
import com.x.processplatform.core.entity.element.Application;
import com.x.query.assemble.surface.Business;
import com.x.query.core.express.index.Indexs;
import io.swagger.v3.oas.annotations.media.Schema;
class ActionListDirectory extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionListDirectory.class);
private static final List<String> APPLICATIONATTRIBUTES = Stream
.<String>of(JpaObject.id_FIELDNAME, Application.name_FIELDNAME).collect(Collectors.toUnmodifiableList());
private static final List<String> APPINFOATTRIBUTES = Stream
.<String>of(JpaObject.id_FIELDNAME, AppInfo.appName_FIELDNAME).collect(Collectors.toUnmodifiableList());
@SuppressWarnings("unchecked")
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson) throws Exception {
LOGGER.info("execute:{}.", effectivePerson::getDistinguishedName);
ActionResult<List<Wo>> result = new ActionResult<>();
CacheKey cacheKey = new CacheKey(this.getClass());
Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
if (optional.isPresent()) {
result.setData((List<Wo>) optional.get());
} else {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
List<Wo> wos = new ArrayList<>();
Business business = new Business(emc);
wos.add(this.processPlatform(business));
wos.add(this.cms(business));
CacheManager.put(cacheCategory, cacheKey, wos);
result.setData(wos);
}
}
return result;
}
private Wo processPlatform(Business business) throws Exception {
EntityManagerContainer emc = business.entityManagerContainer();
List<Application> os = emc.fetchAll(Application.class, APPLICATIONATTRIBUTES);
List<WoKey> keys = os.stream().map(o -> new WoKey(o.getName(), o.getId()))
.sorted(Comparator.nullsLast(Comparator.comparing(WoKey::getName))).collect(
ArrayList::new, List::add,
List::addAll);
Wo wo = new Wo();
wo.setCategory(Indexs.CATEGORY_PROCESSPLATFORM);
wo.setKeyList(keys);
return wo;
}
private Wo cms(Business business) throws Exception {
EntityManagerContainer emc = business.entityManagerContainer();
List<AppInfo> os = emc.fetchAll(AppInfo.class, APPINFOATTRIBUTES);
List<WoKey> keys = os.stream().map(o -> new WoKey(o.getAppName(), o.getId()))
.sorted(Comparator.nullsLast(Comparator.comparing(WoKey::getName))).collect(
ArrayList::new, List::add,
List::addAll);
Wo wo = new Wo();
wo.setCategory(Indexs.CATEGORY_CMS);
wo.setKeyList(keys);
return wo;
}
@Schema(name = "com.x.query.assemble.surface.jaxrs.index.ActionListDirectory$Wo")
public class Wo extends GsonPropertyObject {
@FieldDescribe("分类")
@Schema(description = "分类")
private String category;
@FieldDescribe("标识")
@Schema(description = "标识")
private List<WoKey> keyList = new ArrayList<>();
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public List<WoKey> getKeyList() {
return keyList;
}
public void setKeyList(List<WoKey> keyList) {
this.keyList = keyList;
}
}
@Schema(name = "com.x.query.assemble.surface.jaxrs.index.ActionListDirectory$WoKey")
public class WoKey extends GsonPropertyObject {
public WoKey(String name, String key) {
this.name = name;
this.key = key;
}
@FieldDescribe("名称.")
@Schema(description = "名称.")
private String name;
@FieldDescribe("标识.")
@Schema(description = "标识.")
private String key;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
}
}
\ No newline at end of file
package com.x.query.assemble.surface.jaxrs.index;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.MultiReader;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MultiCollector;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TopFieldCollector;
import org.apache.lucene.search.grouping.FirstPassGroupingCollector;
import org.apache.lucene.search.grouping.SearchGroup;
import org.apache.lucene.search.grouping.TermGroupSelector;
import org.apache.lucene.search.grouping.TopGroupsCollector;
import org.apache.lucene.util.BytesRef;
import com.google.gson.JsonElement;
import com.hankcs.lucene.HanLPAnalyzer;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.bean.tuple.Pair;
import com.x.base.core.project.bean.tuple.Quadruple;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.query.assemble.surface.Business;
import com.x.query.core.express.assemble.surface.jaxrs.index.ActionPostWi;
import com.x.query.core.express.assemble.surface.jaxrs.index.ActionPostWo;
import com.x.query.core.express.index.Facets;
import com.x.query.core.express.index.Filter;
import com.x.query.core.express.index.Indexs;
import com.x.query.core.express.index.WoField;
import io.swagger.v3.oas.annotations.media.Schema;
class ActionPost extends BaseAction {
private static final Logger LOGGER = LoggerFactory.getLogger(ActionPost.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
LOGGER.info("execute:{}.", effectivePerson::getDistinguishedName);
ActionResult<Wo> result = new ActionResult<>();
Wo wo = new Wo();
result.setData(wo);
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
Integer rows = Indexs.rows(wi.getSize());
Integer start = Indexs.start(wi.getPage(), rows);
Set<String> readers = new TreeSet<>();
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
Business business = new Business(emc);
String person = business.index().who(effectivePerson, wi.getPerson());
wi.getDirectoryList().stream().forEach(o -> {
try {
readers.addAll(business.index().determineReaders(person, o.getCategory(), o.getKey()));
} catch (Exception e) {
LOGGER.error(e);
}
});
}
List<String> categories = this.categories(wi.getDirectoryList());
initWo(wo, categories);
Optional<Query> searchQuery = searchQuery(wi.getQuery(), new HanLPAnalyzer());
Optional<Query> readersQuery = Indexs.readersQuery(readers);
List<Query> filterQueries = Indexs.filterQueries(wi.getFilterList());
BooleanQuery.Builder builder = new BooleanQuery.Builder();
Stream.of(searchQuery, readersQuery).filter(Optional::isPresent)
.forEach(o -> builder.add(o.get(), BooleanClause.Occur.MUST));
filterQueries.stream().forEach(o -> builder.add(o, BooleanClause.Occur.MUST));
Query query = builder.build();
LOGGER.debug("index lucene query:{}.", query::toString);
IndexReader[] indexReaders = this.indexReaders(wi.getDirectoryList());
if (indexReaders.length == 0) {
return result;
}
try (MultiReader multiReader = new MultiReader(indexReaders)) {
IndexSearcher searcher = new IndexSearcher(multiReader);
wo.setDynamicFieldList(getDynamicFieldList(categories, multiReader));
TopFieldCollector topFieldCollector = TopFieldCollector.create(sort(wi.getSort()), 1000, 1000);
List<Pair<String, FirstPassGroupingCollector<BytesRef>>> firstPassGroupingCollectorPairs = this
.adjustFacetField(categories,
wi.getFilterList().stream().map(Filter::getField).collect(Collectors.toList()))
.stream()
.<Pair<String, FirstPassGroupingCollector<BytesRef>>>map(o -> {
try {
return Pair.of(o,
new FirstPassGroupingCollector<>(new TermGroupSelector(o),
org.apache.lucene.search.Sort.INDEXORDER,
Config.query().index().getFacetMaxGroups()));
} catch (Exception ex) {
LOGGER.error(ex);
}
return null;
}).filter(o -> !Objects.isNull(o)).collect(Collectors.toList());
searcher.search(query, MultiCollector.wrap(topFieldCollector, MultiCollector
.wrap(firstPassGroupingCollectorPairs.stream().map(Pair::second).collect(Collectors.toList()))));
writeDocument(searcher, topFieldCollector, start, rows, wo, wi.getFixedFieldList(),
wi.getDynamicFieldList());
List<Pair<String, TopGroupsCollector<BytesRef>>> topGroupsCollectorPairs = firstPassGroupingCollectorPairs
.stream().<Pair<String, Optional<Collection<SearchGroup<BytesRef>>>>>map(param -> {
Collection<SearchGroup<BytesRef>> topGroups = null;
try {
topGroups = param.second().getTopGroups(0);
} catch (Exception e) {
LOGGER.error(e);
}
if (Objects.isNull(topGroups)) {
return Pair.of(param.first(), Optional.empty());
} else {
return Pair.of(param.first(), Optional.of(topGroups));
}
}).filter(o -> o.second().isPresent())
.<Pair<String, TopGroupsCollector<BytesRef>>>map(param -> {
try {
return Pair.of(param.first(),
new TopGroupsCollector<>(new TermGroupSelector(param.first()), param.second().get(),
org.apache.lucene.search.Sort.INDEXORDER,
org.apache.lucene.search.Sort.INDEXORDER,
Config.query().index().getSearchMaxHits(), false));
} catch (Exception e) {
LOGGER.error(e);
}
return null;
}).filter(o -> !Objects.isNull(o)).collect(Collectors.toList());
if (!topGroupsCollectorPairs.isEmpty()) {
searcher.search(query, MultiCollector
.wrap(topGroupsCollectorPairs.stream().map(Pair::second).collect(Collectors.toList())));
wo.setFacetList(Facets.topGroupsCollector(topGroupsCollectorPairs));
}
}
return result;
}
private void initWo(Wo wo, List<String> categories) {
wo.setFixedFieldList(this.getFixedFieldList(categories));
}
private void writeDocument(IndexSearcher searcher, TopFieldCollector topFieldCollector, int start, int rows, Wo wo,
List<String> fixedFieldList, List<String> dynamicFieldList) {
List<String> outFields = outFields(wo, fixedFieldList, dynamicFieldList);
TopDocs topDocs = topFieldCollector.topDocs(start, rows);
wo.setCount(topDocs.totalHits.value);
ScoreDoc[] scoreDocs = topDocs.scoreDocs;
if (null != scoreDocs) {
Arrays.stream(scoreDocs).forEach(o -> {
try {
org.apache.lucene.document.Document document = searcher.doc(o.doc);
Map<String, Object> map = outFields.stream()
.map(f -> Quadruple.of(Indexs.judgeField(f), document.getFields(f)))
.filter(param -> param.fourth().length > 0)
.map(p -> Pair.of(p.first(), Indexs.indexableFieldValue(p.fourth(), p.third())))
.collect(Collectors.toMap(Pair::first, Pair::second));
wo.getDocumentList().add(map);
} catch (Exception e) {
LOGGER.error(e);
}
});
}
}
private List<String> outFields(Wo wo, List<String> fixedFieldList, List<String> dynamicFieldList) {
List<String> list = new ArrayList<>();
list.add(Indexs.FIELD_ID);
if (ListTools.isEmpty(fixedFieldList) && ListTools.isEmpty(dynamicFieldList)) {
list.addAll(wo.getFixedFieldList().stream().map(WoField::getField).collect(Collectors.toList()));
} else {
list.addAll(fixedFieldList);
list.addAll(dynamicFieldList);
}
return list;
}
@Schema(name = "com.x.custom.index.assemble.control.jaxrs.index.ActionPost$Wo")
public class Wo extends ActionPostWo {
private static final long serialVersionUID = 3751674531291729956L;
}
@Schema(name = "com.x.custom.index.assemble.control.jaxrs.index.ActionPost$Wi")
public class Wi extends ActionPostWi {
private static final long serialVersionUID = -4646809016933808952L;
}
}
package com.x.query.assemble.surface.jaxrs.index;
import com.x.base.core.project.exception.PromptException;
class ExceptionDirectoryNotExist extends PromptException {
private static final long serialVersionUID = -3439770681867963457L;
ExceptionDirectoryNotExist() {
super("directory not exist.");
}
}
package com.x.query.assemble.surface.jaxrs.index;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import com.google.gson.JsonElement;
import com.x.base.core.project.annotation.JaxrsDescribe;
import com.x.base.core.project.annotation.JaxrsMethodDescribe;
import com.x.base.core.project.annotation.JaxrsParameterDescribe;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.http.HttpMediaType;
import com.x.base.core.project.jaxrs.ResponseFactory;
import com.x.base.core.project.jaxrs.StandardJaxrsAction;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
@Tag(name = "IndexAction", description = "检索接口.")
@Path("index")
@JaxrsDescribe("检索接口.")
public class IndexAction extends StandardJaxrsAction {
private static final Logger LOGGER = LoggerFactory.getLogger(IndexAction.class);
private static final String OPERATIONID_PREFIX = "IndexAction::";
@Operation(summary = "执行检索.", operationId = OPERATIONID_PREFIX + "post", responses = { @ApiResponse(content = {
@Content(schema = @Schema(implementation = ActionPost.Wo.class)) }) }, requestBody = @RequestBody(content = {
@Content(schema = @Schema(implementation = ActionPost.Wi.class)) }))
@JaxrsMethodDescribe(value = "执行检索.", action = ActionPost.class)
@POST
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void post(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<ActionPost.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionPost().execute(effectivePerson, jsonElement);
} catch (Exception e) {
LOGGER.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@Operation(summary = "执行导出.", operationId = OPERATIONID_PREFIX + "export", responses = { @ApiResponse(content = {
@Content(schema = @Schema(implementation = ActionExport.Wo.class)) }) }, requestBody = @RequestBody(content = {
@Content(schema = @Schema(implementation = ActionExport.Wi.class)) }))
@JaxrsMethodDescribe(value = "执行导出.", action = ActionExport.class)
@POST
@Path("export")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void export(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
JsonElement jsonElement) {
ActionResult<ActionExport.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionExport().execute(effectivePerson, jsonElement);
} catch (Exception e) {
LOGGER.error(e, effectivePerson, request, jsonElement);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@Operation(summary = "获取指定标识返回导出结果文件.", operationId = OPERATIONID_PREFIX + "exportResult", responses = {
@ApiResponse(content = { @Content(schema = @Schema(implementation = ActionExportResult.Wo.class)) }) })
@JaxrsMethodDescribe(value = "获取指定标识返回导出结果文件.", action = ActionExportResult.class)
@GET
@Path("export/{flag}/result")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void exportResult(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request,
@JaxrsParameterDescribe("标识") @PathParam("flag") String flag) {
ActionResult<ActionExportResult.Wo> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionExportResult().execute(effectivePerson, flag);
} catch (Exception e) {
LOGGER.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
@Operation(summary = "获取检索目录列表.", operationId = OPERATIONID_PREFIX + "listDirectory", responses = {
@ApiResponse(content = { @Content(schema = @Schema(implementation = ActionListDirectory.Wo.class)) }) })
@JaxrsMethodDescribe(value = "获取检索目录列表.", action = ActionListDirectory.class)
@GET
@Path("list/directory")
@Produces(HttpMediaType.APPLICATION_JSON_UTF_8)
@Consumes(MediaType.APPLICATION_JSON)
public void listDirectory(@Suspended final AsyncResponse asyncResponse, @Context HttpServletRequest request) {
ActionResult<List<ActionListDirectory.Wo>> result = new ActionResult<>();
EffectivePerson effectivePerson = this.effectivePerson(request);
try {
result = new ActionListDirectory().execute(effectivePerson);
} catch (Exception e) {
LOGGER.error(e, effectivePerson, request, null);
result.error(e);
}
asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册