当前位置: 首页>>代码示例>>Java>>正文


Java FunctionScoreQueryBuilder.add方法代码示例

本文整理汇总了Java中org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.add方法的典型用法代码示例。如果您正苦于以下问题:Java FunctionScoreQueryBuilder.add方法的具体用法?Java FunctionScoreQueryBuilder.add怎么用?Java FunctionScoreQueryBuilder.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder的用法示例。


在下文中一共展示了FunctionScoreQueryBuilder.add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: makeQueryBuilder

import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; //导入方法依赖的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;
}
 
开发者ID:hailin0,项目名称:es-service-parent,代码行数:44,代码来源:EsQueryBuilder.java

示例2: getQueryBuilder

import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; //导入方法依赖的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;
}
 
开发者ID:jaibeermalik,项目名称:elasticsearch-tutorial,代码行数:41,代码来源:ProductQueryServiceImpl.java

示例3: getQueryBuilder

import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; //导入方法依赖的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;
}
 
开发者ID:jaibeermalik,项目名称:elasticsearch-akka,代码行数:32,代码来源:ProductQueryServiceImpl.java

示例4: getQueryBuilder

import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder; //导入方法依赖的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;
}
 
开发者ID:jaibeermalik,项目名称:searchanalytics-bigdata,代码行数:33,代码来源:ProductQueryServiceImpl.java


注:本文中的org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。