From 15b46d195ad7239bc1a7b3d7a50ca077849e0dd0 Mon Sep 17 00:00:00 2001 From: Eliot Jordan Date: Mon, 13 Jan 2025 11:35:26 -0600 Subject: [PATCH] Remove trailing dashes from title slugs --- solr/conf/slug.js | 5 +++++ test/dpul_collections/solr_test.exs | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/solr/conf/slug.js b/solr/conf/slug.js index b8a50ed7..641f3a60 100755 --- a/solr/conf/slug.js +++ b/solr/conf/slug.js @@ -32,6 +32,11 @@ function processAdd(cmd) { .join('-') .slice(0, maxCharacters) + // Remove any trailing dash + if (slug.slice(-1) == '-') { + slug = slug.slice(0, -1) + } + doc.setField("slug_s", slug); } diff --git a/test/dpul_collections/solr_test.exs b/test/dpul_collections/solr_test.exs index 912371ef..2c86a11a 100644 --- a/test/dpul_collections/solr_test.exs +++ b/test/dpul_collections/solr_test.exs @@ -203,6 +203,19 @@ defmodule DpulCollections.SolrTest do "él-no-responde-mis-mensajes" end + test "slug generation when the slug is truncated with a trailing dash" do + doc = %{ + "id" => "3cb7627b-defc-401b-9959-42ebc4488f74", + "title_txtm" => ["¿Cómo la reforma educacional beneficia a mi familia?"] + } + + Solr.add([doc], active_collection()) + Solr.commit(active_collection()) + + assert Solr.find_by_id("3cb7627b-defc-401b-9959-42ebc4488f74")["slug_s"] == + "cómo-reforma-educacional-beneficia" + end + test "an exception is logged when indexing a document raises a solr error" do doc = %{ # No title