mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-26 06:46:10 +00:00
lucene 4: cleanup terms/uid filter
This commit is contained in:
parent
79368bb221
commit
0660e20c47
@ -28,6 +28,7 @@ import org.elasticsearch.common.lucene.search.NotDeletedFilter;
|
|||||||
// So it can basically be cached safely even with a reader that changes deletions but remain with teh same cache key
|
// So it can basically be cached safely even with a reader that changes deletions but remain with teh same cache key
|
||||||
// See more: https://issues.apache.org/jira/browse/LUCENE-2468
|
// See more: https://issues.apache.org/jira/browse/LUCENE-2468
|
||||||
// TODO Lucene 4.0 won't need this, since live docs are "and'ed" while scoring
|
// TODO Lucene 4.0 won't need this, since live docs are "and'ed" while scoring
|
||||||
|
// LUCENE 4 UPGRADE: we probably don't need this anymore, because of acceptDocs
|
||||||
public class DeletionAwareConstantScoreQuery extends ConstantScoreQuery {
|
public class DeletionAwareConstantScoreQuery extends ConstantScoreQuery {
|
||||||
|
|
||||||
private final Filter actualFilter;
|
private final Filter actualFilter;
|
||||||
|
@ -19,13 +19,7 @@
|
|||||||
|
|
||||||
package org.apache.lucene.search;
|
package org.apache.lucene.search;
|
||||||
|
|
||||||
import org.apache.lucene.index.AtomicReader;
|
import org.apache.lucene.index.*;
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
|
||||||
import org.apache.lucene.index.DocsEnum;
|
|
||||||
import org.apache.lucene.index.Fields;
|
|
||||||
import org.apache.lucene.index.Term;
|
|
||||||
import org.apache.lucene.index.Terms;
|
|
||||||
import org.apache.lucene.index.TermsEnum;
|
|
||||||
import org.apache.lucene.queries.TermsFilter;
|
import org.apache.lucene.queries.TermsFilter;
|
||||||
import org.apache.lucene.util.Bits;
|
import org.apache.lucene.util.Bits;
|
||||||
import org.apache.lucene.util.BytesRef;
|
import org.apache.lucene.util.BytesRef;
|
||||||
@ -39,7 +33,8 @@ import java.util.Collection;
|
|||||||
* Similar to {@link TermsFilter} but stores the terms in an array for better memory usage
|
* Similar to {@link TermsFilter} but stores the terms in an array for better memory usage
|
||||||
* when cached, and also uses bulk read
|
* when cached, and also uses bulk read
|
||||||
*/
|
*/
|
||||||
// LUCENE MONITOR: Against TermsFilter - this is now identical to TermsFilter once 4.1 is released
|
// LUCENE 4 UPGRADE: Make sure to sync this against latest 4.1
|
||||||
|
// LUCENE 4.1: once its out, we can use TermsFilter from it
|
||||||
public class XTermsFilter extends Filter {
|
public class XTermsFilter extends Filter {
|
||||||
|
|
||||||
private final Term[] filterTerms;
|
private final Term[] filterTerms;
|
||||||
|
@ -166,7 +166,7 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||||||
if (indexed() || context == null) {
|
if (indexed() || context == null) {
|
||||||
return super.fieldQuery(value, context);
|
return super.fieldQuery(value, context);
|
||||||
}
|
}
|
||||||
UidFilter filter = new UidFilter(context.queryTypes(), ImmutableList.of(value), context.indexCache().bloomCache());
|
UidFilter filter = new UidFilter(context.queryTypes(), ImmutableList.of(value));
|
||||||
// no need for constant score filter, since we don't cache the filter, and it always takes deletes into account
|
// no need for constant score filter, since we don't cache the filter, and it always takes deletes into account
|
||||||
return new ConstantScoreQuery(filter);
|
return new ConstantScoreQuery(filter);
|
||||||
}
|
}
|
||||||
@ -176,7 +176,7 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||||||
if (indexed() || context == null) {
|
if (indexed() || context == null) {
|
||||||
return super.fieldFilter(value, context);
|
return super.fieldFilter(value, context);
|
||||||
}
|
}
|
||||||
return new UidFilter(context.queryTypes(), ImmutableList.of(value), context.indexCache().bloomCache());
|
return new UidFilter(context.queryTypes(), ImmutableList.of(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -19,11 +19,7 @@
|
|||||||
|
|
||||||
package org.elasticsearch.index.search;
|
package org.elasticsearch.index.search;
|
||||||
|
|
||||||
import org.apache.lucene.index.AtomicReader;
|
import org.apache.lucene.index.*;
|
||||||
import org.apache.lucene.index.AtomicReaderContext;
|
|
||||||
import org.apache.lucene.index.DocsEnum;
|
|
||||||
import org.apache.lucene.index.Term;
|
|
||||||
import org.apache.lucene.index.TermsEnum;
|
|
||||||
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.util.Bits;
|
import org.apache.lucene.util.Bits;
|
||||||
@ -36,9 +32,11 @@ import java.util.Arrays;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
// LUCENE 4 UPGRADE: we can potentially use TermsFilter here, specifically, now when we don't do bloom filter, batching, and with optimization on single field terms
|
||||||
public class UidFilter extends Filter {
|
public class UidFilter extends Filter {
|
||||||
|
|
||||||
final Term[] uids;
|
final Term[] uids;
|
||||||
|
|
||||||
public UidFilter(Collection<String> types, List<String> ids) {
|
public UidFilter(Collection<String> types, List<String> ids) {
|
||||||
this.uids = new Term[types.size() * ids.size()];
|
this.uids = new Term[types.size() * ids.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -60,7 +58,6 @@ public class UidFilter extends Filter {
|
|||||||
// - If we have a single id, we can create a SingleIdDocIdSet to save on mem
|
// - If we have a single id, we can create a SingleIdDocIdSet to save on mem
|
||||||
// - We can use sorted int array DocIdSet to reserve memory compared to OpenBitSet in some cases
|
// - We can use sorted int array DocIdSet to reserve memory compared to OpenBitSet in some cases
|
||||||
@Override
|
@Override
|
||||||
// LUCENE 4 UPGRADE: this filter does respect acceptDocs maybe we need to change this
|
|
||||||
public DocIdSet getDocIdSet(AtomicReaderContext ctx, Bits acceptedDocs) throws IOException {
|
public DocIdSet getDocIdSet(AtomicReaderContext ctx, Bits acceptedDocs) throws IOException {
|
||||||
FixedBitSet set = null;
|
FixedBitSet set = null;
|
||||||
final AtomicReader reader = ctx.reader();
|
final AtomicReader reader = ctx.reader();
|
||||||
@ -71,8 +68,6 @@ public class UidFilter extends Filter {
|
|||||||
docsEnum = termsEnum.docs(acceptedDocs, docsEnum, 0);
|
docsEnum = termsEnum.docs(acceptedDocs, docsEnum, 0);
|
||||||
int doc;
|
int doc;
|
||||||
while ((doc = docsEnum.nextDoc()) != DocsEnum.NO_MORE_DOCS) {
|
while ((doc = docsEnum.nextDoc()) != DocsEnum.NO_MORE_DOCS) {
|
||||||
// no need for batching, its on the UID, there will be only
|
|
||||||
// one doc
|
|
||||||
if (set == null) {
|
if (set == null) {
|
||||||
set = new FixedBitSet(reader.maxDoc());
|
set = new FixedBitSet(reader.maxDoc());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user