本文整理汇总了Java中org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ScoreFunctionBuilder类的具体用法?Java ScoreFunctionBuilder怎么用?Java ScoreFunctionBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScoreFunctionBuilder类属于org.elasticsearch.index.query.functionscore包,在下文中一共展示了ScoreFunctionBuilder类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testScore
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder; //导入依赖的package包/类
public void testScore() throws Exception {
createIndex("test");
ensureGreen("test");
indexRandom(true,
client().prepareIndex("test", "doc", "1").setSource("text", "hello goodbye"),
client().prepareIndex("test", "doc", "2").setSource("text", "hello hello hello goodbye"),
client().prepareIndex("test", "doc", "3").setSource("text", "hello hello goodebye"));
ScoreFunctionBuilder<?> score = ScoreFunctionBuilders.scriptFunction(new Script(ScriptType.INLINE, "expression", "1 / _score", Collections.emptyMap()));
SearchRequestBuilder req = client().prepareSearch().setIndices("test");
req.setQuery(QueryBuilders.functionScoreQuery(QueryBuilders.termQuery("text", "hello"), score).boostMode(CombineFunction.REPLACE));
req.setSearchType(SearchType.DFS_QUERY_THEN_FETCH); // make sure DF is consistent
SearchResponse rsp = req.get();
assertSearchResponse(rsp);
SearchHits hits = rsp.getHits();
assertEquals(3, hits.getTotalHits());
assertEquals("1", hits.getAt(0).getId());
assertEquals("3", hits.getAt(1).getId());
assertEquals("2", hits.getAt(2).getId());
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:MoreExpressionTests.java
示例2: registerScoreFunctions
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder; //导入依赖的package包/类
private void registerScoreFunctions(List<SearchPlugin> plugins) {
registerScoreFunction(new ScoreFunctionSpec<>(ScriptScoreFunctionBuilder.NAME, ScriptScoreFunctionBuilder::new,
ScriptScoreFunctionBuilder::fromXContent));
registerScoreFunction(
new ScoreFunctionSpec<>(GaussDecayFunctionBuilder.NAME, GaussDecayFunctionBuilder::new, GaussDecayFunctionBuilder.PARSER));
registerScoreFunction(new ScoreFunctionSpec<>(LinearDecayFunctionBuilder.NAME, LinearDecayFunctionBuilder::new,
LinearDecayFunctionBuilder.PARSER));
registerScoreFunction(new ScoreFunctionSpec<>(ExponentialDecayFunctionBuilder.NAME, ExponentialDecayFunctionBuilder::new,
ExponentialDecayFunctionBuilder.PARSER));
registerScoreFunction(new ScoreFunctionSpec<>(RandomScoreFunctionBuilder.NAME, RandomScoreFunctionBuilder::new,
RandomScoreFunctionBuilder::fromXContent));
registerScoreFunction(new ScoreFunctionSpec<>(FieldValueFactorFunctionBuilder.NAME, FieldValueFactorFunctionBuilder::new,
FieldValueFactorFunctionBuilder::fromXContent));
//weight doesn't have its own parser, so every function supports it out of the box.
//Can be a single function too when not associated to any other function, which is why it needs to be registered manually here.
namedWriteables.add(new NamedWriteableRegistry.Entry(ScoreFunctionBuilder.class, WeightBuilder.NAME, WeightBuilder::new));
registerFromPlugin(plugins, SearchPlugin::getScoreFunctions, this::registerScoreFunction);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:SearchModule.java
示例3: registerScoreFunction
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder; //导入依赖的package包/类
private void registerScoreFunction(ScoreFunctionSpec<?> scoreFunction) {
namedWriteables.add(new NamedWriteableRegistry.Entry(
ScoreFunctionBuilder.class, scoreFunction.getName().getPreferredName(), scoreFunction.getReader()));
// TODO remove funky contexts
namedXContents.add(new NamedXContentRegistry.Entry(
ScoreFunctionBuilder.class, scoreFunction.getName(),
(XContentParser p, Object c) -> scoreFunction.getParser().fromXContent((QueryParseContext) c)));
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:SearchModule.java
示例4: getQueryBuilder
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder; //导入依赖的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
示例5: getQueryBuilder
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder; //导入依赖的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
示例6: getQueryBuilder
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder; //导入依赖的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
示例7: setWeight
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder; //导入依赖的package包/类
@Override
public ScoreFunctionBuilder setWeight(float weight) {
throw new IllegalArgumentException(BoostScoreFunction.BOOST_WEIGHT_ERROR_MESSAGE);
}
开发者ID:baidu,项目名称:Elasticsearch,代码行数:5,代码来源:FactorBuilder.java
示例8: functionScoreQuery
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder; //导入依赖的package包/类
/**
* A query that allows to define a custom scoring function.
*
* @param function The function builder used to custom score
*/
public static FunctionScoreQueryBuilder functionScoreQuery(ScoreFunctionBuilder function) {
return new FunctionScoreQueryBuilder(function);
}
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:QueryBuilders.java
注:本文中的org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论