forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support
search_type
in Rank Evaluation API (elastic#48542)
Adding support for the `search_type` request parameter to the Ranking Evaluation API since this parameter can impact the ranking and the metric score and should be choosen in the same way when evaluating the search as later in the real search. Closes elastic#48503
- Loading branch information
Christoph Büscher
committed
Oct 29, 2019
1 parent
a036215
commit 9dd0018
Showing
9 changed files
with
137 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...ank-eval/src/test/java/org/elasticsearch/index/rankeval/TransportRankEvalActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* 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.index.rankeval; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.search.MultiSearchRequest; | ||
import org.elasticsearch.action.search.MultiSearchResponse; | ||
import org.elasticsearch.action.search.SearchType; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.IndicesOptions; | ||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.script.ScriptService; | ||
import org.elasticsearch.search.builder.SearchSourceBuilder; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.transport.TransportService; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.mock; | ||
|
||
public class TransportRankEvalActionTests extends ESTestCase { | ||
|
||
private Settings settings = Settings.builder().put("path.home", createTempDir().toString()).put("node.name", "test-" + getTestName()) | ||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build(); | ||
|
||
/** | ||
* Test that request parameters like indicesOptions or searchType from ranking evaluation request are transfered to msearch request | ||
*/ | ||
public void testTransferRequestParameters() throws Exception { | ||
String indexName = "test_index"; | ||
List<RatedRequest> specifications = new ArrayList<>(); | ||
specifications | ||
.add(new RatedRequest("amsterdam_query", Arrays.asList(new RatedDocument(indexName, "1", 3)), new SearchSourceBuilder())); | ||
RankEvalRequest rankEvalRequest = new RankEvalRequest(new RankEvalSpec(specifications, new DiscountedCumulativeGain()), | ||
new String[] { indexName }); | ||
SearchType expectedSearchType = randomFrom(SearchType.CURRENTLY_SUPPORTED); | ||
rankEvalRequest.searchType(expectedSearchType); | ||
IndicesOptions expectedIndicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), | ||
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()); | ||
rankEvalRequest.indicesOptions(expectedIndicesOptions); | ||
|
||
NodeClient client = new NodeClient(settings, null) { | ||
@Override | ||
public void multiSearch(MultiSearchRequest request, ActionListener<MultiSearchResponse> listener) { | ||
assertEquals(1, request.requests().size()); | ||
assertEquals(expectedSearchType, request.requests().get(0).searchType()); | ||
assertArrayEquals(new String[]{indexName}, request.requests().get(0).indices()); | ||
assertEquals(expectedIndicesOptions, request.requests().get(0).indicesOptions()); | ||
} | ||
}; | ||
|
||
TransportRankEvalAction action = new TransportRankEvalAction(mock(ActionFilters.class), client, mock(TransportService.class), | ||
mock(ScriptService.class), NamedXContentRegistry.EMPTY); | ||
action.doExecute(null, rankEvalRequest, null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ setup: | |
- do: | ||
rank_eval: | ||
index: foo, | ||
search_type: query_then_fetch | ||
body: { | ||
"requests" : [ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters