static String reason(BitDocIdSet actual, BitDocIdSet expected, IndexSearcher indexSearcher) throws IOException { StringBuilder builder = new StringBuilder(); builder.append("expected cardinality:").append(expected.bits().cardinality()).append('\n'); DocIdSetIterator iterator = expected.iterator(); for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) { builder .append("Expected doc[") .append(doc) .append("] with id value ") .append(indexSearcher.doc(doc).get(UidFieldMapper.NAME)) .append('\n'); } builder.append("actual cardinality: ").append(actual.bits().cardinality()).append('\n'); iterator = actual.iterator(); for (int doc = iterator.nextDoc(); doc != DocIdSetIterator.NO_MORE_DOCS; doc = iterator.nextDoc()) { builder .append("Actual doc[") .append(doc) .append("] with id value ") .append(indexSearcher.doc(doc).get(UidFieldMapper.NAME)) .append('\n'); } return builder.toString(); }
private int findRootDocumentIfNested( SearchContext context, LeafReaderContext subReaderContext, int subDocId) throws IOException { if (context.mapperService().hasNested()) { BitDocIdSet nonNested = context .bitsetFilterCache() .getBitDocIdSetFilter(Queries.newNonNestedFilter()) .getDocIdSet(subReaderContext); BitSet bits = nonNested.bits(); if (!bits.get(subDocId)) { return bits.nextSetBit(subDocId); } } return -1; }
@Override public FieldComparator<Object> setNextReader(LeafReaderContext context) throws IOException { BitDocIdSet children = childFilter.getDocIdSet(context); if (children == null) { childDocuments = null; } else { childDocuments = children.bits(); } BitDocIdSet parents = parentFilter.getDocIdSet(context); if (parents == null) { parentDocuments = null; } else { parentDocuments = parents.bits(); } wrappedComparator = wrappedComparator.setNextReader(context); return this; }
static boolean equals(BitDocIdSet expected, BitDocIdSet actual) { if (actual == null && expected == null) { return true; } else if (actual == null || expected == null) { return false; } BitSet actualBits = actual.bits(); BitSet expectedBits = expected.bits(); if (actualBits.length() != expectedBits.length()) { return false; } for (int i = 0; i < expectedBits.length(); i++) { if (expectedBits.get(i) != actualBits.get(i)) { return false; } } return true; }
private InternalSearchHit.InternalNestedIdentity getInternalNestedIdentity( SearchContext context, int nestedSubDocId, LeafReaderContext subReaderContext, DocumentMapper documentMapper, ObjectMapper nestedObjectMapper) throws IOException { int currentParent = nestedSubDocId; ObjectMapper nestedParentObjectMapper; StringBuilder field = new StringBuilder(); ObjectMapper current = nestedObjectMapper; InternalSearchHit.InternalNestedIdentity nestedIdentity = null; do { Filter parentFilter; nestedParentObjectMapper = documentMapper.findParentObjectMapper(current); if (field.length() != 0) { field.insert(0, '.'); } field.insert(0, current.name()); if (nestedParentObjectMapper != null) { if (nestedParentObjectMapper.nested().isNested() == false) { current = nestedParentObjectMapper; continue; } parentFilter = nestedParentObjectMapper.nestedTypeFilter(); } else { parentFilter = Queries.newNonNestedFilter(); } Filter childFilter = nestedObjectMapper.nestedTypeFilter(); if (childFilter == null) { current = nestedParentObjectMapper; continue; } // We can pass down 'null' as acceptedDocs, because we're fetching matched docId that matched // in the query phase. DocIdSet childDocSet = childFilter.getDocIdSet(subReaderContext, null); if (childDocSet == null) { current = nestedParentObjectMapper; continue; } DocIdSetIterator childIter = childDocSet.iterator(); if (childIter == null) { current = nestedParentObjectMapper; continue; } BitDocIdSet parentBitSet = context .bitsetFilterCache() .getBitDocIdSetFilter(parentFilter) .getDocIdSet(subReaderContext); BitSet parentBits = parentBitSet.bits(); int offset = 0; int nextParent = parentBits.nextSetBit(currentParent); for (int docId = childIter.advance(currentParent + 1); docId < nextParent && docId != DocIdSetIterator.NO_MORE_DOCS; docId = childIter.nextDoc()) { offset++; } currentParent = nextParent; current = nestedObjectMapper = nestedParentObjectMapper; nestedIdentity = new InternalSearchHit.InternalNestedIdentity(field.toString(), offset, nestedIdentity); field = new StringBuilder(); } while (current != null); return nestedIdentity; }