|
| 1 | +# Licensed to Elasticsearch B.V under one or more agreements. |
| 2 | +# Elasticsearch B.V licenses this file to you under the Apache 2.0 License. |
| 3 | +# See the LICENSE file in the project root for more information |
| 4 | + |
| 5 | +require 'spec_helper' |
| 6 | + |
| 7 | +describe 'client#rank_eval' do |
| 8 | + |
| 9 | + let(:expected_args) do |
| 10 | + [ |
| 11 | + 'GET', |
| 12 | + url, |
| 13 | + params, |
| 14 | + body |
| 15 | + ] |
| 16 | + end |
| 17 | + |
| 18 | + let(:params) do |
| 19 | + {} |
| 20 | + end |
| 21 | + |
| 22 | + let(:body) do |
| 23 | + {} |
| 24 | + end |
| 25 | + |
| 26 | + let(:url) do |
| 27 | + '_rank_eval' |
| 28 | + end |
| 29 | + |
| 30 | + context 'when there is no body specified' do |
| 31 | + |
| 32 | + let(:client) do |
| 33 | + Class.new { include Elasticsearch::API }.new |
| 34 | + end |
| 35 | + |
| 36 | + it 'raises an exception' do |
| 37 | + expect { |
| 38 | + client.rank_eval(index: 'my_index') |
| 39 | + }.to raise_exception(ArgumentError) |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + context 'when an index is specified' do |
| 44 | + |
| 45 | + let(:url) do |
| 46 | + 'my_index/_rank_eval' |
| 47 | + end |
| 48 | + |
| 49 | + it 'performs the request' do |
| 50 | + expect(client.rank_eval(index: 'my_index', body: {})).to eq({}) |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + context 'when params are provided' do |
| 55 | + |
| 56 | + let(:params) do |
| 57 | + { |
| 58 | + ignore_unavailable: true, |
| 59 | + allow_no_indices: false, |
| 60 | + expand_wildcards: 'open' |
| 61 | + } |
| 62 | + end |
| 63 | + |
| 64 | + it 'performs the request' do |
| 65 | + expect(client_double.rank_eval(body: {}, |
| 66 | + ignore_unavailable: true, |
| 67 | + allow_no_indices: false, |
| 68 | + expand_wildcards: 'open')).to eq({}) |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + context 'when a body is specified' do |
| 73 | + |
| 74 | + let(:body) do |
| 75 | + { |
| 76 | + "requests": [ |
| 77 | + { |
| 78 | + "id": "JFK query", |
| 79 | + "request": { "query": { "match_all": {}}}, |
| 80 | + "ratings": [] |
| 81 | + }], |
| 82 | + "metric": { |
| 83 | + "expected_reciprocal_rank": { |
| 84 | + "maximum_relevance": 3, |
| 85 | + "k": 20 |
| 86 | + } |
| 87 | + } |
| 88 | + } |
| 89 | + end |
| 90 | + |
| 91 | + let(:url) do |
| 92 | + 'my_index/_rank_eval' |
| 93 | + end |
| 94 | + |
| 95 | + it 'performs the request' do |
| 96 | + expect(client_double.rank_eval(index: 'my_index', |
| 97 | + body: { |
| 98 | + "requests": [ |
| 99 | + { |
| 100 | + "id": "JFK query", |
| 101 | + "request": { "query": { "match_all": {}}}, |
| 102 | + "ratings": [] |
| 103 | + }], |
| 104 | + "metric": { |
| 105 | + "expected_reciprocal_rank": { |
| 106 | + "maximum_relevance": 3, |
| 107 | + "k": 20 |
| 108 | + } |
| 109 | + } |
| 110 | + })).to eq({}) |
| 111 | + end |
| 112 | + end |
| 113 | +end |
0 commit comments