Remove RescoreParseElement
The refactoring of RescoreBuilder and QueryRescoreBuilder moved parsing previously in RescoreParseElement into the builders. This removes the left over parse element.
This commit is contained in:
parent
26a0fb37a4
commit
06184ee006
|
@ -1,80 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.search.rescore;
|
||||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.SearchParseElement;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class RescoreParseElement implements SearchParseElement {
|
||||
|
||||
@Override
|
||||
public void parse(XContentParser parser, SearchContext context) throws Exception {
|
||||
if (parser.currentToken() == XContentParser.Token.START_ARRAY) {
|
||||
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
|
||||
context.addRescore(parseSingleRescoreContext(parser, context.getQueryShardContext()));
|
||||
}
|
||||
} else {
|
||||
context.addRescore(parseSingleRescoreContext(parser, context.getQueryShardContext()));
|
||||
}
|
||||
}
|
||||
|
||||
public RescoreSearchContext parseSingleRescoreContext(XContentParser parser, QueryShardContext context) throws ElasticsearchParseException, IOException {
|
||||
String fieldName = null;
|
||||
RescoreSearchContext rescoreContext = null;
|
||||
Integer windowSize = null;
|
||||
XContentParser.Token token;
|
||||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
|
||||
if (token == XContentParser.Token.FIELD_NAME) {
|
||||
fieldName = parser.currentName();
|
||||
if (QueryRescorer.NAME.equals(fieldName)) {
|
||||
// we only have one at this point
|
||||
Rescorer rescorer = QueryRescorer.INSTANCE;
|
||||
token = parser.nextToken();
|
||||
if (token != XContentParser.Token.START_OBJECT) {
|
||||
throw new ElasticsearchParseException("rescore type malformed, must start with start_object");
|
||||
}
|
||||
rescoreContext = rescorer.parse(parser, context);
|
||||
}
|
||||
} else if (token.isValue()) {
|
||||
if ("window_size".equals(fieldName)) {
|
||||
windowSize = parser.intValue();
|
||||
} else {
|
||||
throw new IllegalArgumentException("rescore doesn't support [" + fieldName + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (rescoreContext == null) {
|
||||
throw new IllegalArgumentException("missing rescore type");
|
||||
}
|
||||
if (windowSize != null) {
|
||||
rescoreContext.setWindowSize(windowSize.intValue());
|
||||
}
|
||||
return rescoreContext;
|
||||
}
|
||||
|
||||
}
|
|
@ -29,23 +29,25 @@ import org.elasticsearch.search.SearchPhase;
|
|||
import org.elasticsearch.search.internal.SearchContext;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.singletonMap;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class RescorePhase extends AbstractComponent implements SearchPhase {
|
||||
private static final Map<String, SearchParseElement> PARSE_ELEMENTS = singletonMap("rescore", new RescoreParseElement());
|
||||
|
||||
@Inject
|
||||
public RescorePhase(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* rescorers do not have a parse element, they use
|
||||
* {@link RescoreBuilder#parseFromXContent(org.elasticsearch.index.query.QueryParseContext)} for parsing instead.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, ? extends SearchParseElement> parseElements() {
|
||||
return PARSE_ELEMENTS;
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.elasticsearch.search.rescore;
|
||||
|
||||
import org.apache.lucene.search.Query;
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
|
@ -153,8 +154,8 @@ public class QueryRescoreBuilderTests extends ESTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* test that build() outputs a {@link RescoreSearchContext} that is similar to the one
|
||||
* we would get when parsing the xContent the test rescore builder is rendering out
|
||||
* test that build() outputs a {@link RescoreSearchContext} that has the same properties
|
||||
* than the test builder
|
||||
*/
|
||||
public void testBuildRescoreSearchContext() throws ElasticsearchParseException, IOException {
|
||||
Settings indexSettings = Settings.settingsBuilder()
|
||||
|
@ -171,18 +172,16 @@ public class QueryRescoreBuilderTests extends ESTestCase {
|
|||
};
|
||||
|
||||
for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) {
|
||||
RescoreBuilder<?> rescoreBuilder = randomRescoreBuilder();
|
||||
QueryRescorerBuilder rescoreBuilder = randomRescoreBuilder();
|
||||
QueryRescoreContext rescoreContext = rescoreBuilder.build(mockShardContext);
|
||||
XContentParser parser = createParser(rescoreBuilder);
|
||||
|
||||
QueryRescoreContext parsedRescoreContext = (QueryRescoreContext) new RescoreParseElement().parseSingleRescoreContext(parser,
|
||||
mockShardContext);
|
||||
assertNotSame(rescoreContext, parsedRescoreContext);
|
||||
assertEquals(rescoreContext.window(), parsedRescoreContext.window());
|
||||
assertEquals(rescoreContext.query(), parsedRescoreContext.query());
|
||||
assertEquals(rescoreContext.queryWeight(), parsedRescoreContext.queryWeight(), Float.MIN_VALUE);
|
||||
assertEquals(rescoreContext.rescoreQueryWeight(), parsedRescoreContext.rescoreQueryWeight(), Float.MIN_VALUE);
|
||||
assertEquals(rescoreContext.scoreMode(), parsedRescoreContext.scoreMode());
|
||||
int expectedWindowSize = rescoreBuilder.windowSize() == null ? QueryRescoreContext.DEFAULT_WINDOW_SIZE :
|
||||
rescoreBuilder.windowSize().intValue();
|
||||
assertEquals(expectedWindowSize, rescoreContext.window());
|
||||
Query expectedQuery = QueryBuilder.rewriteQuery(rescoreBuilder.getRescoreQuery(), mockShardContext).toQuery(mockShardContext);
|
||||
assertEquals(expectedQuery, rescoreContext.query());
|
||||
assertEquals(rescoreBuilder.getQueryWeight(), rescoreContext.queryWeight(), Float.MIN_VALUE);
|
||||
assertEquals(rescoreBuilder.getRescoreQueryWeight(), rescoreContext.rescoreQueryWeight(), Float.MIN_VALUE);
|
||||
assertEquals(rescoreBuilder.getScoreMode(), rescoreContext.scoreMode());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -318,7 +317,7 @@ public class QueryRescoreBuilderTests extends ESTestCase {
|
|||
/**
|
||||
* create random shape that is put under test
|
||||
*/
|
||||
public static org.elasticsearch.search.rescore.QueryRescorerBuilder randomRescoreBuilder() {
|
||||
public static QueryRescorerBuilder randomRescoreBuilder() {
|
||||
QueryBuilder<MatchAllQueryBuilder> queryBuilder = new MatchAllQueryBuilder().boost(randomFloat())
|
||||
.queryName(randomAsciiOfLength(20));
|
||||
org.elasticsearch.search.rescore.QueryRescorerBuilder rescorer = new
|
||||
|
|
Loading…
Reference in New Issue