當前位置: 首頁>>代碼示例>>Java>>正文


Java SearchContext.parsedPostFilter方法代碼示例

本文整理匯總了Java中org.elasticsearch.search.internal.SearchContext.parsedPostFilter方法的典型用法代碼示例。如果您正苦於以下問題:Java SearchContext.parsedPostFilter方法的具體用法?Java SearchContext.parsedPostFilter怎麽用?Java SearchContext.parsedPostFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.search.internal.SearchContext的用法示例。


在下文中一共展示了SearchContext.parsedPostFilter方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hitExecute

import org.elasticsearch.search.internal.SearchContext; //導入方法依賴的package包/類
@Override
public void hitExecute(SearchContext context, HitContext hitContext) {
    List<String> matchedQueries = new ArrayList<>(2);

    try {
        addMatchedQueries(hitContext, context.parsedQuery().namedFilters(), matchedQueries);

        if (context.parsedPostFilter() != null) {
            addMatchedQueries(hitContext, context.parsedPostFilter().namedFilters(), matchedQueries);
        }
    } catch (IOException e) {
        throw ExceptionsHelper.convertToElastic(e);
    } finally {
        SearchContext.current().clearReleasables(Lifetime.COLLECTION);
    }

    hitContext.hit().matchedQueries(matchedQueries.toArray(new String[matchedQueries.size()]));
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:19,代碼來源:MatchedQueriesFetchSubPhase.java

示例2: parse

import org.elasticsearch.search.internal.SearchContext; //導入方法依賴的package包/類
@Override
public void parse(XContentParser parser, SearchContext context) throws Exception {
    ParsedQuery postFilter = context.queryParserService().parseInnerFilter(parser);
    if (postFilter != null) {
        context.parsedPostFilter(postFilter);
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:8,代碼來源:PostFilterParseElement.java

示例3: parse

import org.elasticsearch.search.internal.SearchContext; //導入方法依賴的package包/類
@Override
public void parse(XContentParser parser, SearchContext context) throws Exception {
    byte[] filterSource = parser.binaryValue();
    try (XContentParser fSourceParser = XContentFactory.xContent(filterSource).createParser(filterSource)) {
        ParsedQuery filter = context.queryParserService().parseInnerFilter(fSourceParser);
        if (filter != null) {
            context.parsedPostFilter(filter);
        }
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:11,代碼來源:FilterBinaryParseElement.java

示例4: hitsExecute

import org.elasticsearch.search.internal.SearchContext; //導入方法依賴的package包/類
@Override
public void hitsExecute(SearchContext context, SearchHit[] hits) {
    if (hits.length == 0 ||
        // in case the request has only suggest, parsed query is null
        context.parsedQuery() == null) {
        return;
    }
    hits = hits.clone(); // don't modify the incoming hits
    Arrays.sort(hits, (a, b) -> Integer.compare(a.docId(), b.docId()));
    @SuppressWarnings("unchecked")
    List<String>[] matchedQueries = new List[hits.length];
    for (int i = 0; i < matchedQueries.length; ++i) {
        matchedQueries[i] = new ArrayList<>();
    }

    Map<String, Query> namedQueries = new HashMap<>(context.parsedQuery().namedFilters());
    if (context.parsedPostFilter() != null) {
        namedQueries.putAll(context.parsedPostFilter().namedFilters());
    }

    try {
        for (Map.Entry<String, Query> entry : namedQueries.entrySet()) {
            String name = entry.getKey();
            Query query = entry.getValue();
            int readerIndex = -1;
            int docBase = -1;
            Weight weight = context.searcher().createNormalizedWeight(query, false);
            Bits matchingDocs = null;
            final IndexReader indexReader = context.searcher().getIndexReader();
            for (int i = 0; i < hits.length; ++i) {
                SearchHit hit = hits[i];
                int hitReaderIndex = ReaderUtil.subIndex(hit.docId(), indexReader.leaves());
                if (readerIndex != hitReaderIndex) {
                    readerIndex = hitReaderIndex;
                    LeafReaderContext ctx = indexReader.leaves().get(readerIndex);
                    docBase = ctx.docBase;
                    // scorers can be costly to create, so reuse them across docs of the same segment
                    Scorer scorer = weight.scorer(ctx);
                    matchingDocs = Lucene.asSequentialAccessBits(ctx.reader().maxDoc(), scorer);
                }
                if (matchingDocs.get(hit.docId() - docBase)) {
                    matchedQueries[i].add(name);
                }
            }
        }
        for (int i = 0; i < hits.length; ++i) {
            hits[i].matchedQueries(matchedQueries[i].toArray(new String[matchedQueries[i].size()]));
        }
    } catch (IOException e) {
        throw ExceptionsHelper.convertToElastic(e);
    } finally {
        context.clearReleasables(Lifetime.COLLECTION);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:55,代碼來源:MatchedQueriesFetchSubPhase.java

示例5: hitExecutionNeeded

import org.elasticsearch.search.internal.SearchContext; //導入方法依賴的package包/類
@Override
public boolean hitExecutionNeeded(SearchContext context) {
    return !context.parsedQuery().namedFilters().isEmpty()
            || (context.parsedPostFilter() !=null && !context.parsedPostFilter().namedFilters().isEmpty());
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:6,代碼來源:MatchedQueriesFetchSubPhase.java


注:本文中的org.elasticsearch.search.internal.SearchContext.parsedPostFilter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。