From d1571ca1c7907999faaa360673cc3b39e36b3b71 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Fri, 3 May 2024 15:39:23 +0200 Subject: [PATCH] use inline expression script for preferring short module names The 'expression' language is faster, more secure, and supported on modern versions of Elasticsearch. It requires numeric fields. Now that we have the numeric `documentation_length` field, we can use it to prefer shorter names rather than needing to put files onto the ES servers. --- lib/MetaCPAN/Model/Search.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/MetaCPAN/Model/Search.pm b/lib/MetaCPAN/Model/Search.pm index cd34960ad..43ea5a979 100644 --- a/lib/MetaCPAN/Model/Search.pm +++ b/lib/MetaCPAN/Model/Search.pm @@ -297,8 +297,9 @@ sub build_query { # prefer shorter module names script_score => { script => { - lang => 'groovy', - file => 'prefer_shorter_module_names_400', + lang => 'expression', + inline => + "_score - (doc['documentation_length'].value == 0 ? 26 : doc['documentation_length'].value)/400", }, }, query => {