always use deletion aware constant score

This commit is contained in:
kimchy 2010-10-25 13:35:43 +02:00
parent b7eacc3618
commit 835a81c16c
4 changed files with 7 additions and 28 deletions

View File

@ -29,11 +29,5 @@ import org.elasticsearch.index.IndexComponent;
*/
public interface IndexEngine extends IndexComponent {
/**
* Are readers cloned on deletion? If this is the case, then some specific
* needs to be taken.
*/
boolean readerClonedOnDeletion();
void close();
}

View File

@ -41,13 +41,6 @@ public class RobinIndexEngine extends AbstractIndexComponent implements IndexEng
super(index, indexSettings);
}
/**
* With NRT, readers are cloned on deletions... .
*/
@Override public boolean readerClonedOnDeletion() {
return true;
}
@Override public void close() {
}
}

View File

@ -19,7 +19,6 @@
package org.elasticsearch.index.query.xcontent;
import org.apache.lucene.search.ConstantScoreQuery;
import org.apache.lucene.search.DeletionAwareConstantScoreQuery;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Query;
@ -77,19 +76,12 @@ public class ConstantScoreQueryParser extends AbstractIndexComponent implements
throw new QueryParsingException(index, "[constant_score] requires 'filter' element");
}
// cache the filter if possible
Query query;
// cache the filter if possible needed
if (cache) {
Filter nonCachedFilter = filter;
filter = parseContext.cacheFilter(filter);
if (parseContext.indexEngine().readerClonedOnDeletion() && (filter != nonCachedFilter)) {
query = new DeletionAwareConstantScoreQuery(filter, true);
} else {
query = new ConstantScoreQuery(filter);
}
} else {
query = new ConstantScoreQuery(filter);
}
Query query = new DeletionAwareConstantScoreQuery(filter, true);
query.setBoost(boost);
return query;
}

View File

@ -881,8 +881,8 @@ public class SimpleIndexQueryParserTests {
@Test public void testConstantScoreQueryBuilder() throws IOException {
IndexQueryParser queryParser = queryParser();
Query parsedQuery = queryParser.parse(constantScoreQuery(termFilter("name.last", "banon"))).query();
assertThat(parsedQuery, instanceOf(ConstantScoreQuery.class));
ConstantScoreQuery constantScoreQuery = (ConstantScoreQuery) parsedQuery;
assertThat(parsedQuery, instanceOf(DeletionAwareConstantScoreQuery.class));
DeletionAwareConstantScoreQuery constantScoreQuery = (DeletionAwareConstantScoreQuery) parsedQuery;
assertThat(((TermFilter) constantScoreQuery.getFilter()).getTerm(), equalTo(new Term("name.last", "banon")));
}
@ -890,8 +890,8 @@ public class SimpleIndexQueryParserTests {
IndexQueryParser queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/xcontent/constantScore-query.json");
Query parsedQuery = queryParser.parse(query).query();
assertThat(parsedQuery, instanceOf(ConstantScoreQuery.class));
ConstantScoreQuery constantScoreQuery = (ConstantScoreQuery) parsedQuery;
assertThat(parsedQuery, instanceOf(DeletionAwareConstantScoreQuery.class));
DeletionAwareConstantScoreQuery constantScoreQuery = (DeletionAwareConstantScoreQuery) parsedQuery;
assertThat(((TermFilter) constantScoreQuery.getFilter()).getTerm(), equalTo(new Term("name.last", "banon")));
}