Skip to content

Commit dac1d6e

Browse files
committed
Always include citationKey in search results
1 parent 35aac85 commit dac1d6e

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/tools/search.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ const SearchSchema = z
6060
.optional()
6161
.describe("Exclude subgroups from the search (optional)"),
6262
limit: z.number().optional().describe("Maximum number of results to return (optional)"),
63-
includeBibliography: z
64-
.boolean()
65-
.optional()
66-
.describe(
67-
"Include citation key and bibliography metadata in results (optional, default false)",
68-
),
6963
})
7064
.strict()
7165
.refine(
@@ -92,6 +86,7 @@ interface SearchResult {
9286
success: boolean;
9387
error?: string;
9488
results?: Array<{
89+
citationKey: string;
9590
id: number;
9691
uuid: string;
9792
name: string;
@@ -104,8 +99,6 @@ interface SearchResult {
10499
modificationDate?: string;
105100
tags?: string[];
106101
size?: number;
107-
citationKey?: string | null;
108-
bibliographyTitle?: string | null;
109102
}>;
110103
totalCount?: number;
111104
}
@@ -122,7 +115,6 @@ const search = async (input: SearchInput): Promise<SearchResult> => {
122115
comparison,
123116
excludeSubgroups,
124117
limit = 50,
125-
includeBibliography = false,
126118
} = input;
127119

128120
// Validate inputs
@@ -284,6 +276,7 @@ const search = async (input: SearchInput): Promise<SearchResult> => {
284276
const results = limitedResults.map((record, index) => {
285277
try {
286278
const result = {};
279+
result["citationKey"] = "";
287280
result["id"] = record.id();
288281
result["uuid"] = record.uuid();
289282
result["name"] = record.name();
@@ -317,22 +310,24 @@ const search = async (input: SearchInput): Promise<SearchResult> => {
317310

318311
const result = await executeJxa<SearchResult>(script);
319312

320-
// Enrich results with bibliography metadata if requested
321-
if (includeBibliography && result.success && result.results) {
313+
// Always enrich results with citation keys from Zotero bibliography
314+
if (result.success && result.results) {
315+
const hasConfig = process.env.BIBLIOGRAPHY_JSON || process.env.BIBLIOGRAPHY_BIB;
316+
322317
for (const record of result.results) {
318+
if (!hasConfig) {
319+
// Skip lookup if no config - leave as empty string
320+
continue;
321+
}
322+
323323
try {
324324
const metadata = await lookupBibliographyMetadataByPath(record.path);
325-
if (metadata.success) {
326-
record.citationKey = metadata.descriptor.citationKey ?? null;
327-
record.bibliographyTitle = metadata.descriptor.title ?? null;
328-
} else {
329-
record.citationKey = null;
330-
record.bibliographyTitle = null;
325+
if (metadata.success && metadata.descriptor.citationKey) {
326+
record.citationKey = metadata.descriptor.citationKey;
331327
}
332-
} catch {
333-
// Silently skip if lookup fails
334-
record.citationKey = null;
335-
record.bibliographyTitle = null;
328+
// If no match found, keep empty string
329+
} catch (error) {
330+
// Lookup failed - keep empty string
336331
}
337332
}
338333
}

0 commit comments

Comments
 (0)