limit target documents num of suggest

This commit is contained in:
yfujita 2017-01-30 19:44:00 +09:00
parent 241ab2c8c9
commit ae8d9c7752
3 changed files with 55 additions and 2 deletions

View file

@ -48,8 +48,11 @@ import org.codelibs.fess.suggest.index.contents.document.ESSourceReader;
import org.codelibs.fess.suggest.settings.SuggestSettings;
import org.codelibs.fess.suggest.util.SuggestUtil;
import org.codelibs.fess.util.ComponentUtil;
import org.elasticsearch.common.lucene.search.function.CombineFunction;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -151,7 +154,16 @@ public class SuggestHelper {
final ESSourceReader reader =
new ESSourceReader(fessEsClient, suggester.settings(), fessConfig.getIndexDocumentSearchIndex(),
fessConfig.getIndexDocumentType());
reader.setScrollSize(fessConfig.getSuggestSourceReaderScrollSizeAsInteger().intValue());
reader.setScrollSize(fessConfig.getSuggestSourceReaderScrollSizeAsInteger());
reader.setLimitDocNumPercentage(fessConfig.getSuggestUpdateContentsLimitNumPercentage());
reader.setLimitNumber(fessConfig.getSuggestUpdateContentsLimitNumAsInteger());
final List<FunctionScoreQueryBuilder.FilterFunctionBuilder> flist = new ArrayList<>();
flist.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(ScoreFunctionBuilders.randomFunction(System
.currentTimeMillis())));
reader.setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.matchAllQuery(),
flist.toArray(new FunctionScoreQueryBuilder.FilterFunctionBuilder[flist.size()])).boostMode(
CombineFunction.MULTIPLY));
return reader;
}, 2, fessConfig.getSuggestUpdateRequestIntervalAsInteger().longValue()).then(response -> {
suggester.refresh();
@ -305,5 +317,4 @@ public class SuggestHelper {
public void deleteBadWord(final String badWord) {
suggester.indexer().deleteBadWord(badWord);
}
}

View file

@ -855,6 +855,12 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. 1 */
String SUGGEST_UPDATE_REQUEST_INTERVAL = "suggest.update.request.interval";
/** The key of the configuration. e.g. 50% */
String SUGGEST_UPDATE_CONTENTS_LIMIT_NUM_PERCENTAGE = "suggest.update.contents.limit.num.percentage";
/** The key of the configuration. e.g. 10000 */
String SUGGEST_UPDATE_CONTENTS_LIMIT_NUM = "suggest.update.contents.limit.num";
/** The key of the configuration. e.g. 1 */
String SUGGEST_SOURCE_READER_SCROLL_SIZE = "suggest.source.reader.scroll.size";
@ -3798,6 +3804,28 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
Integer getSuggestUpdateRequestIntervalAsInteger();
/**
* Get the value for the key 'suggest.update.contents.limit.num.percentage'. <br>
* The value is, e.g. 50% <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getSuggestUpdateContentsLimitNumPercentage();
/**
* Get the value for the key 'suggest.update.contents.limit.num'. <br>
* The value is, e.g. 10000 <br>
* @return The value of found property. (NotNull: if not found, exception but basically no way)
*/
String getSuggestUpdateContentsLimitNum();
/**
* Get the value for the key 'suggest.update.contents.limit.num' as {@link Integer}. <br>
* The value is, e.g. 10000 <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 getSuggestUpdateContentsLimitNumAsInteger();
/**
* Get the value for the key 'suggest.source.reader.scroll.size'. <br>
* The value is, e.g. 1 <br>
@ -5880,6 +5908,18 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
return getAsInteger(FessConfig.SUGGEST_UPDATE_REQUEST_INTERVAL);
}
public String getSuggestUpdateContentsLimitNumPercentage() {
return get(FessConfig.SUGGEST_UPDATE_CONTENTS_LIMIT_NUM_PERCENTAGE);
}
public String getSuggestUpdateContentsLimitNum() {
return get(FessConfig.SUGGEST_UPDATE_CONTENTS_LIMIT_NUM);
}
public Integer getSuggestUpdateContentsLimitNumAsInteger() {
return getAsInteger(FessConfig.SUGGEST_UPDATE_CONTENTS_LIMIT_NUM);
}
public String getSuggestSourceReaderScrollSize() {
return get(FessConfig.SUGGEST_SOURCE_READER_SCROLL_SIZE);
}

View file

@ -438,6 +438,8 @@ suggest.field.tags=label
suggest.field.roles=role
suggest.field.index.contents=content,title
suggest.update.request.interval=1
suggest.update.contents.limit.num.percentage=50%
suggest.update.contents.limit.num=10000
suggest.source.reader.scroll.size=1
suggest.popular.word.cache.size=1000
suggest.popular.word.cache.expire=60