Query DSL: query_string / field to use the optimized match_all query when using * (or *:*), closes #413.

This commit is contained in:
kimchy 2010-10-07 16:48:24 +02:00
parent 504a5458c5
commit d0bf743ab4
5 changed files with 12 additions and 5 deletions

View file

@ -24,6 +24,7 @@ import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.FieldMappers; import org.elasticsearch.index.mapper.FieldMappers;
import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.index.mapper.MapperService;
@ -83,6 +84,10 @@ public class MapperQueryParser extends QueryParser {
return super.newTermQuery(term); return super.newTermQuery(term);
} }
@Override protected Query newMatchAllDocsQuery() {
return Queries.MATCH_ALL_QUERY;
}
@Override public Query getFieldQuery(String field, String queryText) throws ParseException { @Override public Query getFieldQuery(String field, String queryText) throws ParseException {
currentMapper = null; currentMapper = null;
if (parseContext.mapperService() != null) { if (parseContext.mapperService() != null) {

View file

@ -29,12 +29,13 @@ import java.util.List;
*/ */
public class Queries { public class Queries {
public final static MatchAllDocsQuery MATCH_ALL_QUERY = new MatchAllDocsQuery(); // We don't use MatchAllDocsQuery, its slower than the one below ... (much slower)
public final static Query MATCH_ALL_QUERY = new DeletionAwareConstantScoreQuery(new MatchAllDocsFilter(), true);
/** /**
* A match all docs filter. Note, requires no caching!. * A match all docs filter. Note, requires no caching!.
*/ */
public final static MatchAllDocsFilter MATCH_ALL_FILTER = new MatchAllDocsFilter(); public final static Filter MATCH_ALL_FILTER = new MatchAllDocsFilter();
private final static Field disjuncts; private final static Field disjuncts;

View file

@ -19,7 +19,6 @@
package org.elasticsearch.index.query.xcontent; package org.elasticsearch.index.query.xcontent;
import org.apache.lucene.search.DeletionAwareConstantScoreQuery;
import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
@ -70,7 +69,7 @@ public class MatchAllQueryParser extends AbstractIndexComponent implements XCont
} }
if (boost == 1.0f && normsField == null) { if (boost == 1.0f && normsField == null) {
return new DeletionAwareConstantScoreQuery(Queries.MATCH_ALL_FILTER, true); // no need to cache a MATCH ALL FILTER return Queries.MATCH_ALL_QUERY;
} }
MatchAllDocsQuery query = new MatchAllDocsQuery(normsField); MatchAllDocsQuery query = new MatchAllDocsQuery(normsField);

View file

@ -56,6 +56,7 @@ public class FsMetaDataGatewayTests extends AbstractNodesTests {
closeNode("server1"); closeNode("server1");
startNode("server1"); startNode("server1");
Thread.sleep(500);
try { try {
client("server1").admin().indices().create(createIndexRequest("test")).actionGet(); client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
assert false : "index should exists"; assert false : "index should exists";

View file

@ -77,12 +77,13 @@ public class HdfsGatewayTests {
node.close(); node.close();
} }
@Test public void testHdfsGateway() { @Test public void testHdfsGateway() throws Exception {
// first, test meta data // first, test meta data
CreateIndexResponse createIndexResponse = node.client().admin().indices().create(createIndexRequest("test")).actionGet(); CreateIndexResponse createIndexResponse = node.client().admin().indices().create(createIndexRequest("test")).actionGet();
assertThat(createIndexResponse.acknowledged(), equalTo(true)); assertThat(createIndexResponse.acknowledged(), equalTo(true));
node.close(); node.close();
node = buildNode().start(); node = buildNode().start();
Thread.sleep(500);
try { try {
node.client().admin().indices().create(createIndexRequest("test")).actionGet(); node.client().admin().indices().create(createIndexRequest("test")).actionGet();
assert false : "index should exists"; assert false : "index should exists";