use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class IndexingHelper method getDocumentListByQuery.
protected List<Map<String, Object>> getDocumentListByQuery(final SearchEngineClient searchEngineClient, final QueryBuilder queryBuilder, final String[] fields) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final SearchResponse countResponse = searchEngineClient.prepareSearch(fessConfig.getIndexDocumentUpdateIndex()).setQuery(queryBuilder).setSize(0).execute().actionGet(fessConfig.getIndexSearchTimeout());
final long numFound = countResponse.getHits().getTotalHits().value;
return searchEngineClient.getDocumentList(fessConfig.getIndexDocumentUpdateIndex(), requestBuilder -> {
requestBuilder.setQuery(queryBuilder).setSize((int) numFound);
if (fields != null) {
requestBuilder.setFetchSource(fields, null);
}
return true;
});
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class IndexingHelper method deleteOldDocuments.
private void deleteOldDocuments(final SearchEngineClient searchEngineClient, final DocList docList) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final List<String> docIdList = new ArrayList<>();
for (final Map<String, Object> inputDoc : docList) {
final Object idValue = inputDoc.get(fessConfig.getIndexFieldId());
if (idValue == null) {
continue;
}
final Object configIdValue = inputDoc.get(fessConfig.getIndexFieldConfigId());
if (configIdValue == null) {
continue;
}
final QueryBuilder queryBuilder = QueryBuilders.boolQuery().must(QueryBuilders.termQuery(fessConfig.getIndexFieldUrl(), inputDoc.get(fessConfig.getIndexFieldUrl()))).filter(QueryBuilders.termQuery(fessConfig.getIndexFieldConfigId(), configIdValue));
final List<Map<String, Object>> docs = getDocumentListByQuery(searchEngineClient, queryBuilder, new String[] { fessConfig.getIndexFieldId(), fessConfig.getIndexFieldDocId() });
for (final Map<String, Object> doc : docs) {
final Object oldIdValue = doc.get(fessConfig.getIndexFieldId());
if (!idValue.equals(oldIdValue) && oldIdValue != null) {
final Object oldDocIdValue = doc.get(fessConfig.getIndexFieldDocId());
if (oldDocIdValue != null) {
docIdList.add(oldDocIdValue.toString());
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("{} => {}", queryBuilder, docs);
}
}
if (!docIdList.isEmpty()) {
searchEngineClient.deleteByQuery(fessConfig.getIndexDocumentUpdateIndex(), QueryBuilders.idsQuery().addIds(docIdList.stream().toArray(n -> new String[n])));
}
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class LanguageHelper method createScript.
public Script createScript(final Map<String, Object> doc, final String code) {
final StringBuilder buf = new StringBuilder(100);
buf.append(code);
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String language = DocumentUtil.getValue(doc, fessConfig.getIndexFieldLang(), String.class);
if (StringUtil.isNotBlank(language)) {
for (final String f : langFields) {
buf.append(";ctx._source.").append(f).append('_').append(language).append("=ctx._source.").append(f);
}
}
if (logger.isDebugEnabled()) {
logger.debug("update script: {}", buf);
}
return new Script(buf.toString());
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class LanguageHelper method getReindexScriptSource.
public String getReindexScriptSource() {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String langField = fessConfig.getIndexFieldLang();
final String code = Arrays.stream(langFields).map(s -> "ctx._source['" + s + "_'+ctx._source." + langField + "]=ctx._source." + s).collect(Collectors.joining(";"));
if (logger.isDebugEnabled()) {
logger.debug("reindex script: {}", code);
}
return "if(ctx._source." + langField + "!=null){" + code + "}";
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class LanguageHelper method init.
@PostConstruct
public void init() {
if (logger.isDebugEnabled()) {
logger.debug("Initialize {}", this.getClass().getSimpleName());
}
final FessConfig fessConfig = ComponentUtil.getFessConfig();
langFields = fessConfig.getIndexerLanguageFieldsAsArray();
supportedLanguages = fessConfig.getSupportedLanguagesAsArray();
maxTextLength = fessConfig.getIndexerLanguageDetectLengthAsInteger();
}
Aggregations