Skip to content

Commit

Permalink
Query DSL: query_string / field to use the optimized match_all query …
Browse files Browse the repository at this point in the history
…when using * (or *:*), closes elastic#413.
  • Loading branch information
kimchy committed Oct 7, 2010
1 parent 504a545 commit d0bf743
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.Query;
import org.elasticsearch.common.lucene.Lucene;
import org.elasticsearch.common.lucene.search.Queries;
import org.elasticsearch.index.mapper.FieldMapper;
import org.elasticsearch.index.mapper.FieldMappers;
import org.elasticsearch.index.mapper.MapperService;
Expand Down Expand Up @@ -83,6 +84,10 @@ public void reset(QueryParserSettings settings) {
return super.newTermQuery(term);
}

@Override protected Query newMatchAllDocsQuery() {
return Queries.MATCH_ALL_QUERY;
}

@Override public Query getFieldQuery(String field, String queryText) throws ParseException {
currentMapper = null;
if (parseContext.mapperService() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
*/
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!.
*/
public final static MatchAllDocsFilter MATCH_ALL_FILTER = new MatchAllDocsFilter();
public final static Filter MATCH_ALL_FILTER = new MatchAllDocsFilter();

private final static Field disjuncts;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.elasticsearch.index.query.xcontent;

import org.apache.lucene.search.DeletionAwareConstantScoreQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.Query;
import org.elasticsearch.common.Strings;
Expand Down Expand Up @@ -70,7 +69,7 @@ public class MatchAllQueryParser extends AbstractIndexComponent implements XCont
}

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class FsMetaDataGatewayTests extends AbstractNodesTests {
closeNode("server1");

startNode("server1");
Thread.sleep(500);
try {
client("server1").admin().indices().create(createIndexRequest("test")).actionGet();
assert false : "index should exists";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ private Node buildNode() {
node.close();
}

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

0 comments on commit d0bf743

Please sign in to comment.