|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.index.rankeval; |
| 21 | + |
| 22 | +import org.elasticsearch.action.ActionListener; |
| 23 | +import org.elasticsearch.action.search.MultiSearchRequest; |
| 24 | +import org.elasticsearch.action.search.MultiSearchResponse; |
| 25 | +import org.elasticsearch.action.search.SearchType; |
| 26 | +import org.elasticsearch.action.support.ActionFilters; |
| 27 | +import org.elasticsearch.action.support.IndicesOptions; |
| 28 | +import org.elasticsearch.client.node.NodeClient; |
| 29 | +import org.elasticsearch.common.settings.Settings; |
| 30 | +import org.elasticsearch.common.xcontent.NamedXContentRegistry; |
| 31 | +import org.elasticsearch.env.Environment; |
| 32 | +import org.elasticsearch.script.ScriptService; |
| 33 | +import org.elasticsearch.search.builder.SearchSourceBuilder; |
| 34 | +import org.elasticsearch.test.ESTestCase; |
| 35 | +import org.elasticsearch.transport.TransportService; |
| 36 | + |
| 37 | +import java.util.ArrayList; |
| 38 | +import java.util.Arrays; |
| 39 | +import java.util.List; |
| 40 | + |
| 41 | +import static org.mockito.Mockito.mock; |
| 42 | + |
| 43 | +public class TransportRankEvalActionTests extends ESTestCase { |
| 44 | + |
| 45 | + private Settings settings = Settings.builder().put("path.home", createTempDir().toString()).put("node.name", "test-" + getTestName()) |
| 46 | + .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).build(); |
| 47 | + |
| 48 | + /** |
| 49 | + * Test that request parameters like indicesOptions or searchType from ranking evaluation request are transfered to msearch request |
| 50 | + */ |
| 51 | + public void testTransferRequestParameters() throws Exception { |
| 52 | + String indexName = "test_index"; |
| 53 | + List<RatedRequest> specifications = new ArrayList<>(); |
| 54 | + specifications |
| 55 | + .add(new RatedRequest("amsterdam_query", Arrays.asList(new RatedDocument(indexName, "1", 3)), new SearchSourceBuilder())); |
| 56 | + RankEvalRequest rankEvalRequest = new RankEvalRequest(new RankEvalSpec(specifications, new DiscountedCumulativeGain()), |
| 57 | + new String[] { indexName }); |
| 58 | + SearchType expectedSearchType = randomFrom(SearchType.CURRENTLY_SUPPORTED); |
| 59 | + rankEvalRequest.searchType(expectedSearchType); |
| 60 | + IndicesOptions expectedIndicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), |
| 61 | + randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()); |
| 62 | + rankEvalRequest.indicesOptions(expectedIndicesOptions); |
| 63 | + |
| 64 | + NodeClient client = new NodeClient(settings, null) { |
| 65 | + @Override |
| 66 | + public void multiSearch(MultiSearchRequest request, ActionListener<MultiSearchResponse> listener) { |
| 67 | + assertEquals(1, request.requests().size()); |
| 68 | + assertEquals(expectedSearchType, request.requests().get(0).searchType()); |
| 69 | + assertArrayEquals(new String[]{indexName}, request.requests().get(0).indices()); |
| 70 | + assertEquals(expectedIndicesOptions, request.requests().get(0).indicesOptions()); |
| 71 | + } |
| 72 | + }; |
| 73 | + |
| 74 | + TransportRankEvalAction action = new TransportRankEvalAction(mock(ActionFilters.class), client, mock(TransportService.class), |
| 75 | + mock(ScriptService.class), NamedXContentRegistry.EMPTY); |
| 76 | + action.doExecute(null, rankEvalRequest, null); |
| 77 | + } |
| 78 | +} |
0 commit comments