From 3d538d71ca6b861a1dac35d0e8627a7a20c45c4e Mon Sep 17 00:00:00 2001 From: abaevbog Date: Thu, 3 Apr 2025 21:27:46 -0700 Subject: [PATCH] citation dlg: search by identifier (#5182) - if the search string looks like a DOI or ISBN, use it as a search condition. https://forums.zotero.org/discussion/comment/489309/#Comment_489309 - have library use "All Fields & Tags" search mode. Followup to zotero@b78bf8e --- .../zotero/integration/citationDialog.js | 2 +- .../citationDialog/searchHandler.mjs | 23 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/integration/citationDialog.js b/chrome/content/zotero/integration/citationDialog.js index c158f970a0..d7f8922825 100644 --- a/chrome/content/zotero/integration/citationDialog.js +++ b/chrome/content/zotero/integration/citationDialog.js @@ -645,7 +645,7 @@ class LibraryLayout extends Layout { }, isSearch: () => true, isSearchMode: () => true, - setSearch: str => collectionTreeRow.setSearch(str), + setSearch: (searchText, mode) => collectionTreeRow.setSearch(searchText, mode), ref: collectionTreeRow.ref }); await this.itemsView.setFilter('search', SearchHandler.searchValue); diff --git a/chrome/content/zotero/integration/citationDialog/searchHandler.mjs b/chrome/content/zotero/integration/citationDialog/searchHandler.mjs index f3e73e1ca8..84ba31c25d 100644 --- a/chrome/content/zotero/integration/citationDialog/searchHandler.mjs +++ b/chrome/content/zotero/integration/citationDialog/searchHandler.mjs @@ -195,7 +195,12 @@ export class CitationDialogSearchHandler { cleanSearchQuery(str) { str = str.replace(/ (?:&|and) /g, " ", "g").replace(/^,/, ''); - str = this._cleanYear(str); + let isbn = Zotero.Utilities.cleanISBN(str); + let doi = Zotero.Utilities.cleanDOI(str); + // if the string looks like an identifier, do not try to extract the year + if (!(isbn || doi)) { + str = this._cleanYear(str); + } str = str.trim(); // If the query is very short, treat it as empty @@ -228,8 +233,20 @@ export class CitationDialogSearchHandler { s.addCondition("quicksearch-titleCreatorYearNote", "contains", this.searchValue); } else if (realInputRegex.test(this.searchValue)) { - s.addCondition("quicksearch-titleCreatorYear", "contains", this.searchValue); - s.addCondition("itemType", "isNot", "attachment"); + // search for the identifier if it is provided, + // otherwise look up by title, creator and year + let isDOI = Zotero.Utilities.cleanDOI(this.searchValue); + let isISBN = Zotero.Utilities.cleanISBN(this.searchValue); + if (isDOI) { + s.addCondition("DOI", "contains", this.searchValue); + } + else if (isISBN) { + s.addCondition("ISBN", "contains", this.searchValue); + } + else { + s.addCondition("quicksearch-titleCreatorYear", "contains", this.searchValue); + s.addCondition("itemType", "isNot", "attachment"); + } } let searchResultIDs = await s.search(); // Search results might be in an unloaded library, so get items asynchronously and load necessary data