[duplicates] DOIs are not case sensitive
This commit is contained in:
parent
d291084af6
commit
d30ab9cc4f
|
@ -124,6 +124,18 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortByValue(a, b) {
|
||||||
|
if((a.value === null && b.value !== null)
|
||||||
|
|| (a.value === undefined && b.value !== undefined)
|
||||||
|
|| a.value < b.value) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(a.value === b.value) return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Function} compareRows Comparison function, if not exact match
|
* @param {Function} compareRows Comparison function, if not exact match
|
||||||
* @param {Boolean} reprocessMatches Compare every row against every other,
|
* @param {Boolean} reprocessMatches Compare every row against every other,
|
||||||
|
@ -181,8 +193,7 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
|
||||||
var sql = "SELECT itemID, value FROM items JOIN itemData USING (itemID) "
|
var sql = "SELECT itemID, value FROM items JOIN itemData USING (itemID) "
|
||||||
+ "JOIN itemDataValues USING (valueID) "
|
+ "JOIN itemDataValues USING (valueID) "
|
||||||
+ "WHERE libraryID=? AND itemTypeID=? AND fieldID=? "
|
+ "WHERE libraryID=? AND itemTypeID=? AND fieldID=? "
|
||||||
+ "AND itemID NOT IN (SELECT itemID FROM deletedItems) "
|
+ "AND itemID NOT IN (SELECT itemID FROM deletedItems)";
|
||||||
+ "ORDER BY value";
|
|
||||||
var rows = Zotero.DB.query(
|
var rows = Zotero.DB.query(
|
||||||
sql,
|
sql,
|
||||||
[
|
[
|
||||||
|
@ -194,25 +205,28 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
|
||||||
var isbnCache = {};
|
var isbnCache = {};
|
||||||
if (rows) {
|
if (rows) {
|
||||||
for each(var row in rows) {
|
for each(var row in rows) {
|
||||||
isbnCache[row.itemID] = (row.value+'').replace(/[^\dX]+/ig, '').toUpperCase(); //ignore formatting
|
row.value = (row.value+'').replace(/[^\dX]+/ig, '').toUpperCase(); //ignore formatting
|
||||||
}
|
isbnCache[row.itemID] = row.value;
|
||||||
}
|
}
|
||||||
|
rows.sort(sortByValue);
|
||||||
processRows();
|
processRows();
|
||||||
|
}
|
||||||
|
|
||||||
// DOI
|
// DOI
|
||||||
var sql = "SELECT itemID, value FROM items JOIN itemData USING (itemID) "
|
var sql = "SELECT itemID, value FROM items JOIN itemData USING (itemID) "
|
||||||
+ "JOIN itemDataValues USING (valueID) "
|
+ "JOIN itemDataValues USING (valueID) "
|
||||||
+ "WHERE libraryID=? AND fieldID=? AND REGEXP('^10\\.', value) "
|
+ "WHERE libraryID=? AND fieldID=? AND REGEXP('^10\\.', value) "
|
||||||
+ "AND itemID NOT IN (SELECT itemID FROM deletedItems) "
|
+ "AND itemID NOT IN (SELECT itemID FROM deletedItems)";
|
||||||
+ "ORDER BY value";
|
|
||||||
var rows = Zotero.DB.query(sql, [this._libraryID, Zotero.ItemFields.getID('DOI')]);
|
var rows = Zotero.DB.query(sql, [this._libraryID, Zotero.ItemFields.getID('DOI')]);
|
||||||
var doiCache = {};
|
var doiCache = {};
|
||||||
if (rows) {
|
if (rows) {
|
||||||
for each(var row in rows) {
|
for each(var row in rows) {
|
||||||
doiCache[row.itemID] = row.value.toString().trim();
|
row.value = (row.value+'').trim().toUpperCase(); //DOIs are case insensitive
|
||||||
}
|
doiCache[row.itemID] = row.value;
|
||||||
}
|
}
|
||||||
|
rows.sort(sortByValue);
|
||||||
processRows();
|
processRows();
|
||||||
|
}
|
||||||
|
|
||||||
// Get years
|
// Get years
|
||||||
var dateFields = [Zotero.ItemFields.getID('date')].concat(
|
var dateFields = [Zotero.ItemFields.getID('date')].concat(
|
||||||
|
@ -242,24 +256,22 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
|
||||||
+ "WHERE libraryID=? AND fieldID BETWEEN 110 AND 113 "
|
+ "WHERE libraryID=? AND fieldID BETWEEN 110 AND 113 "
|
||||||
+ "AND itemTypeID NOT IN (1, 14) "
|
+ "AND itemTypeID NOT IN (1, 14) "
|
||||||
+ "AND itemID NOT IN (SELECT itemID FROM deletedItems)";
|
+ "AND itemID NOT IN (SELECT itemID FROM deletedItems)";
|
||||||
var rows = Zotero.DB.query(sql, [this._libraryID]) || [];
|
var rows = Zotero.DB.query(sql, [this._libraryID]);
|
||||||
// Normalize all values ahead of time
|
if(rows) {
|
||||||
|
//normalize all values ahead of time
|
||||||
rows = rows.map(function(row) {
|
rows = rows.map(function(row) {
|
||||||
row.value = normalizeString(row.value);
|
row.value = normalizeString(row.value);
|
||||||
return row;
|
return row;
|
||||||
});
|
});
|
||||||
// Sort rows by normalized values
|
//sort rows by normalized values
|
||||||
rows = rows.sort(function(a, b) {
|
rows.sort(sortByValue);
|
||||||
if(a.value === b.value) return 0;
|
|
||||||
if(a.value < b.value) return -1;
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
processRows(function (a, b) {
|
processRows(function (a, b) {
|
||||||
var aTitle = a.value;
|
var aTitle = a.value;
|
||||||
var bTitle = b.value;
|
var bTitle = b.value;
|
||||||
|
|
||||||
// If we stripped one of the strings completely, we can't compare them
|
// If we stripped one of the strings completely, we can't compare them
|
||||||
if (aTitle.length == 0 || bTitle.length == 0) {
|
if(!aTitle || !bTitle) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,6 +352,7 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}, true);
|
}, true);
|
||||||
|
}
|
||||||
|
|
||||||
// Match on exact fields
|
// Match on exact fields
|
||||||
/*var fields = [''];
|
/*var fields = [''];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user