prefer file names for clinical sources
This commit is contained in:
parent
e258b0875b
commit
8921dbaa32
2 changed files with 34 additions and 5 deletions
|
|
@ -224,17 +224,18 @@ function displayTitleForSource(source, fallback) {
|
|||
source = source || {};
|
||||
var rawTitle = String(source.title || '').trim();
|
||||
var filePath = source.file_path || source.filePath || source.path || '';
|
||||
if (looksLikeInternalPdfTitle(rawTitle)) {
|
||||
var fromPath = titleFromPath(filePath);
|
||||
if (fromPath) return cleanTitle(fromPath);
|
||||
var fromPath = titleFromPath(filePath);
|
||||
if (fromPath) return cleanTitle(fromPath);
|
||||
if (looksLikePdfMetadataJunk(rawTitle)) {
|
||||
var mapped = INTERNAL_TITLE_FALLBACKS[String(source.id || '')] || INTERNAL_TITLE_FALLBACKS[rawTitle];
|
||||
if (mapped) return mapped;
|
||||
}
|
||||
return cleanTitle(rawTitle || filePath || fallback || 'Untitled resource');
|
||||
}
|
||||
|
||||
function looksLikeInternalPdfTitle(title) {
|
||||
return /\.qxd$/i.test(String(title || '').trim());
|
||||
function looksLikePdfMetadataJunk(title) {
|
||||
title = String(title || '').trim();
|
||||
return /\.qxd$/i.test(title) || /^https?:\/\//i.test(title) || /^www\./i.test(title);
|
||||
}
|
||||
|
||||
function titleFromPath(filePath) {
|
||||
|
|
|
|||
|
|
@ -46,6 +46,34 @@ test('clinical retrieval leaves normal source titles unchanged', () => {
|
|||
assert.equal(results[0].title, 'Nelson Textbook of Pediatrics');
|
||||
});
|
||||
|
||||
test('clinical retrieval always prefers file basename over PDF metadata title', () => {
|
||||
const results = normalizeMcpSearchResponse({
|
||||
results: [{
|
||||
id: 321,
|
||||
doc_type: 'file',
|
||||
title: 'Dermatology, Second Edition: 2-Volume Set (Bolognia, Dermatology)',
|
||||
file_path: 'Medical Library/Dermatology/My%20Named%20Dermatology%20Source.pdf',
|
||||
excerpt: 'Dermatologic therapy text'
|
||||
}]
|
||||
});
|
||||
|
||||
assert.equal(results[0].title, 'My Named Dermatology Source');
|
||||
});
|
||||
|
||||
test('clinical retrieval prefers file basename for URL PDF metadata titles', () => {
|
||||
const results = normalizeMcpSearchResponse({
|
||||
results: [{
|
||||
id: 456,
|
||||
doc_type: 'file',
|
||||
title: 'https://bookbaz.ir',
|
||||
file_path: 'Medical Library/Dermatology/Bolognia%20Dermatology%20Second%20Edition.pdf',
|
||||
excerpt: 'Dermatologic therapy text'
|
||||
}]
|
||||
});
|
||||
|
||||
assert.equal(results[0].title, 'Bolognia Dermatology Second Edition');
|
||||
});
|
||||
|
||||
test('clinical retrieval strips image markdown while preserving OCR table text', () => {
|
||||
const results = normalizeMcpSearchResponse({
|
||||
results: [{
|
||||
|
|
|
|||
Loading…
Reference in a new issue