fix nested filter to work well with inner nested queries
This commit is contained in:
parent
66d5eb94fb
commit
9513dd0a4a
|
@ -19,9 +19,7 @@
|
||||||
|
|
||||||
package org.elasticsearch.index.query;
|
package org.elasticsearch.index.query;
|
||||||
|
|
||||||
import org.apache.lucene.index.IndexReader;
|
|
||||||
import org.apache.lucene.search.DeletionAwareConstantScoreQuery;
|
import org.apache.lucene.search.DeletionAwareConstantScoreQuery;
|
||||||
import org.apache.lucene.search.DocIdSet;
|
|
||||||
import org.apache.lucene.search.Filter;
|
import org.apache.lucene.search.Filter;
|
||||||
import org.apache.lucene.search.FilteredQuery;
|
import org.apache.lucene.search.FilteredQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
|
@ -60,10 +58,10 @@ public class NestedFilterParser implements FilterParser {
|
||||||
String filterName = null;
|
String filterName = null;
|
||||||
|
|
||||||
// we need a late binding filter so we can inject a parent nested filter inner nested queries
|
// we need a late binding filter so we can inject a parent nested filter inner nested queries
|
||||||
LateBindingParentFilter currentParentFilterContext = parentFilterContext.get();
|
NestedQueryParser.LateBindingParentFilter currentParentFilterContext = NestedQueryParser.parentFilterContext.get();
|
||||||
|
|
||||||
LateBindingParentFilter usAsParentFilter = new LateBindingParentFilter();
|
NestedQueryParser.LateBindingParentFilter usAsParentFilter = new NestedQueryParser.LateBindingParentFilter();
|
||||||
parentFilterContext.set(usAsParentFilter);
|
NestedQueryParser.parentFilterContext.set(usAsParentFilter);
|
||||||
|
|
||||||
String currentFieldName = null;
|
String currentFieldName = null;
|
||||||
XContentParser.Token token;
|
XContentParser.Token token;
|
||||||
|
@ -131,7 +129,7 @@ public class NestedFilterParser implements FilterParser {
|
||||||
}
|
}
|
||||||
|
|
||||||
// restore the thread local one...
|
// restore the thread local one...
|
||||||
parentFilterContext.set(currentParentFilterContext);
|
NestedQueryParser.parentFilterContext.set(currentParentFilterContext);
|
||||||
|
|
||||||
BlockJoinQuery joinQuery = new BlockJoinQuery(query, parentFilter, BlockJoinQuery.ScoreMode.None);
|
BlockJoinQuery joinQuery = new BlockJoinQuery(query, parentFilter, BlockJoinQuery.ScoreMode.None);
|
||||||
|
|
||||||
|
@ -148,27 +146,4 @@ public class NestedFilterParser implements FilterParser {
|
||||||
}
|
}
|
||||||
return joinFilter;
|
return joinFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ThreadLocal<LateBindingParentFilter> parentFilterContext = new ThreadLocal<LateBindingParentFilter>();
|
|
||||||
|
|
||||||
static class LateBindingParentFilter extends Filter {
|
|
||||||
|
|
||||||
Filter filter;
|
|
||||||
|
|
||||||
@Override public int hashCode() {
|
|
||||||
return filter.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public boolean equals(Object obj) {
|
|
||||||
return filter.equals(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public String toString() {
|
|
||||||
return filter.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
|
|
||||||
return filter.getDocIdSet(reader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue