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
This commit is contained in:
abaevbog 2025-04-03 21:27:46 -07:00 • committed by GitHub
parent 0b8b4c0ff6
commit 3d538d71ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 4 deletions

View file

@ -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);

View file

@ -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