本文整理匯總了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());
}