本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}