Skip to content

Commit

Permalink
change the output format to be what RRE does and RankQuest expects.
Browse files Browse the repository at this point in the history
  • Loading branch information
epugh committed Jan 22, 2024
1 parent ca67fb3 commit b6823e8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
16 changes: 2 additions & 14 deletions app/views/api/v1/export/ratings/_rre_query.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@ json.placeholders do
json.set!('$query', query.query_text)
end

grouped_ratings = {}

query.ratings.fully_rated.each do |r|
int_rating = r.rating.to_i # rre and rankquest both are int based
# rubocop:disable Style/IfUnlessModifier
unless grouped_ratings.key?(int_rating)
grouped_ratings[int_rating] = []
end
# rubocop:enable Style/IfUnlessModifier
grouped_ratings[int_rating] << r.doc_id
end

json.relevant_documents do
grouped_ratings.sort.to_h.each do |key, value|
json.set!(key, value)
query.ratings.fully_rated.each do |r|
json.set!(r.doc_id, { gain: r.rating.to_i } )
end
end
15 changes: 8 additions & 7 deletions test/controllers/api/v1/export/ratings_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,24 @@ class RatingsControllerTest < ActionController::TestCase
assert_response :ok

body = response.parsed_body

puts response.body

assert_equal body['id_field'], 'id'
assert_equal body['index'], the_case.tries.latest.index_name_from_search_url
assert_equal body['queries'].size, the_case.queries.size
assert_equal body['queries'][0]['placeholders']['$query'], the_case.queries[0].query_text
assert_equal body['queries'][2]['placeholders']['$query'], the_case.queries[2].query_text
assert_not_nil body['queries'][2]['relevant_documents']
puts body['queries'][2]['relevant_documents']

# somewhat verbose RRE format for describing ratings.
expected_relevant_docs = {
"1": ["docb"],
"3": ["doca"]
docb: {
gain: 1,
},
doca: {
gain: 3,
},
}



assert_equal expected_relevant_docs, body['queries'][2]['relevant_documents'].deep_symbolize_keys
end
end
Expand Down

0 comments on commit b6823e8

Please sign in to comment.