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


Java SearchContext.current方法代码示例

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


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

示例1: parse

import org.elasticsearch.search.internal.SearchContext; //导入方法依赖的package包/类
public InnerHitsSubSearchContext parse(QueryParseContext parserContext) throws IOException, QueryParsingException {
    String fieldName = null;
    XContentParser.Token token;
    String innerHitName = null;
    SubSearchContext subSearchContext = new SubSearchContext(SearchContext.current());
    try {
        XContentParser parser = parserContext.parser();
        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            if (token == XContentParser.Token.FIELD_NAME) {
                fieldName = parser.currentName();
            } else if (token.isValue()) {
                if ("name".equals(fieldName)) {
                    innerHitName = parser.textOrNull();
                } else {
                    parseCommonInnerHitOptions(parser, token, fieldName, subSearchContext, sortParseElement, sourceParseElement, highlighterParseElement, scriptFieldsParseElement, fieldDataFieldsParseElement);
                }
            } else {
                parseCommonInnerHitOptions(parser, token, fieldName, subSearchContext, sortParseElement, sourceParseElement, highlighterParseElement, scriptFieldsParseElement, fieldDataFieldsParseElement);
            }
        }
    } catch (Exception e) {
        throw new QueryParsingException(parserContext, "Failed to parse [_inner_hits]", e);
    }
    return new InnerHitsSubSearchContext(innerHitName, subSearchContext);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:26,代码来源:InnerHitsQueryParserHelper.java

示例2: addInnerHits

