diff --git a/db/migrate/20240626181338_reindex_p_at10_code.rb b/db/migrate/20240626181338_reindex_p_at10_code.rb new file mode 100644 index 000000000..b7bf0bba9 --- /dev/null +++ b/db/migrate/20240626181338_reindex_p_at10_code.rb @@ -0,0 +1,12 @@ +class ReindexPAt10Code < ActiveRecord::Migration[7.1] + # force existing P@10 scorers to reload using the latest scorer information. + def change + scorers_to_update = ['P@10'] + scorers_to_update.each do |scorer_name| + scorer = Scorer.where(name: scorer_name, communal: true).first + name = scorer.name + scorer.code = File.readlines("./db/scorers/#{name.downcase}.js",'\n').join('\n') + scorer.save! + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 0a19e24b7..116dc63f7 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_06_26_173902) do +ActiveRecord::Schema[7.1].define(version: 2024_06_26_181338) do create_table "active_storage_attachments", charset: "utf8mb4", collation: "utf8mb4_bin", force: :cascade do |t| t.string "name", null: false t.string "record_type", null: false diff --git a/db/scorers/p@10.js b/db/scorers/p@10.js index e8a37cbc4..f094fbdb8 100644 --- a/db/scorers/p@10.js +++ b/db/scorers/p@10.js @@ -1,4 +1,11 @@ -var k = 10 // @Rank -var score = avgRating(k); - +const k = 10; // @Rank +// k may be > length list, so count up the total number of documents processed. +let count = 0, total = 0; +eachDoc(function(doc, i) { + if (hasDocRating(i) && (docRating(i)) > 0) { // map 0 -> irrel, 1+ ->rel + count = count + 1; + } + total = total + 1.0; +}, k); +const score = total ? count / total : 0.0; setScore(score);