modify popular word parameters
This commit is contained in:
parent
a5d829f174
commit
720a767deb
9 changed files with 115 additions and 24 deletions
|
@ -329,7 +329,7 @@ public class JsonApiManager extends BaseApiManager {
|
|||
String errMsg = StringUtil.EMPTY;
|
||||
final StringBuilder buf = new StringBuilder(255);
|
||||
try {
|
||||
final List<String> popularWordList = popularWordHelper.getWordList(seed, tags, fields, excludes);
|
||||
final List<String> popularWordList = popularWordHelper.getWordList(seed, tags, null, fields, excludes);
|
||||
|
||||
buf.append("\"result\":[");
|
||||
boolean first1 = true;
|
||||
|
|
|
@ -21,7 +21,6 @@ import javax.servlet.ServletContext;
|
|||
|
||||
import org.codelibs.core.beans.util.BeanUtil;
|
||||
import org.codelibs.core.beans.util.CopyOptions;
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.exception.UserRoleLoginException;
|
||||
import org.codelibs.fess.util.ActivityUtil;
|
||||
import org.dbflute.optional.OptionalThing;
|
||||
|
@ -29,10 +28,7 @@ import org.lastaflute.di.util.LdiFileUtil;
|
|||
import org.lastaflute.web.login.LoginManager;
|
||||
import org.lastaflute.web.response.ActionResponse;
|
||||
import org.lastaflute.web.ruts.process.ActionRuntime;
|
||||
import org.lastaflute.web.util.LaRequestUtil;
|
||||
import org.lastaflute.web.util.LaServletContextUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author codelibs
|
||||
|
|
|
@ -97,7 +97,7 @@ public abstract class FessSearchAction extends FessBaseAction {
|
|||
runtime.registerData("searchLogSupport", searchLogSupport);
|
||||
runtime.registerData("favoriteSupport", favoriteSupport);
|
||||
if (fessConfig.isWebApiPopularWord()) {
|
||||
runtime.registerData("popularWords", popularWordHelper.getWordList(null, null, null, null));// TODO parameters
|
||||
runtime.registerData("popularWords", popularWordHelper.getWordList(null, null, null, null, null));
|
||||
}
|
||||
return super.hookBefore(runtime);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.codelibs.fess.ds.impl;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.fess.mylasta.direction.FessConfig;
|
||||
import org.codelibs.fess.suggest.request.popularwords.PopularWordsRequestBuilder;
|
||||
import org.codelibs.fess.util.ComponentUtil;
|
||||
|
@ -50,17 +51,18 @@ public class PopularWordHelper {
|
|||
.expireAfterWrite(fessConfig.getSuggestPopularWordCacheExpireAsInteger().longValue(), TimeUnit.MINUTES).build();
|
||||
}
|
||||
|
||||
public List<String> getWordList(final String seed, final String[] tags, final String[] fields, final String[] excludes) {
|
||||
final RoleQueryHelper roleQueryHelper = ComponentUtil.getRoleQueryHelper();
|
||||
final String[] roles = roleQueryHelper.build().stream().toArray(n -> new String[n]);
|
||||
return getWordList(seed, tags, roles, fields, excludes);
|
||||
}
|
||||
|
||||
public List<String> getWordList(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().stream().filter(s -> StringUtil.isNotBlank(s))
|
||||
.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(seed, tags, roles, fields, excludes),
|
||||
getCacheKey(baseSeed, baseTags, baseRoles, baseFields, baseExcludes),
|
||||
() -> {
|
||||
final List<String> wordList = new ArrayList<String>();
|
||||
final SuggestHelper suggestHelper = ComponentUtil.getSuggestHelper();
|
||||
|
@ -68,13 +70,11 @@ public class PopularWordHelper {
|
|||
suggestHelper.suggester().popularWords()
|
||||
.setSize(fessConfig.getSuggestPopularWordSizeAsInteger().intValue())
|
||||
.setWindowSize(fessConfig.getSuggestPopularWordWindowSizeAsInteger().intValue());
|
||||
if (seed != null) {
|
||||
popularWordsRequestBuilder.setSeed(seed);
|
||||
}
|
||||
StreamUtil.of(tags).forEach(tag -> popularWordsRequestBuilder.addTag(tag));
|
||||
StreamUtil.of(roles).forEach(role -> popularWordsRequestBuilder.addRole(role));
|
||||
StreamUtil.of(fields).forEach(field -> popularWordsRequestBuilder.addField(field));
|
||||
StreamUtil.of(excludes).forEach(exclude -> popularWordsRequestBuilder.addExcludeWord(exclude));
|
||||
popularWordsRequestBuilder.setSeed(baseSeed);
|
||||
StreamUtil.of(baseTags).forEach(tag -> popularWordsRequestBuilder.addTag(tag));
|
||||
StreamUtil.of(baseRoles).forEach(role -> popularWordsRequestBuilder.addRole(role));
|
||||
StreamUtil.of(baseFields).forEach(field -> popularWordsRequestBuilder.addField(field));
|
||||
StreamUtil.of(baseExcludes).forEach(exclude -> popularWordsRequestBuilder.addExcludeWord(exclude));
|
||||
popularWordsRequestBuilder.execute().then(r -> {
|
||||
r.getItems().stream().forEach(item -> wordList.add(item.getText()));
|
||||
}).error(t -> logger.warn("Failed to generate popular words.", t));
|
||||
|
|
|
@ -506,6 +506,15 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
/** The key of the configuration. e.g. 0 */
|
||||
String SUGGEST_POPULAR_WORD_SEED = "suggest.popular.word.seed";
|
||||
|
||||
/** The key of the configuration. e.g. */
|
||||
String SUGGEST_POPULAR_WORD_TAGS = "suggest.popular.word.tags";
|
||||
|
||||
/** The key of the configuration. e.g. */
|
||||
String SUGGEST_POPULAR_WORD_FIELDS = "suggest.popular.word.fields";
|
||||
|
||||
/** The key of the configuration. e.g. */
|
||||
String SUGGEST_POPULAR_WORD_EXCLUDES = "suggest.popular.word.excludes";
|
||||
|
||||
/** The key of the configuration. e.g. 10 */
|
||||
String SUGGEST_POPULAR_WORD_SIZE = "suggest.popular.word.size";
|
||||
|
||||
|
@ -2091,6 +2100,51 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
*/
|
||||
Integer getSuggestPopularWordSeedAsInteger();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'suggest.popular.word.tags'. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
*/
|
||||
String getSuggestPopularWordTags();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'suggest.popular.word.tags' as {@link Integer}. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
* @throws NumberFormatException When the property is not integer.
|
||||
*/
|
||||
Integer getSuggestPopularWordTagsAsInteger();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'suggest.popular.word.fields'. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
*/
|
||||
String getSuggestPopularWordFields();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'suggest.popular.word.fields' as {@link Integer}. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
* @throws NumberFormatException When the property is not integer.
|
||||
*/
|
||||
Integer getSuggestPopularWordFieldsAsInteger();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'suggest.popular.word.excludes'. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
*/
|
||||
String getSuggestPopularWordExcludes();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'suggest.popular.word.excludes' as {@link Integer}. <br>
|
||||
* The value is, e.g. <br>
|
||||
* @return The value of found property. (NotNull: if not found, exception but basically no way)
|
||||
* @throws NumberFormatException When the property is not integer.
|
||||
*/
|
||||
Integer getSuggestPopularWordExcludesAsInteger();
|
||||
|
||||
/**
|
||||
* Get the value for the key 'suggest.popular.word.size'. <br>
|
||||
* The value is, e.g. 10 <br>
|
||||
|
@ -3056,6 +3110,30 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
|
|||
return getAsInteger(FessConfig.SUGGEST_POPULAR_WORD_SEED);
|
||||
}
|
||||
|
||||
public String getSuggestPopularWordTags() {
|
||||
return get(FessConfig.SUGGEST_POPULAR_WORD_TAGS);
|
||||
}
|
||||
|
||||
public Integer getSuggestPopularWordTagsAsInteger() {
|
||||
return getAsInteger(FessConfig.SUGGEST_POPULAR_WORD_TAGS);
|
||||
}
|
||||
|
||||
public String getSuggestPopularWordFields() {
|
||||
return get(FessConfig.SUGGEST_POPULAR_WORD_FIELDS);
|
||||
}
|
||||
|
||||
public Integer getSuggestPopularWordFieldsAsInteger() {
|
||||
return getAsInteger(FessConfig.SUGGEST_POPULAR_WORD_FIELDS);
|
||||
}
|
||||
|
||||
public String getSuggestPopularWordExcludes() {
|
||||
return get(FessConfig.SUGGEST_POPULAR_WORD_EXCLUDES);
|
||||
}
|
||||
|
||||
public Integer getSuggestPopularWordExcludesAsInteger() {
|
||||
return getAsInteger(FessConfig.SUGGEST_POPULAR_WORD_EXCLUDES);
|
||||
}
|
||||
|
||||
public String getSuggestPopularWordSize() {
|
||||
return get(FessConfig.SUGGEST_POPULAR_WORD_SIZE);
|
||||
}
|
||||
|
|
|
@ -349,4 +349,22 @@ public interface FessProp {
|
|||
}
|
||||
return params.get(name);
|
||||
}
|
||||
|
||||
String getSuggestPopularWordFields();
|
||||
|
||||
public default String[] getSuggestPopularWordFieldsAsArray() {
|
||||
return StreamUtil.of(getSuggestPopularWordFields().split("\n")).filter(s -> StringUtil.isNotBlank(s)).toArray(n -> new String[n]);
|
||||
}
|
||||
|
||||
String getSuggestPopularWordTags();
|
||||
|
||||
public default String[] getSuggestPopularWordTagsAsArray() {
|
||||
return StreamUtil.of(getSuggestPopularWordTags().split("\n")).filter(s -> StringUtil.isNotBlank(s)).toArray(n -> new String[n]);
|
||||
}
|
||||
|
||||
String getSuggestPopularWordExcludes();
|
||||
|
||||
public default String[] getSuggestPopularWordExcludesAsArray() {
|
||||
return StreamUtil.of(getSuggestPopularWordExcludes().split("\n")).filter(s -> StringUtil.isNotBlank(s)).toArray(n -> new String[n]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,9 @@
|
|||
*/
|
||||
package org.codelibs.fess.util;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.lastaflute.web.util.LaRequestUtil;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -274,6 +274,9 @@ online.help.supported.langs=
|
|||
# ------
|
||||
|
||||
suggest.popular.word.seed=0
|
||||
suggest.popular.word.tags=
|
||||
suggest.popular.word.fields=
|
||||
suggest.popular.word.excludes=
|
||||
suggest.popular.word.size=10
|
||||
suggest.popular.word.window.size=30
|
||||
suggest.min.hit.count=1
|
||||
|
|
Loading…
Add table
Reference in a new issue