import org.elasticsearch.search.internal.SearchContext; //导入方法依赖的package包/类
public void addInnerHits(String name, InnerHitsContext.BaseInnerHits context) {
    SearchContext sc = SearchContext.current();
    if (sc == null) {
        throw new QueryParsingException(this, "inner_hits unsupported");
    }

    InnerHitsContext innerHitsContext = sc.innerHits();
    innerHitsContext.addInnerHitDefinition(name, context);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:10,代码来源:QueryParseContext.java

示例3: nowInMillis

import org.elasticsearch.search.internal.SearchContext; //导入方法依赖的package包/类
public long nowInMillis() {
    SearchContext current = SearchContext.current();
    if (current != null) {
        return current.nowInMillis();
    }
    return System.currentTimeMillis();
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:8,代码来源:QueryParseContext.java

示例4: doCreateWeight

import org.elasticsearch.search.internal.SearchContext; //导入方法依赖的package包/类
@Override
public Weight doCreateWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    SearchContext sc = SearchContext.current();
    ChildWeight childWeight;
    boolean releaseCollectorResource = true;
    ParentOrdAndScoreCollector collector = null;
    IndexParentChildFieldData globalIfd = parentChildIndexFieldData.loadGlobal((DirectoryReader)searcher.getIndexReader());
    if (globalIfd == null) {
        // No docs of the specified type don't exist on this shard
        return new BooleanQuery.Builder().build().createWeight(searcher, needsScores);
    }

    try {
        collector = new ParentOrdAndScoreCollector(sc, globalIfd, parentType);
        searcher.search(parentQuery, collector);
        if (collector.parentCount() == 0) {
            return new BooleanQuery.Builder().build().createWeight(searcher, needsScores);
        }
        childWeight = new ChildWeight(this, parentQuery.createWeight(searcher, needsScores), childrenFilter, collector, globalIfd);
        releaseCollectorResource = false;
    } finally {
        if (releaseCollectorResource) {
            // either if we run into an exception or if we return early
            Releasables.close(collector);
        }
    }
    sc.addReleasable(collector, Lifetime.COLLECTION);
    return childWeight;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:30,代码来源:ParentQuery.java

示例5: doCreateWeight

import org.elasticsearch.search.internal.SearchContext; //导入方法依赖的package包/类
@Override
public Weight doCreateWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    SearchContext sc = SearchContext.current();
    IndexParentChildFieldData globalIfd = parentChildIndexFieldData.loadGlobal((DirectoryReader)searcher.getIndexReader());

    final long valueCount;
    List<LeafReaderContext> leaves = searcher.getIndexReader().leaves();
    if (globalIfd == null || leaves.isEmpty()) {
        return new BooleanQuery.Builder().build().createWeight(searcher, needsScores);
    } else {
        AtomicParentChildFieldData afd = globalIfd.load(leaves.get(0));
        SortedDocValues globalValues = afd.getOrdinalsValues(parentType);
        valueCount = globalValues.getValueCount();
    }

    if (valueCount == 0) {
        return new BooleanQuery.Builder().build().createWeight(searcher, needsScores);
    }

    ParentOrdCollector collector = new ParentOrdCollector(globalIfd, valueCount, parentType);
    searcher.search(childQuery, collector);

    final long remaining = collector.foundParents();
    if (remaining == 0) {
        return new BooleanQuery.Builder().build().createWeight(searcher, needsScores);
    }

    Filter shortCircuitFilter = null;
    if (remaining <= shortCircuitParentDocSet) {
        shortCircuitFilter = ParentIdsFilter.createShortCircuitFilter(
                nonNestedDocsFilter, sc, parentType, collector.values, collector.parentOrds, remaining
        );
    }
    return new ParentWeight(this, parentFilter, globalIfd, shortCircuitFilter, collector, remaining);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:36,代码来源:ChildrenConstantScoreQuery.java

示例6: valueForSearch

import org.elasticsearch.search.internal.SearchContext; //导入方法依赖的package包/类
@Override
public Object valueForSearch(Object value) {
    long now;
    SearchContext searchContext = SearchContext.current();
    if (searchContext != null) {
        now = searchContext.nowInMillis();
    } else {
        now = System.currentTimeMillis();
    }
    long val = value(value);
    return val - now;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:13,代码来源:TTLFieldMapper.java

示例7: now

import org.elasticsearch.search.internal.SearchContext; //导入方法依赖的package包/类
private static Callable<Long> now() {
    return new Callable<Long>() {
        @Override
        public Long call() {
            final SearchContext context = SearchContext.current();
            return context != null
                ? context.nowInMillis()
                : System.currentTimeMillis();
        }
    };
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:12,代码来源:DateFieldMapper.java

示例8: parse

import org.elasticsearch.search.internal.SearchContext; //导入方法依赖的package包/类
@Override
public ScoreFunction parse(QueryParseContext parseContext, XContentParser parser) throws IOException, QueryParsingException {

    String currentFieldName = null;
    String field = null;
    float boostFactor = 1;
    FieldValueFactorFunction.Modifier modifier = FieldValueFactorFunction.Modifier.NONE;
    Double missing = null;
    XContentParser.Token token;
    while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
        if (token == XContentParser.Token.FIELD_NAME) {
            currentFieldName = parser.currentName();
        } else if (token.isValue()) {
            if ("field".equals(currentFieldName)) {
                field = parser.text();
            } else if ("factor".equals(currentFieldName)) {
                boostFactor = parser.floatValue();
            } else if ("modifier".equals(currentFieldName)) {
                modifier = FieldValueFactorFunction.Modifier.valueOf(parser.text().toUpperCase(Locale.ROOT));
            } else if ("missing".equals(currentFieldName)) {
                missing = parser.doubleValue();
            } else {
                throw new QueryParsingException(parseContext, NAMES[0] + " query does not support [" + currentFieldName + "]");
            }
        } else if("factor".equals(currentFieldName) && (token == XContentParser.Token.START_ARRAY || token == XContentParser.Token.START_OBJECT)) {
            throw new QueryParsingException(parseContext, "[" + NAMES[0] + "] field 'factor' does not support lists or objects");
        }
    }

    if (field == null) {
        throw new QueryParsingException(parseContext, "[" + NAMES[0] + "] required field 'field' missing");
    }

    SearchContext searchContext = SearchContext.current();
    MappedFieldType fieldType = searchContext.mapperService().smartNameFieldType(field);
    IndexNumericFieldData fieldData = null;
    if (fieldType == null) {
        if(missing == null) {
            throw new ElasticsearchException("Unable to find a field mapper for field [" + field + "]. No 'missing' value defined.");
        }
    } else {
        fieldData = searchContext.fieldData().getForField(fieldType);
    }
    return new FieldValueFactorFunction(field, boostFactor, modifier, missing, fieldData);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:46,代码来源:FieldValueFactorFunctionParser.java

示例9: doCreateWeight

import org.elasticsearch.search.internal.SearchContext; //导入方法依赖的package包/类
@Override
public Weight doCreateWeight(IndexSearcher searcher, boolean needsScores) throws IOException {
    SearchContext sc = SearchContext.current();

    IndexParentChildFieldData globalIfd = ifd.loadGlobal((DirectoryReader)searcher.getIndexReader());
    if (globalIfd == null) {
        // No docs of the specified type exist on this shard
        return new BooleanQuery.Builder().build().createWeight(searcher, needsScores);
    }

    boolean abort = true;
    long numFoundParents;
    ParentCollector collector = null;
    try {
        if (minChildren == 0 && maxChildren == 0 && scoreType != ScoreType.NONE) {
            switch (scoreType) {
            case MIN:
                collector = new MinCollector(globalIfd, sc, parentType);
                break;
            case MAX:
                collector = new MaxCollector(globalIfd, sc, parentType);
                break;
            case SUM:
                collector = new SumCollector(globalIfd, sc, parentType);
                break;
            }
        }
        if (collector == null) {
            switch (scoreType) {
            case MIN:
                collector = new MinCountCollector(globalIfd, sc, parentType);
                break;
            case MAX:
                collector = new MaxCountCollector(globalIfd, sc, parentType);
                break;
            case SUM:
            case AVG:
                collector = new SumCountAndAvgCollector(globalIfd, sc, parentType);
                break;
            case NONE:
                collector = new CountCollector(globalIfd, sc, parentType);
                break;
            default:
                throw new RuntimeException("Are we missing a score type here? -- " + scoreType);
            }
        }

        searcher.search(childQuery, collector);
        numFoundParents = collector.foundParents();
        if (numFoundParents == 0) {
            return new BooleanQuery.Builder().build().createWeight(searcher, needsScores);
        }
        abort = false;
    } finally {
        if (abort) {
            Releasables.close(collector);
        }
    }
    sc.addReleasable(collector, Lifetime.COLLECTION);
    final Filter parentFilter;
    if (numFoundParents <= shortCircuitParentDocSet) {
        parentFilter = ParentIdsFilter.createShortCircuitFilter(nonNestedDocsFilter, sc, parentType, collector.values,
                collector.parentIdxs, numFoundParents);
    } else {
        parentFilter = this.parentFilter;
    }
    return new ParentWeight(this, childQuery.createWeight(searcher, needsScores), parentFilter, numFoundParents, collector, minChildren,
            maxChildren);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:70,代码来源:ChildrenQuery.java


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