use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class SearchHelper method getDocumentListByDocIds.
public List<Map<String, Object>> getDocumentListByDocIds(final String[] docIds, final String[] fields, final OptionalThing<FessUserBean> userBean, final SearchRequestType searchRequestType) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
return ComponentUtil.getSearchEngineClient().getDocumentList(fessConfig.getIndexDocumentSearchIndex(), builder -> {
final BoolQueryBuilder boolQuery = QueryBuilders.boolQuery().must(QueryBuilders.termsQuery(fessConfig.getIndexFieldDocId(), docIds));
final QueryHelper queryHelper = ComponentUtil.getQueryHelper();
if (searchRequestType != SearchRequestType.ADMIN_SEARCH) {
final Set<String> roleSet = ComponentUtil.getRoleQueryHelper().build(searchRequestType);
if (!roleSet.isEmpty()) {
queryHelper.buildRoleQuery(roleSet, boolQuery);
}
}
builder.setQuery(boolQuery);
builder.setSize(fessConfig.getPagingSearchPageMaxSizeAsInteger());
builder.setFetchSource(fields, null);
queryHelper.processSearchPreference(builder, userBean, String.join(StringUtil.EMPTY, docIds));
return true;
});
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class SuggestHelper method init.
@PostConstruct
public void init() {
if (logger.isDebugEnabled()) {
logger.debug("Initialize {}", this.getClass().getSimpleName());
}
fessConfig = ComponentUtil.getFessConfig();
split(fessConfig.getSuggestFieldContents(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(contentFieldNameSet::add));
split(fessConfig.getSuggestFieldTags(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(tagFieldNameSet::add));
split(fessConfig.getSuggestFieldRoles(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(roleFieldNameSet::add));
contentFieldList = Arrays.asList(stream(fessConfig.getSuggestFieldContents()).get(stream -> stream.toArray(n -> new String[n])));
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
searchEngineClient.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(fessConfig.getIndexHealthTimeout());
final SuggestSettingsBuilder settingsBuilder = SuggestSettings.builder();
settingsBuilder.addInitialSettings("elasticsearch.type", fessConfig.getFesenType());
settingsBuilder.bulkTimeout(fessConfig.getIndexBulkTimeout());
settingsBuilder.clusterTimeout(fessConfig.getIndexHealthTimeout());
settingsBuilder.indexTimeout(fessConfig.getIndexIndexTimeout());
settingsBuilder.indicesTimeout(fessConfig.getIndexIndicesTimeout());
settingsBuilder.searchTimeout(fessConfig.getIndexSearchTimeout());
suggester = Suggester.builder().settings(settingsBuilder).build(searchEngineClient, fessConfig.getIndexDocumentSuggestIndex());
suggester.settings().array().delete(SuggestSettings.DefaultKeys.SUPPORTED_FIELDS);
split(fessConfig.getSuggestFieldIndexContents(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(field -> {
try {
suggester.settings().array().add(SuggestSettings.DefaultKeys.SUPPORTED_FIELDS, field);
} catch (final SuggestSettingsException e) {
logger.warn("Failed to add {}", field, e);
}
}));
suggester.createIndexIfNothing();
if (ComponentUtil.hasPopularWordHelper()) {
popularWordHelper = ComponentUtil.getPopularWordHelper();
}
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class CorsFilter method doFilter.
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
final HttpServletRequest httpRequest = (HttpServletRequest) request;
final String origin = httpRequest.getHeader("Origin");
if (StringUtil.isBlank(origin)) {
chain.doFilter(request, response);
return;
}
if (logger.isDebugEnabled()) {
logger.debug("HTTP Request: {}", httpRequest.getMethod());
}
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String allowOrigin = getAllowOrigin(fessConfig, origin);
if (StringUtil.isNotBlank(allowOrigin)) {
if (logger.isDebugEnabled()) {
logger.debug("allowOrigin: {}", allowOrigin);
}
final HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, allowOrigin);
httpResponse.addHeader(ACCESS_CONTROL_ALLOW_METHODS, fessConfig.getApiCorsAllowMethods());
httpResponse.addHeader(ACCESS_CONTROL_ALLOW_HEADERS, fessConfig.getApiCorsAllowHeaders());
httpResponse.addHeader(ACCESS_CONTROL_MAX_AGE, fessConfig.getApiCorsMaxAge());
httpResponse.addHeader(ACCESS_CONTROL_ALLOW_CREDENTIALS, fessConfig.getApiCorsAllowCredentials());
if (OPTIONS.equals(httpRequest.getMethod())) {
httpResponse.setStatus(HttpServletResponse.SC_ACCEPTED);
return;
}
}
chain.doFilter(request, response);
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class CrawlingConfigHelper method getExcludedUrlList.
public List<String> getExcludedUrlList(final String configId) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final int failureCount = fessConfig.getFailureCountThreshold();
final String ignoreFailureType = fessConfig.getIgnoreFailureType();
if (failureCount < 0) {
return Collections.emptyList();
}
final int count = failureCount;
final ListResultBean<FailureUrl> list = ComponentUtil.getComponent(FailureUrlBhv.class).selectList(cb -> {
cb.query().setConfigId_Equal(configId);
cb.query().setErrorCount_GreaterEqual(count);
cb.fetchFirst(fessConfig.getPageFailureUrlMaxFetchSizeAsInteger());
});
if (list.isEmpty()) {
return Collections.emptyList();
}
Pattern pattern = null;
if (StringUtil.isNotBlank(ignoreFailureType)) {
pattern = Pattern.compile(ignoreFailureType);
}
final List<String> urlList = new ArrayList<>();
for (final FailureUrl failureUrl : list) {
if (pattern != null) {
if (!pattern.matcher(failureUrl.getErrorName()).matches()) {
urlList.add(failureUrl.getUrl());
}
} else {
urlList.add(failureUrl.getUrl());
}
}
return urlList;
}
use of org.codelibs.fess.mylasta.direction.FessConfig in project fess by codelibs.
the class CrawlingInfoHelper method getSessionIdList.
public List<Map<String, String>> getSessionIdList(final SearchEngineClient searchEngineClient) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
return searchEngineClient.search(fessConfig.getIndexDocumentSearchIndex(), queryRequestBuilder -> {
queryRequestBuilder.setQuery(QueryBuilders.matchAllQuery());
final TermsAggregationBuilder termsBuilder = AggregationBuilders.terms(fessConfig.getIndexFieldSegment()).field(fessConfig.getIndexFieldSegment()).size(maxSessionIdsInList).order(BucketOrder.key(false));
queryRequestBuilder.addAggregation(termsBuilder);
queryRequestBuilder.setPreference(Constants.SEARCH_PREFERENCE_LOCAL);
return true;
}, (queryRequestBuilder, execTime, searchResponse) -> {
final List<Map<String, String>> sessionIdList = new ArrayList<>();
searchResponse.ifPresent(response -> {
final Terms terms = response.getAggregations().get(fessConfig.getIndexFieldSegment());
for (final Bucket bucket : terms.getBuckets()) {
final Map<String, String> map = new HashMap<>(2);
map.put(fessConfig.getIndexFieldSegment(), bucket.getKey().toString());
map.put(FACET_COUNT_KEY, Long.toString(bucket.getDocCount()));
sessionIdList.add(map);
}
});
return sessionIdList;
});
}
Aggregations