Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.
Ruby agplai-assistantdockerdsgvogdprhotwireissue-trackerjira-alternativeknowledge-basellmmcp-servermeeting-notesopen-sourceproject-managementredmine-alternativeruby-on-railsself-hostedticketingtime-tracking
Show each search hit's date and translate the hit labels
Guido Boyke5f5b144f7d9b
diff --git a/app/services/power_search_service.rb b/app/services/power_search_service.rbindex a7a884c..1df0c9f 100644--- a/app/services/power_search_service.rb+++ b/app/services/power_search_service.rb@@ -7,6 +7,18 @@ class PowerSearchServiceSEMANTIC_THRESHOLD = 0.7LIMIT = 15+ # Stable keys, not labels: the results view translates them+ # (views.organisations.power_search.power_search_results.types.*).+ RESULT_TYPES = {+ 'Note' => :note,+ 'DocumentVersion' => :document,+ 'DocumentationPage' => :documentation,+ 'Post' => :post,+ 'Ticket' => :ticket,+ 'Meeting' => :meeting,+ 'MeetingAnalysis' => :meeting_analysis+ }.freeze+def initialize(query, organisation, project_id = nil, current_user = nil)@query = query@organisation = organisation@@ -210,58 +222,56 @@ class PowerSearchServicelink: result_link(result),project_name: project&.name,project_link: project && Rails.application.routes.url_helpers.organisation_project_path(@organisation, project),+ date: result_date(result),content: result_content(result),highlighted_content: highlighted_content,similarity: similarity,match_types: match_types,- match_type: match_types.first, # For backwards compatibilityhighlight: highlighted_content}enddef result_type(fragmentable_type)- case fragmentable_type- when 'Note'- 'Note'- when 'DocumentVersion'- 'Dokument'- when 'DocumentationPage'- 'Dokumentation'- when 'Post'- 'Post'- when 'Ticket'- 'Ticket'- when 'Meeting'- 'Meeting'- when 'MeetingAnalysis'- 'Analyse'- else- 'Unknown'- end+ RESULT_TYPES.fetch(fragmentable_type, :unknown)+ end++ # When the information came into being, the date the results show next to the+ # type. A meeting counts from the day it took place, not from the day somebody+ # entered it; everything else from its creation. Not updated_at: a status change+ # would make an old ticket look fresh.+ def result_date(result)+ record = result.fragmentable+ return unless record++ result.fragmentable_type == 'Meeting' ? record.occurred_at : record.created_atenddef result_title(result)case result.fragmentable_typewhen 'Note'- result.fragmentable&.title || 'Note (deleted)'+ result.fragmentable&.title || deleted_title(:note)when 'DocumentVersion'- result.fragmentable&.document&.title || 'Document (deleted)'+ result.fragmentable&.document&.title || deleted_title(:document)when 'DocumentationPage'page = result.fragmentable- page&.title.presence || page&.path || 'Dokumentation (deleted)'+ page&.title.presence || page&.path || deleted_title(:documentation)when 'Post'- result.fragmentable&.ticket&.title || 'Ticket (deleted)'+ result.fragmentable&.ticket&.title || deleted_title(:ticket)when 'Ticket'- result.fragmentable&.title || 'Ticket (deleted)'+ result.fragmentable&.title || deleted_title(:ticket)when 'Meeting'- result.fragmentable&.title || 'Meeting (deleted)'+ result.fragmentable&.title || deleted_title(:meeting)when 'MeetingAnalysis'- result.fragmentable&.prompt_title || 'Analyse (deleted)'+ result.fragmentable&.prompt_title || deleted_title(:meeting_analysis)else- 'Unknown'+ deleted_title(:unknown)endend+ def deleted_title(type)+ I18n.t("services.power_search.deleted_titles.#{type}")+ end+def result_project(result)case result.fragmentable_typewhen 'Note', 'Ticket', 'Meeting'@@ -280,9 +290,9 @@ class PowerSearchServicedef determine_match_types(fragments, highlight_map, similarities)match_types = []- match_types << 'Volltext Treffer' if fragments.any? { |f| highlight_map[f.id].present? }- match_types << 'Semantischer Treffer' if fragments.any? { |f| similarities[f.id] >= SEMANTIC_THRESHOLD }- match_types << 'Unbekannter Treffer' if match_types.empty?+ match_types << :fulltext if fragments.any? { |f| highlight_map[f.id].present? }+ match_types << :semantic if fragments.any? { |f| similarities[f.id] >= SEMANTIC_THRESHOLD }+ match_types << :unknown if match_types.empty?match_typesenddiff --git a/app/views/organisations/power_search/_power_search_results.html.erb b/app/views/organisations/power_search/_power_search_results.html.erbindex 43a3004..79ef88c 100644--- a/app/views/organisations/power_search/_power_search_results.html.erb+++ b/app/views/organisations/power_search/_power_search_results.html.erb@@ -10,7 +10,7 @@<div class="border-b border-gray-200 pb-6"><p class="mb-1 flex flex-wrap items-center gap-2"><span class="inline-block px-2 py-1 text-xs font-semibold text-gray-600 border border-gray-200 rounded">- <%= result[:type] %>+ <%= t("views.organisations.power_search.power_search_results.types.#{result[:type]}") %></span><% if result[:project_name].present? %>@@ -21,14 +21,17 @@<% end %><% end %>- <% match_types = result[:match_types] || [result[:match_type]] %>- <% match_types.each do |match_type| %>- <% if match_type == 'Volltext Treffer' %>- <span class="inline-block px-2 py-1 text-xs font-semibold text-on-fill bg-green-500 rounded"><%= t('views.organisations.power_search.power_search_results.match_fulltext') %></span>- <% elsif match_type == 'Semantischer Treffer' %>- <span class="inline-block px-2 py-1 text-xs font-semibold text-on-fill bg-blue-500 rounded"><%= t('views.organisations.power_search.power_search_results.match_semantic') %></span>+ <% if result[:date].present? %>+ <time datetime="<%= result[:date].to_date.iso8601 %>" class="inline-block px-2 py-1 text-xs font-semibold text-gray-600 border border-gray-200 rounded"><%= l(result[:date].to_date) %></time>+ <% end %>++ <% result[:match_types].each do |match_type| %>+ <% if match_type == :fulltext %>+ <span class="inline-block px-2 py-1 text-xs font-semibold text-on-fill bg-green-500 rounded"><%= t('views.organisations.power_search.power_search_results.fulltext_match') %></span>+ <% elsif match_type == :semantic %>+ <span class="inline-block px-2 py-1 text-xs font-semibold text-on-fill bg-blue-500 rounded"><%= t('views.organisations.power_search.power_search_results.semantic_match') %></span><% else %>- <span class="inline-block px-2 py-1 text-xs font-semibold text-on-fill bg-gray-500 rounded"><%= t('views.organisations.power_search.power_search_results.match_unknown') %></span>+ <span class="inline-block px-2 py-1 text-xs font-semibold text-on-fill bg-gray-500 rounded"><%= t('views.organisations.power_search.power_search_results.unknown_match') %></span><% end %><% end %></p>@@ -37,12 +40,6 @@<h3 class="text-lg font-semibold"><%= link_to result[:title], result[:link], class: "text-gray-900 underline decoration-gray-300 hover:decoration-gray-600" %></h3>- <% if false %>- <p class="text-gray-600">- <span>Ähnlichkeit: <%= result[:similarity].round(2) %></span>- </p>- <% end %>-</div></div>diff --git a/config/locales/de.yml b/config/locales/de.ymlindex b6c196f..58758e0 100644--- a/config/locales/de.yml+++ b/config/locales/de.yml@@ -2492,17 +2492,14 @@ de:project_announcement: "🔔 WANN SIE BENACHRICHTIGT WERDEN:\n• Wichtige Projektankündigungen\n• Release-Informationen\n• Deadline-Änderungen\n• Team-Meeting Einladungen\n\n⚙️ WICHTIG:\n• Meist zeitkritische Informationen\n• Betrifft alle Projektmitglieder\n\n💡 TIPP: Diese sollten Sie nicht deaktivieren, da sie oft wichtige organisatorische Informationen enthalten."system_message: "🔔 WANN SIE BENACHRICHTIGT WERDEN:\n• Geplante Wartungsarbeiten\n• Neue Features und Updates\n• Wichtige Systemänderungen\n• Sicherheitsupdates\n\n⚙️ HÄUFIGKEIT:\n• Sehr selten (1-2x pro Monat)\n• Nur wirklich wichtige Informationen\n\n💡 TIPP: Sollte aktiv bleiben, da diese Nachrichten Ihre Arbeit beeinflussen können."power_search:- match_types:- fulltext: Volltext Treffer- semantic: Semantischer Treffer- unknown: Unbekannter Treffer- object_types:- document: Dokument- document_deleted: Dokument (gelöscht)- note: Notiz- note_deleted: Notiz (gelöscht)- post: Post- ticket: Ticket+ # Title of a hit whose record is gone (PowerSearchService#result_title).+ deleted_titles:+ note: Notiz (gelöscht)+ document: Dokument (gelöscht)+ documentation: Dokumentation (gelöscht)+ ticket: Ticket (gelöscht)+ meeting: Meeting (gelöscht)+ meeting_analysis: Analyse (gelöscht)unknown: Unbekanntsettings:# Tab-Label des KI-Bereichs (S2). Die Seitennamen des Bereichs stehen unterdiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 11fdc13..bb7bef8 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -2390,17 +2390,14 @@ en:project_announcement: "🔔 WHEN YOU'LL BE NOTIFIED:\n• Important project announcements\n• Release information\n• Deadline changes\n• Team meeting invitations\n\n⚙️ IMPORTANT:\n• Usually time-critical information\n• Affects all project members\n\n💡 TIP: You shouldn't deactivate these as they often contain important organizational information."system_message: "🔔 WHEN YOU'LL BE NOTIFIED:\n• Scheduled maintenance\n• New features and updates\n• Important system changes\n• Security updates\n\n⚙️ FREQUENCY:\n• Very rare (1-2x per month)\n• Only really important information\n\n💡 TIP: Should stay active as these messages can affect your work."power_search:- match_types:- fulltext: Full-text Match- semantic: Semantic Match- unknown: Unknown Match- object_types:- document: Document- document_deleted: Document (deleted)- note: Note- note_deleted: Note (deleted)- post: Post- ticket: Ticket+ # Title of a hit whose record is gone (PowerSearchService#result_title).+ deleted_titles:+ note: Note (deleted)+ document: Document (deleted)+ documentation: Documentation (deleted)+ ticket: Ticket (deleted)+ meeting: Meeting (deleted)+ meeting_analysis: Analysis (deleted)unknown: Unknownsettings:# Tab-Label des KI-Bereichs (S2). Die Seitennamen des Bereichs stehen unterdiff --git a/config/locales/views/ansichten.de.yml b/config/locales/views/ansichten.de.ymlindex 7144a3d..74168e3 100644--- a/config/locales/views/ansichten.de.yml+++ b/config/locales/views/ansichten.de.yml@@ -32,5 +32,13 @@ de:fulltext_match: Volltext Treffersemantic_match: Semantischer Trefferunknown_match: Unbekannter Treffer- similarity: 'Ähnlichkeit:'+ types:+ note: Notiz+ document: Dokument+ documentation: Dokumentation+ post: Kommentar+ ticket: Ticket+ meeting: Meeting+ meeting_analysis: Analyse+ unknown: Unbekanntno_results: Keine Treffer gefunden.diff --git a/config/locales/views/ansichten.en.yml b/config/locales/views/ansichten.en.ymlindex a330d7d..5247aa5 100644--- a/config/locales/views/ansichten.en.yml+++ b/config/locales/views/ansichten.en.yml@@ -32,5 +32,13 @@ en:fulltext_match: Full-text matchsemantic_match: Semantic matchunknown_match: Unknown match- similarity: 'Similarity:'+ types:+ note: Note+ document: Document+ documentation: Documentation+ post: Comment+ ticket: Ticket+ meeting: Meeting+ meeting_analysis: Analysis+ unknown: Unknownno_results: No results found.diff --git a/config/locales/views_extracted.de.yml b/config/locales/views_extracted.de.ymlindex db8387b..fb0998c 100644--- a/config/locales/views_extracted.de.yml+++ b/config/locales/views_extracted.de.yml@@ -277,10 +277,6 @@ de:power_search:index:title: Suchergebnisse- power_search_results:- match_fulltext: Volltext Treffer- match_semantic: Semantischer Treffer- match_unknown: Unbekannter Trefferactivities:shared:empty_title: Keine Aktivitäten gefundendiff --git a/config/locales/views_extracted.en.yml b/config/locales/views_extracted.en.ymlindex 5e1639d..8270d41 100644--- a/config/locales/views_extracted.en.yml+++ b/config/locales/views_extracted.en.yml@@ -269,10 +269,6 @@ en:power_search:index:title: Search results- power_search_results:- match_fulltext: Full-text match- match_semantic: Semantic match- match_unknown: Unknown matchactivities:shared:empty_title: No activities founddiff --git a/spec/requests/organisations/power_search_result_header_spec.rb b/spec/requests/organisations/power_search_result_header_spec.rbnew file mode 100644index 0000000..8b54de7--- /dev/null+++ b/spec/requests/organisations/power_search_result_header_spec.rb@@ -0,0 +1,63 @@+# frozen_string_literal: true++require 'rails_helper'++# The header of a search hit: what it is, which project, and since when the+# information exists. The service hands out stable keys (type, match types) and a+# date; the view owns the words, in the language of the request.+RSpec.describe 'Power search result header', type: :request do+ let(:organisation) { create(:organisation) }+ let(:user) { create(:user) }+ let(:role) { create(:admin_role, organisation: organisation) }+ let(:hit) do+ {+ type: :post,+ title: 'Export der Kundenliste',+ link: '#',+ project_name: 'Beispielprojekt',+ project_link: nil,+ date: Time.zone.local(2025, 3, 12, 10),+ content: 'Eine mögliche Abfrage',+ highlighted_content: nil,+ similarity: 0.9,+ match_types: %i[fulltext semantic],+ highlight: nil+ }+ end++ before do+ ActsAsTenant.with_tenant(organisation) do+ create(:membership, user: user, organisation: organisation, role: role, active: true)+ end+ ActsAsTenant.current_tenant = organisation+ sign_in user+ service = instance_double(PowerSearchService, execute: [hit], semantic_degraded?: false)+ allow(PowerSearchService).to receive(:new).and_return(service)+ end++ def header_for(locale)+ post organisation_power_search_path(organisation_id: organisation.id, locale: locale),+ params: { power_search_query: 'abfrage' }+ expect(response).to have_http_status(:ok)+ Nokogiri::HTML(response.body).at_css('.posts-container p').text.squish+ end++ it 'names the type, the project, the date and the match types in German' do+ expect(header_for(:de)).to eq('Kommentar Beispielprojekt 12.03.2025 Volltext Treffer Semantischer Treffer')+ end++ it 'names them in English' do+ expect(header_for(:en)).to eq('Comment Beispielprojekt 2025-03-12 Full-text match Semantic match')+ end++ it 'marks the date up as a machine-readable time' do+ header_for(:de)+ time = Nokogiri::HTML(response.body).at_css('.posts-container time')+ expect(time['datetime']).to eq('2025-03-12')+ end++ it 'leaves the date out when the hit has none' do+ hit[:date] = nil+ expect(header_for(:de)).to eq('Kommentar Beispielprojekt Volltext Treffer Semantischer Treffer')+ end+enddiff --git a/spec/services/power_search_service_privacy_spec.rb b/spec/services/power_search_service_privacy_spec.rbindex 4d45cf4..17d1c2a 100644--- a/spec/services/power_search_service_privacy_spec.rb+++ b/spec/services/power_search_service_privacy_spec.rb@@ -56,7 +56,7 @@ RSpec.describe PowerSearchService, type: :service doresults = service.execute# Filter only post results- post_results = results.select { |result| result[:type] == 'Post' }+ post_results = results.select { |result| result[:type] == :post }# User1 should see public posts and their own private postsexpect(post_results.map { |r| r[:title] }).to include(ticket.title) # public post@@ -82,7 +82,7 @@ RSpec.describe PowerSearchService, type: :service doresults = service.execute# Filter only post results- post_results = results.select { |result| result[:type] == 'Post' }+ post_results = results.select { |result| result[:type] == :post }# User2 should see public posts and their own private postsexpect(post_results.map { |r| r[:title] }).to include(ticket.title) # public post@@ -99,7 +99,7 @@ RSpec.describe PowerSearchService, type: :service doservice1 = described_class.new('privater geheimer inhalt von user1', organisation, project.id, user1)results1 = service1.execute- post_results1 = results1.select { |result| result[:type] == 'Post' }+ post_results1 = results1.select { |result| result[:type] == :post }expect(post_results1.size).to be > 0expect(post_results1.map { |r| r[:content] }.join).to include('privater geheimer inhalt von user1')@@ -107,7 +107,7 @@ RSpec.describe PowerSearchService, type: :service doservice2 = described_class.new('privater geheimer inhalt von user2', organisation, project.id, user2)results2 = service2.execute- post_results2 = results2.select { |result| result[:type] == 'Post' }+ post_results2 = results2.select { |result| result[:type] == :post }expect(post_results2.size).to be > 0expect(post_results2.map { |r| r[:content] }.join).to include('privater geheimer inhalt von user2')end@@ -119,7 +119,7 @@ RSpec.describe PowerSearchService, type: :service doservice = described_class.new('privater geheimer inhalt von user2', organisation, project.id, user1)results = service.execute- post_results = results.select { |result| result[:type] == 'Post' }+ post_results = results.select { |result| result[:type] == :post }# No post results should be found that contain user2's private contentpost_contents = post_results.map { |r| r[:content] }@@ -132,7 +132,7 @@ RSpec.describe PowerSearchService, type: :service doservice = described_class.new('geheimer', organisation, project.id, nil)results = service.execute- post_results = results.select { |result| result[:type] == 'Post' }+ post_results = results.select { |result| result[:type] == :post }# Without an authenticated user there is no project access -> no hits# (more restrictive than before; PowerSearch requires auth anyway).@@ -148,7 +148,7 @@ RSpec.describe PowerSearchService, type: :service doservice = described_class.new('geheimer', organisation, nil, user1)results = service.execute- post_results = results.select { |result| result[:type] == 'Post' }+ post_results = results.select { |result| result[:type] == :post }post_contents = post_results.map { |r| r[:content] }combined_content = post_contents.join@@ -172,7 +172,7 @@ RSpec.describe PowerSearchService, type: :service doservice = described_class.new('geheimer', organisation, project.id, user3)results = service.execute- post_results = results.select { |result| result[:type] == 'Post' }+ post_results = results.select { |result| result[:type] == :post }post_contents = post_results.map { |r| r[:content] }combined_content = post_contents.joindiff --git a/spec/services/power_search_service_spec.rb b/spec/services/power_search_service_spec.rbindex 1ad2259..fed0dc8 100644--- a/spec/services/power_search_service_spec.rb+++ b/spec/services/power_search_service_spec.rb@@ -130,7 +130,7 @@ RSpec.describe PowerSearchService, type: :service doresult = described_class.new('searchable', organisation, project.id, user).execute.firstexpect(result).to include(- type: 'Ticket',+ type: :ticket,title: 'Search Target',similarity: 0.85,highlighted_content: '<mark>searchable</mark>',@@ -140,7 +140,6 @@ RSpec.describe PowerSearchService, type: :service doexpect(result[:project_name]).to eq(project.name)expect(result[:project_link]).to be_presentexpect(result[:match_types]).to be_an(Array)- expect(result[:match_type]).to be_a(String)endit 'passes the query and organisation to QueryEmbedding' do@@ -317,49 +316,42 @@ RSpec.describe PowerSearchService, type: :service dostub_combined_search([fragment], similarity: 0.5)stub_highlights(fragment.id => '<mark>match</mark>')result = described_class.new('test', organisation).execute.first- expect(result[:match_types]).to eq(['Volltext Treffer'])+ expect(result[:match_types]).to eq([:fulltext])endit 'detects semantic match when similarity >= threshold' dostub_combined_search([fragment], similarity: 0.75)stub_highlights({})result = described_class.new('test', organisation).execute.first- expect(result[:match_types]).to eq(['Semantischer Treffer'])+ expect(result[:match_types]).to eq([:semantic])endit 'detects both match types when both conditions met' dostub_combined_search([fragment], similarity: 0.75)stub_highlights(fragment.id => '<mark>match</mark>')result = described_class.new('test', organisation).execute.first- expect(result[:match_types]).to contain_exactly('Volltext Treffer', 'Semantischer Treffer')+ expect(result[:match_types]).to contain_exactly(:fulltext, :semantic)endit 'falls back to unknown when neither condition met' dostub_combined_search([fragment], similarity: 0.5)stub_highlights({})result = described_class.new('test', organisation).execute.first- expect(result[:match_types]).to eq(['Unbekannter Treffer'])- end-- it 'sets match_type to first match_types entry for backwards compat' do- stub_combined_search([fragment], similarity: 0.75)- stub_highlights(fragment.id => '<mark>match</mark>')- result = described_class.new('test', organisation).execute.first- expect(result[:match_type]).to eq(result[:match_types].first)+ expect(result[:match_types]).to eq([:unknown])endit 'detects semantic match at exact threshold boundary (0.7)' dostub_combined_search([fragment], similarity: 0.7)stub_highlights({})result = described_class.new('test', organisation).execute.first- expect(result[:match_types]).to include('Semantischer Treffer')+ expect(result[:match_types]).to include(:semantic)endit 'does not detect semantic match just below threshold' dostub_combined_search([fragment], similarity: 0.6999)stub_highlights({})result = described_class.new('test', organisation).execute.first- expect(result[:match_types]).not_to include('Semantischer Treffer')+ expect(result[:match_types]).not_to include(:semantic)endend@@ -394,7 +386,7 @@ RSpec.describe PowerSearchService, type: :service dostub_highlights({})result = described_class.new('test', organisation).execute.first- expect(result[:type]).to eq('Note')+ expect(result[:type]).to eq(:note)expect(result[:title]).to eq('Test Note')end@@ -405,10 +397,36 @@ RSpec.describe PowerSearchService, type: :service dostub_highlights({})result = described_class.new('test', organisation).execute.first- expect(result[:type]).to eq('Ticket')+ expect(result[:type]).to eq(:ticket)expect(result[:title]).to eq('Test Ticket')end+ # Creation, not the last change: a status change must not make an old+ # ticket look fresh in the results.+ it 'dates a ticket by its creation, not its last change' do+ ticket = create(:ticket, project: project, organisation: organisation)+ ticket.update_columns(created_at: Time.zone.local(2025, 3, 12, 10), updated_at: Time.zone.local(2026, 10, 1, 9))+ fragment = create(:fragment, fragmentable: ticket, organisation: organisation)+ stub_combined_search([fragment])+ stub_highlights({})++ result = described_class.new('test', organisation).execute.first+ expect(result[:date].to_date).to eq(Date.new(2025, 3, 12))+ end++ it 'dates a comment by when it was written, not by its ticket' do+ ticket = create(:ticket, project: project, organisation: organisation)+ ticket.update_columns(created_at: Time.zone.local(2024, 1, 5, 10))+ post_record = create(:post, ticket: ticket, user: user, organisation: organisation, create_embeddings: false)+ post_record.update_columns(created_at: Time.zone.local(2025, 3, 12, 10))+ fragment = create(:fragment, fragmentable: post_record, organisation: organisation)+ stub_combined_search([fragment])+ stub_highlights({})++ result = described_class.new('test', organisation).execute.first+ expect(result[:date].to_date).to eq(Date.new(2025, 3, 12))+ end+it 'handles Post type' doticket = create(:ticket, project: project, organisation: organisation, title: 'Post Ticket')post_record = create(:post, ticket: ticket, user: user, organisation: organisation, create_embeddings: false)@@ -417,7 +435,7 @@ RSpec.describe PowerSearchService, type: :service dostub_highlights({})result = described_class.new('test', organisation).execute.first- expect(result[:type]).to eq('Post')+ expect(result[:type]).to eq(:post)expect(result[:title]).to eq('Post Ticket')end@@ -430,7 +448,7 @@ RSpec.describe PowerSearchService, type: :service dostub_highlights({})result = described_class.new('test', organisation).execute.first- expect(result[:type]).to eq('Dokument')+ expect(result[:type]).to eq(:document)expect(result[:title]).to eq('Doc Title')end@@ -441,7 +459,7 @@ RSpec.describe PowerSearchService, type: :service dostub_highlights({})result = described_class.new('test', organisation).execute.first- expect(result[:type]).to eq('Dokumentation')+ expect(result[:type]).to eq(:documentation)expect(result[:title]).to eq('Deployment Guide')endend@@ -498,13 +516,25 @@ RSpec.describe PowerSearchService, type: :service dodescribe '#result_type (private)' dosubject(:service) { described_class.new('q', organisation) }- it('maps Note') { expect(service.send(:result_type, 'Note')).to eq('Note') }- it('maps DocumentVersion') { expect(service.send(:result_type, 'DocumentVersion')).to eq('Dokument') }- it('maps DocumentationPage') { expect(service.send(:result_type, 'DocumentationPage')).to eq('Dokumentation') }- it('maps Post') { expect(service.send(:result_type, 'Post')).to eq('Post') }- it('maps Ticket') { expect(service.send(:result_type, 'Ticket')).to eq('Ticket') }- it('maps MeetingAnalysis') { expect(service.send(:result_type, 'MeetingAnalysis')).to eq('Analyse') }- it('maps unknown') { expect(service.send(:result_type, 'FooBar')).to eq('Unknown') }+ it('maps Note') { expect(service.send(:result_type, 'Note')).to eq(:note) }+ it('maps DocumentVersion') { expect(service.send(:result_type, 'DocumentVersion')).to eq(:document) }+ it('maps DocumentationPage') { expect(service.send(:result_type, 'DocumentationPage')).to eq(:documentation) }+ it('maps Post') { expect(service.send(:result_type, 'Post')).to eq(:post) }+ it('maps Ticket') { expect(service.send(:result_type, 'Ticket')).to eq(:ticket) }+ it('maps Meeting') { expect(service.send(:result_type, 'Meeting')).to eq(:meeting) }+ it('maps MeetingAnalysis') { expect(service.send(:result_type, 'MeetingAnalysis')).to eq(:meeting_analysis) }+ it('maps unknown') { expect(service.send(:result_type, 'FooBar')).to eq(:unknown) }++ # Every type has a label in both languages; a new type without one would show+ # "translation missing" in the results.+ it 'has a label for every type in DE and EN' do+ (described_class::RESULT_TYPES.values + [:unknown]).each do |type|+ %i[de en].each do |locale|+ key = "views.organisations.power_search.power_search_results.types.#{type}"+ expect(I18n.exists?(key, locale)).to be(true), "#{key} missing in #{locale}"+ end+ end+ endenddescribe '#result_title (private)' do@@ -519,7 +549,7 @@ RSpec.describe PowerSearchService, type: :service doit 'returns fallback when fragmentable is nil' dofragment = double('fragment', fragmentable_type: 'Note', fragmentable: nil)- expect(service.send(:result_title, fragment)).to eq('Note (deleted)')+ expect(service.send(:result_title, fragment)).to eq('Notiz (gelöscht)')endend@@ -534,13 +564,13 @@ RSpec.describe PowerSearchService, type: :service doit 'returns fallback when fragmentable is nil' dofragment = double('fragment', fragmentable_type: 'DocumentVersion', fragmentable: nil)- expect(service.send(:result_title, fragment)).to eq('Document (deleted)')+ expect(service.send(:result_title, fragment)).to eq('Dokument (gelöscht)')endit 'returns fallback when document is nil' doversion = double('document_version', document: nil)fragment = double('fragment', fragmentable_type: 'DocumentVersion', fragmentable: version)- expect(service.send(:result_title, fragment)).to eq('Document (deleted)')+ expect(service.send(:result_title, fragment)).to eq('Dokument (gelöscht)')endend@@ -559,7 +589,7 @@ RSpec.describe PowerSearchService, type: :service doit 'returns fallback when fragmentable is nil' dofragment = double('fragment', fragmentable_type: 'DocumentationPage', fragmentable: nil)- expect(service.send(:result_title, fragment)).to eq('Dokumentation (deleted)')+ expect(service.send(:result_title, fragment)).to eq('Dokumentation (gelöscht)')endend@@ -573,13 +603,13 @@ RSpec.describe PowerSearchService, type: :service doit 'returns fallback when fragmentable is nil' dofragment = double('fragment', fragmentable_type: 'Post', fragmentable: nil)- expect(service.send(:result_title, fragment)).to eq('Ticket (deleted)')+ expect(service.send(:result_title, fragment)).to eq('Ticket (gelöscht)')endit 'returns fallback when ticket is nil' dopost_record = double('post', ticket: nil)fragment = double('fragment', fragmentable_type: 'Post', fragmentable: post_record)- expect(service.send(:result_title, fragment)).to eq('Ticket (deleted)')+ expect(service.send(:result_title, fragment)).to eq('Ticket (gelöscht)')endend@@ -592,7 +622,7 @@ RSpec.describe PowerSearchService, type: :service doit 'returns fallback when fragmentable is nil' dofragment = double('fragment', fragmentable_type: 'Ticket', fragmentable: nil)- expect(service.send(:result_title, fragment)).to eq('Ticket (deleted)')+ expect(service.send(:result_title, fragment)).to eq('Ticket (gelöscht)')endend@@ -606,14 +636,14 @@ RSpec.describe PowerSearchService, type: :service doit 'returns fallback when fragmentable is nil' dofragment = double('fragment', fragmentable_type: 'MeetingAnalysis', fragmentable: nil)- expect(service.send(:result_title, fragment)).to eq('Analyse (deleted)')+ expect(service.send(:result_title, fragment)).to eq('Analyse (gelöscht)')endendcontext 'with unknown type' do- it 'returns Unknown' do+ it 'returns Unbekannt' dofragment = double('fragment', fragmentable_type: 'Unknown')- expect(service.send(:result_title, fragment)).to eq('Unknown')+ expect(service.send(:result_title, fragment)).to eq('Unbekannt')endendend@@ -923,22 +953,22 @@ RSpec.describe PowerSearchService, type: :service doit 'returns fulltext when highlight exists' doexpect(service.send(:determine_match_types, fragments, { fid => '<mark>x</mark>' }, { fid => 0.5 }))- .to eq(['Volltext Treffer'])+ .to eq([:fulltext])endit 'returns semantic when similarity >= threshold' doexpect(service.send(:determine_match_types, fragments, {}, { fid => 0.7 }))- .to eq(['Semantischer Treffer'])+ .to eq([:semantic])endit 'returns both when both conditions met' doexpect(service.send(:determine_match_types, fragments, { fid => '<mark>x</mark>' }, { fid => 0.8 }))- .to contain_exactly('Volltext Treffer', 'Semantischer Treffer')+ .to contain_exactly(:fulltext, :semantic)endit 'returns unknown when neither condition met' doexpect(service.send(:determine_match_types, fragments, {}, { fid => 0.3 }))- .to eq(['Unbekannter Treffer'])+ .to eq([:unknown])endend@@ -948,15 +978,15 @@ RSpec.describe PowerSearchService, type: :service dolet!(:fragment) { create(:fragment, fragmentable: ticket, organisation: organisation) }it 'returns hash with all required keys' do- result = service.send(:build_result, fragment, 0.85, '<mark>x</mark>', ['Volltext Treffer'])+ result = service.send(:build_result, fragment, 0.85, '<mark>x</mark>', [:fulltext])expect(result.keys).to contain_exactly(- :type, :title, :link, :project_name, :project_link, :content,- :highlighted_content, :similarity, :match_types, :match_type, :highlight+ :type, :title, :link, :project_name, :project_link, :date, :content,+ :highlighted_content, :similarity, :match_types, :highlight)endit 'includes project name and link' do- result = service.send(:build_result, fragment, 0.85, nil, ['Volltext Treffer'])+ result = service.send(:build_result, fragment, 0.85, nil, [:fulltext])expect(result[:project_name]).to eq(project.name)expect(result[:project_link]).to eq(Rails.application.routes.url_helpers.organisation_project_path(organisation, project)@@ -964,25 +994,20 @@ RSpec.describe PowerSearchService, type: :service doendit 'sets project keys to nil when project is missing' do- orphan = double('ticket', title: 'Orphan', project: nil, plain_text_version: '')+ orphan = double('ticket', title: 'Orphan', project: nil, plain_text_version: '', created_at: Time.current)orphan_fragment = double('fragment', fragmentable_type: 'Ticket', fragmentable: orphan)- result = service.send(:build_result, orphan_fragment, 0.5, nil, ['Unbekannter Treffer'])+ result = service.send(:build_result, orphan_fragment, 0.5, nil, [:unknown])expect(result[:project_name]).to be_nilexpect(result[:project_link]).to be_nilendit 'sets highlight equal to highlighted_content' do- result = service.send(:build_result, fragment, 0.85, '<mark>x</mark>', ['Volltext Treffer'])+ result = service.send(:build_result, fragment, 0.85, '<mark>x</mark>', [:fulltext])expect(result[:highlight]).to eq(result[:highlighted_content])end- it 'sets match_type to first element of match_types' do- result = service.send(:build_result, fragment, 0.85, nil, %w[A B])- expect(result[:match_type]).to eq('A')- end-it 'handles nil highlighted_content' do- result = service.send(:build_result, fragment, 0.5, nil, ['Unbekannter Treffer'])+ result = service.send(:build_result, fragment, 0.5, nil, [:unknown])expect(result[:highlighted_content]).to be_nilexpect(result[:highlight]).to be_nilend@@ -1074,11 +1099,17 @@ RSpec.describe PowerSearchService, type: :service do# 'Meeting', not 'Gespräch': the German UI term was settled as Meeting(s) and the search# result type follows the UI. This assertion kept the pre-rename wording.- expect(result).to include(type: 'Meeting', title: 'Kickoff-Gespräch')+ expect(result).to include(type: :meeting, title: 'Kickoff-Gespräch')expect(result[:project_name]).to eq(project.name)expect(result[:link]).to include("/meetings/#{meeting.id}")expect(result[:content]).to include('Preisliste')end++ it 'dates a meeting by the day it took place, not by the day it was entered' do+ meeting.update_columns(occurred_at: Time.zone.local(2025, 3, 12, 10), created_at: Time.zone.local(2026, 10, 1, 9))+ result = described_class.new('Preisliste', organisation, project.id, user).execute.first+ expect(result[:date].to_date).to eq(Date.new(2025, 3, 12))+ endend# Similarity source (embedding v2 PR 5, §3.4.1). This path re-scores the results of@@ -1107,7 +1138,7 @@ RSpec.describe PowerSearchService, type: :service doresult = described_class.new('q', organisation, project.id, user).execute.firstexpect(result[:similarity]).to be_within(1e-6).of(1.0)- expect(result[:match_types]).to include('Semantischer Treffer')+ expect(result[:match_types]).to include(:semantic)end# The §2.8 repro: before the fix this org scored 0.0 across the board.@@ -1125,7 +1156,7 @@ RSpec.describe PowerSearchService, type: :service doresult = described_class.new('q', organisation, project.id, user).execute.firstexpect(result[:similarity]).to be_within(1e-6).of(1.0)- expect(result[:match_types]).to include('Semantischer Treffer')+ expect(result[:match_types]).to include(:semantic)end# Fail-soft is UNCHANGED, only its source moved: a fragment without a row in the@@ -1139,7 +1170,7 @@ RSpec.describe PowerSearchService, type: :service doresult = described_class.new('q', organisation, project.id, user).execute.firstexpect(result[:similarity]).to eq(0.0)- expect(result[:match_types]).to eq(['Unbekannter Treffer'])+ expect(result[:match_types]).to eq([:unknown])end# A row of the OLD space stays indexed: true until PR 6 retires it — it must not