use of org.codelibs.fess.suggest.request.popularwords.PopularWordsRequestBuilder in project fess by codelibs.
the class PopularWordHelper method getWordList.
public List<String> getWordList(final SearchRequestType searchRequestType, final String seed, final String[] tags, final String[] roles, final String[] fields, final String[] excludes) {
final String baseSeed = seed != null ? seed : fessConfig.getSuggestPopularWordSeed();
final String[] baseTags = tags != null ? tags : fessConfig.getSuggestPopularWordTagsAsArray();
final String[] baseRoles = roles != null ? roles : ComponentUtil.getRoleQueryHelper().build(searchRequestType).stream().filter(StringUtil::isNotBlank).toArray(n -> new String[n]);
final String[] baseFields = fields != null ? fields : fessConfig.getSuggestPopularWordFieldsAsArray();
final String[] baseExcludes = excludes != null ? excludes : fessConfig.getSuggestPopularWordExcludesAsArray();
try {
return cache.get(getCacheKey(baseSeed, baseTags, baseRoles, baseFields, baseExcludes), () -> {
final List<String> wordList = new ArrayList<>();
final SuggestHelper suggestHelper = ComponentUtil.getSuggestHelper();
final PopularWordsRequestBuilder popularWordsRequestBuilder = suggestHelper.suggester().popularWords().setSize(fessConfig.getSuggestPopularWordSizeAsInteger()).setWindowSize(fessConfig.getSuggestPopularWordWindowSizeAsInteger()).setQueryFreqThreshold(fessConfig.getSuggestPopularWordQueryFreqAsInteger());
popularWordsRequestBuilder.setSeed(baseSeed);
stream(baseTags).of(stream -> stream.forEach(tag -> popularWordsRequestBuilder.addTag(tag)));
stream(baseRoles).of(stream -> stream.forEach(role -> popularWordsRequestBuilder.addRole(role)));
stream(baseFields).of(stream -> stream.forEach(field -> popularWordsRequestBuilder.addField(field)));
stream(baseExcludes).of(stream -> stream.forEach(exclude -> popularWordsRequestBuilder.addExcludeWord(exclude)));
try {
popularWordsRequestBuilder.execute().getResponse().getItems().stream().forEach(item -> wordList.add(item.getText()));
} catch (final SuggesterException e) {
logger.warn("Failed to generate popular words.", e);
}
return wordList;
});
} catch (final ExecutionException e) {
logger.warn("Failed to load popular words.", e);
}
return Collections.emptyList();
}
Aggregations