Allow to search across indices and types even if some types do not exists on some indices, closes #839.

This commit is contained in:
kimchy 2011-04-07 16:00:18 +03:00
parent 4603d10501
commit 1fdef91fc2
1 changed files with 21 additions and 1 deletions

View File

@ -31,6 +31,7 @@ import org.elasticsearch.common.collect.Sets;
import org.elasticsearch.common.collect.UnmodifiableIterator; import org.elasticsearch.common.collect.UnmodifiableIterator;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.Streams; import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.lucene.search.TermFilter;
import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadSafe; import org.elasticsearch.common.util.concurrent.ThreadSafe;
@ -240,9 +241,28 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
} }
/** /**
* A filter to filter based on several types. * A filter to filter based on several types. Will not throw types missing failure, and will
* simply filter it out also.
*/ */
public Filter typesFilter(String... types) { public Filter typesFilter(String... types) {
if (types.length == 1) {
DocumentMapper docMapper = documentMapper(types[0]);
if (docMapper == null) {
return new TermFilter(new Term(types[0]));
}
return docMapper.typeFilter();
}
PublicTermsFilter termsFilter = new PublicTermsFilter();
for (String type : types) {
termsFilter.addTerm(new Term(TypeFieldMapper.NAME, type));
}
return termsFilter;
}
/**
* A filter to filter based on several types.
*/
public Filter typesFilterFailOnMissing(String... types) throws TypeMissingException {
if (types.length == 1) { if (types.length == 1) {
DocumentMapper docMapper = documentMapper(types[0]); DocumentMapper docMapper = documentMapper(types[0]);
if (docMapper == null) { if (docMapper == null) {