本文整理汇总了Java中org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ScriptScoreFunctionBuilder类的具体用法?Java ScriptScoreFunctionBuilder怎么用?Java ScriptScoreFunctionBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScriptScoreFunctionBuilder类属于org.elasticsearch.index.query.functionscore.script包,在下文中一共展示了ScriptScoreFunctionBuilder类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeQueryBuilder
import org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionBuilder; //导入依赖的package包/类
/**
* 构建查询
*
* @return
*/
public QueryBuilder makeQueryBuilder(SearchRequestBuilder srb) {
// 拼接查询层次
BoolQueryBuilder boolQ = QueryBuilders.boolQuery();
Map<SearchCondition, ConditionType> searchTypeMap = this.request.getSearchConditions();
ConditionType conditionType;
BoolQueryBuilder subBoolQ;
for (SearchCondition searchCondition : searchTypeMap.keySet()) {
conditionType = searchTypeMap.get(searchCondition);
subBoolQ = queryBuilder(searchCondition, conditionType);
mergeBuilder(boolQ, subBoolQ, conditionType);
}
// 没有条件直接返回
if (!boolQ.hasClauses()) {
return null;
}
// 得分脚本
if (request.getSafeScoreScript().size() < 1) {
srb.setQuery(boolQ);
return boolQ;
}
String boost_mode = request.getSafeExtend().get(Constants.BOOST_MODE_KEY);
if (StringUtils.isBlank(boost_mode)) {
boost_mode = Constants.boost_mode;
}
FunctionScoreQueryBuilder functionScoreQ = QueryBuilders.functionScoreQuery(boolQ);
functionScoreQ.boostMode(boost_mode);
for (ScoreScript scoreScript : request.getSafeScoreScript()) {
ScriptScoreFunctionBuilder builder = ScoreFunctionBuilders.scriptFunction(scoreScript
.getScript());
if (scoreScript.getScriptParams() != null && scoreScript.getScriptParams().size() > 0) {
builder.params(scoreScript.getScriptParams());
}
functionScoreQ.add(builder);
}
srb.setQuery(functionScoreQ);
return functionScoreQ;
}
示例2: scriptFunction
import org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionBuilder; //导入依赖的package包/类
public static ScriptScoreFunctionBuilder scriptFunction(Script script) {
return (new ScriptScoreFunctionBuilder(script));
}
示例3: getQueryBuilder
import org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionBuilder; //导入依赖的package包/类
protected QueryBuilder getQueryBuilder(SearchCriteria searchCriteria)
{
QueryBuilder matchQueryBuilder = null;
String queryString = searchCriteria.getQuery();
if (StringUtils.isBlank(queryString))
{
matchQueryBuilder = QueryBuilders.matchAllQuery();
}
else
{
final String filterSpecialCharsQueryString = escapeQueryChars(queryString);
final QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryString(filterSpecialCharsQueryString);
// Add fields
queryStringQueryBuilder.field(SearchDocumentFieldName.TITLE.getFieldName(), (float) 0.5)
.field(SearchDocumentFieldName.DESCRIPTION.getFieldName(), (float) 0.15)
;
for (final String contentCategoryFieldName : SearchFacetName.categoryFacetFields)
{
queryStringQueryBuilder.field(SearchDocumentFieldName.CATEGORIES_ARRAY.getFieldName() + "."
+ contentCategoryFieldName, 1);
}
matchQueryBuilder = queryStringQueryBuilder;
}
if(searchCriteria.isUseBoostingFactor())
{
FunctionScoreQueryBuilder queryBuilder = new FunctionScoreQueryBuilder(matchQueryBuilder);
ScoreFunctionBuilder scoreFunctionBuilder = new ScriptScoreFunctionBuilder().script(SearchDocumentFieldName
.getCalculatedScoreScriptForBostFactor());
queryBuilder.add(scoreFunctionBuilder);
return queryBuilder;
}
return matchQueryBuilder;
}
示例4: getQueryBuilder
import org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionBuilder; //导入依赖的package包/类
protected QueryBuilder getQueryBuilder(final SearchCriteria searchCriteria)
{
QueryBuilder matchQueryBuilder = null;
final String queryString = searchCriteria.getQuery();
if (StringUtils.isBlank(queryString))
{
matchQueryBuilder = QueryBuilders.matchAllQuery();
}
else
{
final String filterSpecialCharsQueryString = escapeQueryChars(queryString);
final QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders.queryString(filterSpecialCharsQueryString);
// Add fields
queryStringQueryBuilder.field(SearchDocumentFieldName.TITLE.getFieldName(), (float) 0.5).field(
SearchDocumentFieldName.DESCRIPTION.getFieldName(), (float) 0.15);
for (final String contentCategoryFieldName : SearchFacetName.categoryFacetFields)
{
queryStringQueryBuilder.field(SearchDocumentFieldName.CATEGORIES_ARRAY.getFieldName() + "." + contentCategoryFieldName, 1);
}
matchQueryBuilder = queryStringQueryBuilder;
}
if (searchCriteria.isUseBoostingFactor())
{
final FunctionScoreQueryBuilder queryBuilder = new FunctionScoreQueryBuilder(matchQueryBuilder);
final ScoreFunctionBuilder scoreFunctionBuilder = new ScriptScoreFunctionBuilder().script(SearchDocumentFieldName
.getCalculatedScoreScriptForBostFactor());
queryBuilder.add(scoreFunctionBuilder);
return queryBuilder;
}
return matchQueryBuilder;
}
示例5: addBoostForChildren
import org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionBuilder; //导入依赖的package包/类
public ElasticSearchPlaceQuery addBoostForChildren() {
// places with many children should get a higher score
queryBuilder = QueryBuilders.functionScoreQuery(queryBuilder)
.add(new ScriptScoreFunctionBuilder().script("_score + (1.0 - 1.0 / ( 0.001 * doc['children'].value + 1.0 ) )").lang("groovy"));
return this;
}
示例6: getQueryBuilder
import org.elasticsearch.index.query.functionscore.script.ScriptScoreFunctionBuilder; //导入依赖的package包/类
protected QueryBuilder getQueryBuilder(final SearchCriteria searchCriteria) {
QueryBuilder matchQueryBuilder = null;
final String queryString = searchCriteria.getQuery();
if (StringUtils.isBlank(queryString)) {
matchQueryBuilder = QueryBuilders.matchAllQuery();
} else {
final String filterSpecialCharsQueryString = escapeQueryChars(queryString);
final QueryStringQueryBuilder queryStringQueryBuilder = QueryBuilders
.queryString(filterSpecialCharsQueryString);
// Add fields
queryStringQueryBuilder.field(
SearchDocumentFieldName.TITLE.getFieldName(), (float) 0.5)
.field(SearchDocumentFieldName.DESCRIPTION.getFieldName(),
(float) 0.15);
for (final String contentCategoryFieldName : SearchFacetName.categoryFacetFields) {
queryStringQueryBuilder.field(
SearchDocumentFieldName.CATEGORIES_ARRAY.getFieldName()
+ "." + contentCategoryFieldName, 1);
}
matchQueryBuilder = queryStringQueryBuilder;
}
if (searchCriteria.isUseBoostingFactor()) {
final FunctionScoreQueryBuilder queryBuilder = new FunctionScoreQueryBuilder(
matchQueryBuilder);
final ScoreFunctionBuilder scoreFunctionBuilder = new ScriptScoreFunctionBuilder()
.script(SearchDocumentFieldName
.getCalculatedScoreScriptForBostFactor());
queryBuilder.add(scoreFunctionBuilder);
return queryBuilder;
}
return matchQueryBuilder;
}