Initial parent/child queries cleanup.

This commit is contained in:
Martijn van Groningen 2013-01-31 18:39:31 +01:00
parent 371b071fb7
commit 1f50b07406
10 changed files with 27 additions and 56 deletions

View File

@ -125,7 +125,7 @@ public class HasChildFilterParser implements FilterParser {
SearchContext searchContext = SearchContext.current();
HasChildFilter childFilter = HasChildFilter.create(query, null, parentType, childType, searchContext, executionType);
HasChildFilter childFilter = HasChildFilter.create(query, parentType, childType, searchContext, executionType);
searchContext.addRewrite(childFilter);
if (filterName != null) {

View File

@ -124,11 +124,11 @@ public class HasChildQueryParser implements QueryParser {
Query query;
if (scoreType != null) {
Filter parentFilter = parseContext.cacheFilter(parentDocMapper.typeFilter(), null);
ChildrenQuery childrenQuery = new ChildrenQuery(searchContext, parentType, childType, parentFilter, null, innerQuery, scoreType);
ChildrenQuery childrenQuery = new ChildrenQuery(searchContext, parentType, childType, parentFilter, innerQuery, scoreType);
searchContext.addRewrite(childrenQuery);
query = childrenQuery;
} else {
HasChildFilter hasChildFilter = HasChildFilter.create(innerQuery, null, parentType, childType, searchContext, executionType);
HasChildFilter hasChildFilter = HasChildFilter.create(innerQuery, parentType, childType, searchContext, executionType);
searchContext.addRewrite(hasChildFilter);
query = new ConstantScoreQuery(hasChildFilter);
}

View File

@ -121,7 +121,7 @@ public class HasParentFilterParser implements FilterParser {
SearchContext searchContext = SearchContext.current();
HasParentFilter parentFilter = HasParentFilter.create(executionType, query, null, parentType, searchContext);
HasParentFilter parentFilter = HasParentFilter.create(executionType, query, parentType, searchContext);
searchContext.addRewrite(parentFilter);
if (filterName != null) {

View File

@ -149,11 +149,11 @@ public class HasParentQueryParser implements QueryParser {
SearchContext searchContext = SearchContext.current();
Query query;
if (score) {
ParentQuery parentQuery = new ParentQuery(searchContext, innerQuery, parentType, childTypes, childFilter, null);
ParentQuery parentQuery = new ParentQuery(searchContext, innerQuery, parentType, childTypes, childFilter);
searchContext.addRewrite(parentQuery);
query = parentQuery;
} else {
HasParentFilter hasParentFilter = HasParentFilter.create(executionType, innerQuery, null, parentType, searchContext);
HasParentFilter hasParentFilter = HasParentFilter.create(executionType, innerQuery, parentType, searchContext);
searchContext.addRewrite(hasParentFilter);
query = new ConstantScoreQuery(hasParentFilter);
}

View File

@ -121,7 +121,7 @@ public class TopChildrenQueryParser implements QueryParser {
query = new XFilteredQuery(query, parseContext.cacheFilter(childDocMapper.typeFilter(), null));
SearchContext searchContext = SearchContext.current();
TopChildrenQuery childQuery = new TopChildrenQuery(query, null, childType, parentType, scoreType, factor, incrementalFactor);
TopChildrenQuery childQuery = new TopChildrenQuery(query, childType, parentType, scoreType, factor, incrementalFactor);
searchContext.addRewrite(childQuery);
return childQuery;
}

View File

@ -51,18 +51,16 @@ public class ChildrenQuery extends Query implements SearchContext.Rewrite {
private final String childType;
private final Filter parentFilter;
private final ScoreType scoreType;
private final String scope;
private final Query childQuery;
private TObjectFloatHashMap<HashedBytesArray> uidToScore;
private TObjectIntHashMap<HashedBytesArray> uidToCount;
public ChildrenQuery(SearchContext searchContext, String parentType, String childType, Filter parentFilter, String scope, Query childQuery, ScoreType scoreType) {
public ChildrenQuery(SearchContext searchContext, String parentType, String childType, Filter parentFilter, Query childQuery, ScoreType scoreType) {
this.searchContext = searchContext;
this.parentType = parentType;
this.childType = childType;
this.parentFilter = parentFilter;
this.scope = scope;
this.childQuery = childQuery;
this.scoreType = scoreType;
}
@ -72,7 +70,6 @@ public class ChildrenQuery extends Query implements SearchContext.Rewrite {
this.parentType = unProcessedQuery.parentType;
this.childType = unProcessedQuery.childType;
this.parentFilter = unProcessedQuery.parentFilter;
this.scope = unProcessedQuery.scope;
this.scoreType = unProcessedQuery.scoreType;
this.childQuery = rewrittenChildQuery;

View File

@ -45,27 +45,17 @@ import java.util.Map;
public abstract class HasChildFilter extends Filter implements SearchContext.Rewrite {
final Query childQuery;
final String scope;
final String parentType;
final String childType;
final SearchContext searchContext;
protected HasChildFilter(Query childQuery, String scope, String parentType, String childType, SearchContext searchContext) {
protected HasChildFilter(Query childQuery, String parentType, String childType, SearchContext searchContext) {
this.searchContext = searchContext;
this.parentType = parentType;
this.childType = childType;
this.scope = scope;
this.childQuery = childQuery;
}
public Query query() {
return childQuery;
}
public String scope() {
return scope;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@ -73,12 +63,12 @@ public abstract class HasChildFilter extends Filter implements SearchContext.Rew
return sb.toString();
}
public static HasChildFilter create(Query childQuery, String scope, String parentType, String childType, SearchContext searchContext, String executionType) {
public static HasChildFilter create(Query childQuery, String parentType, String childType, SearchContext searchContext, String executionType) {
// This mechanism is experimental and will most likely be removed.
if ("bitset".equals(executionType)) {
return new Bitset(childQuery, scope, parentType, childType, searchContext);
return new Bitset(childQuery, parentType, childType, searchContext);
} else if ("uid".endsWith(executionType)) {
return new Uid(childQuery, scope, parentType, childType, searchContext);
return new Uid(childQuery, parentType, childType, searchContext);
}
throw new ElasticSearchIllegalStateException("Illegal has_child execution type: " + executionType);
}
@ -87,8 +77,8 @@ public abstract class HasChildFilter extends Filter implements SearchContext.Rew
private Map<Object, FixedBitSet> parentDocs;
public Bitset(Query childQuery, String scope, String parentType, String childType, SearchContext searchContext) {
super(childQuery, scope, parentType, childType, searchContext);
public Bitset(Query childQuery, String parentType, String childType, SearchContext searchContext) {
super(childQuery, parentType, childType, searchContext);
}
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
@ -120,8 +110,8 @@ public abstract class HasChildFilter extends Filter implements SearchContext.Rew
THashSet<HashedBytesArray> collectedUids;
Uid(Query childQuery, String scope, String parentType, String childType, SearchContext searchContext) {
super(childQuery, scope, parentType, childType, searchContext);
Uid(Query childQuery, String parentType, String childType, SearchContext searchContext) {
super(childQuery, parentType, childType, searchContext);
}
public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {

View File

@ -49,38 +49,28 @@ import static com.google.common.collect.Maps.newHashMap;
public abstract class HasParentFilter extends Filter implements SearchContext.Rewrite {
final Query parentQuery;
final String scope;
final String parentType;
final SearchContext context;
HasParentFilter(Query parentQuery, String scope, String parentType, SearchContext context) {
HasParentFilter(Query parentQuery, String parentType, SearchContext context) {
this.parentQuery = parentQuery;
this.scope = scope;
this.parentType = parentType;
this.context = context;
}
public String scope() {
return scope;
}
public Query query() {
return parentQuery;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("parent_filter[").append(parentType).append("](").append(query()).append(')');
sb.append("parent_filter[").append(parentType).append("](").append(parentQuery).append(')');
return sb.toString();
}
public static HasParentFilter create(String executionType, Query query, String scope, String parentType, SearchContext context) {
public static HasParentFilter create(String executionType, Query query, String parentType, SearchContext context) {
// This mechanism is experimental and will most likely be removed.
if ("bitset".equals(executionType)) {
return new Bitset(query, scope, parentType, context);
return new Bitset(query, parentType, context);
} else if ("uid".equals(executionType)) {
return new Uid(query, scope, parentType, context);
return new Uid(query, parentType, context);
}
throw new ElasticSearchIllegalStateException("Illegal has_parent execution type: " + executionType);
}
@ -89,8 +79,8 @@ public abstract class HasParentFilter extends Filter implements SearchContext.Re
THashSet<HashedBytesArray> parents;
Uid(Query query, String scope, String parentType, SearchContext context) {
super(query, scope, parentType, context);
Uid(Query query, String parentType, SearchContext context) {
super(query, parentType, context);
}
public DocIdSet getDocIdSet(AtomicReaderContext readerContext, Bits acceptDocs) throws IOException {
@ -176,8 +166,8 @@ public abstract class HasParentFilter extends Filter implements SearchContext.Re
Map<Object, FixedBitSet> parentDocs;
Bitset(Query query, String scope, String parentType, SearchContext context) {
super(query, scope, parentType, context);
Bitset(Query query, String parentType, SearchContext context) {
super(query, parentType, context);
}
public DocIdSet getDocIdSet(AtomicReaderContext readerContext, Bits acceptDocs) throws IOException {

View File

@ -50,17 +50,15 @@ public class ParentQuery extends Query implements SearchContext.Rewrite {
private final String parentType;
private final Filter childrenFilter;
private final List<String> childTypes;
private final String scope;
private TObjectFloatHashMap<HashedBytesArray> uidToScore;
public ParentQuery(SearchContext searchContext, Query parentQuery, String parentType, List<String> childTypes, Filter childrenFilter, String scope) {
public ParentQuery(SearchContext searchContext, Query parentQuery, String parentType, List<String> childTypes, Filter childrenFilter) {
this.searchContext = searchContext;
this.parentQuery = parentQuery;
this.parentType = parentType;
this.childTypes = childTypes;
this.childrenFilter = childrenFilter;
this.scope = scope;
}
private ParentQuery(ParentQuery unwritten, Query rewrittenParentQuery) {
@ -69,7 +67,6 @@ public class ParentQuery extends Query implements SearchContext.Rewrite {
this.parentType = unwritten.parentType;
this.childrenFilter = unwritten.childrenFilter;
this.childTypes = unwritten.childTypes;
this.scope = unwritten.scope;
this.uidToScore = unwritten.uidToScore;
}

View File

@ -39,8 +39,6 @@ public class TopChildrenQuery extends Query implements SearchContext.Rewrite {
private Query query;
private String scope;
private String parentType;
private String childType;
@ -61,9 +59,8 @@ public class TopChildrenQuery extends Query implements SearchContext.Rewrite {
private boolean[] properlyInvoked = new boolean[]{false};
// Note, the query is expected to already be filtered to only child type docs
public TopChildrenQuery(Query query, String scope, String childType, String parentType, ScoreType scoreType, int factor, int incrementalFactor) {
public TopChildrenQuery(Query query, String childType, String parentType, ScoreType scoreType, int factor, int incrementalFactor) {
this.query = query;
this.scope = scope;
this.childType = childType;
this.parentType = parentType;
this.scoreType = scoreType;