Core: Cleanup non nested filter to not flip the bits in the FixedBitSet returned by the wrapped filter.
If the filter producing the FBS were to be cached then it would flip bits each time the NonNestedDocsFilter was executed. In our case we cache the NonNestedDocsFilter itself so that didn't happen each time this filter was used. However the hashcode of NonNestedDocsFilter and NestedDocsFilter was the same, since NonNestedDocsFilter directly used NestedDocsFilter#hashCode() Closes #8227 Closes #8232
This commit is contained in:
parent
da70b5c847
commit
35ede09511
|
@ -30,16 +30,19 @@ import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter that returns all nested documents.
|
||||||
|
* A nested document is a sub documents that belong to a root document.
|
||||||
|
* Nested documents share the unique id and type and optionally the _source with root documents.
|
||||||
|
*/
|
||||||
public class NestedDocsFilter extends Filter {
|
public class NestedDocsFilter extends Filter {
|
||||||
|
|
||||||
public static final NestedDocsFilter INSTANCE = new NestedDocsFilter();
|
public static final NestedDocsFilter INSTANCE = new NestedDocsFilter();
|
||||||
|
|
||||||
private final PrefixFilter filter = new PrefixFilter(new Term(TypeFieldMapper.NAME, new BytesRef("__")));
|
private final Filter filter = nestedFilter();
|
||||||
|
|
||||||
private final int hashCode = filter.hashCode();
|
private final int hashCode = filter.hashCode();
|
||||||
|
|
||||||
private NestedDocsFilter() {
|
private NestedDocsFilter() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -56,4 +59,9 @@ public class NestedDocsFilter extends Filter {
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return obj == INSTANCE;
|
return obj == INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Filter nestedFilter() {
|
||||||
|
return new PrefixFilter(new Term(TypeFieldMapper.NAME, new BytesRef("__")));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -20,40 +20,30 @@
|
||||||
package org.elasticsearch.index.search.nested;
|
package org.elasticsearch.index.search.nested;
|
||||||
|
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicReaderContext;
|
||||||
import org.apache.lucene.index.Term;
|
|
||||||
import org.apache.lucene.search.DocIdSet;
|
import org.apache.lucene.search.DocIdSet;
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.search.PrefixFilter;
|
|
||||||
import org.apache.lucene.util.Bits;
|
import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.elasticsearch.common.lucene.search.NotFilter;
|
||||||
import org.apache.lucene.util.FixedBitSet;
|
|
||||||
import org.elasticsearch.common.lucene.docset.DocIdSets;
|
|
||||||
import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A filter that returns all root (non nested) documents.
|
||||||
|
* Root documents have an unique id, a type and optionally have a _source and other indexed and stored fields.
|
||||||
|
*/
|
||||||
public class NonNestedDocsFilter extends Filter {
|
public class NonNestedDocsFilter extends Filter {
|
||||||
|
|
||||||
public static final NonNestedDocsFilter INSTANCE = new NonNestedDocsFilter();
|
public static final NonNestedDocsFilter INSTANCE = new NonNestedDocsFilter();
|
||||||
|
|
||||||
private final PrefixFilter filter = new PrefixFilter(new Term(TypeFieldMapper.NAME, new BytesRef("__")));
|
private final Filter filter = new NotFilter(NestedDocsFilter.nestedFilter());
|
||||||
|
|
||||||
private final int hashCode = filter.hashCode();
|
private final int hashCode = filter.hashCode();
|
||||||
|
|
||||||
private NonNestedDocsFilter() {
|
private NonNestedDocsFilter() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
|
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
|
||||||
DocIdSet docSet = filter.getDocIdSet(context, acceptDocs);
|
return filter.getDocIdSet(context, acceptDocs);
|
||||||
if (DocIdSets.isEmpty(docSet)) {
|
|
||||||
// will almost never happen, and we need an OpenBitSet for the parent filter in
|
|
||||||
// BlockJoinQuery, we cache it anyhow...
|
|
||||||
docSet = new FixedBitSet(context.reader().maxDoc());
|
|
||||||
}
|
|
||||||
((FixedBitSet) docSet).flip(0, context.reader().maxDoc());
|
|
||||||
return docSet;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue