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