Tweaks to duplicate detection

This commit is contained in:
Aurimas Vinckevicius 2013-02-23 19:25:06 -06:00 committed by aurimasv
parent 8f263d0fd9
commit 42f9aaa8a1

View file

@ -117,8 +117,8 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
}
str = Zotero.Utilities.removeDiacritics(str)
.replace(/[!-/:-@[-`{-~]/g, ' ') // Convert (ASCII) punctuation to spaces
.replace(/ +/, ' ') // Normalize spaces
.replace(/[ !-/:-@[-`{-~]+/g, ' ') // Convert (ASCII) punctuation to spaces
.trim()
.toLowerCase();
return str;
@ -194,7 +194,7 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
var isbnCache = {};
if (rows) {
for each(var row in rows) {
isbnCache[row.itemID] = row.value;
isbnCache[row.itemID] = row.value.replace(/[^\dX]+/ig, '').toUpperCase(); //ignore formatting
}
}
processRows();
@ -209,7 +209,7 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
var doiCache = {};
if (rows) {
for each(var row in rows) {
doiCache[row.itemID] = row.value;
doiCache[row.itemID] = row.value.trim();
}
}
processRows();
@ -279,6 +279,7 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
}
// Check for at least one match on last name + first initial of first name
var aCreatorRows, bCreatorRows;
if (typeof creatorRowsCache[a.itemID] != 'undefined') {
aCreatorRows = creatorRowsCache[a.itemID];
}
@ -287,7 +288,7 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
+ "JOIN creators USING (creatorID) "
+ "JOIN creatorData USING (creatorDataID) "
+ "WHERE itemID=? ORDER BY orderIndex LIMIT 10";
var aCreatorRows = Zotero.DB.query(sql, a.itemID);
aCreatorRows = Zotero.DB.query(sql, a.itemID);
creatorRowsCache[a.itemID] = aCreatorRows;
}
@ -300,12 +301,12 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
+ "JOIN creators USING (creatorID) "
+ "JOIN creatorData USING (creatorDataID) "
+ "WHERE itemID=? ORDER BY orderIndex LIMIT 10";
var bCreatorRows = Zotero.DB.query(sql, b.itemID);
bCreatorRows = Zotero.DB.query(sql, b.itemID);
creatorRowsCache[b.itemID] = bCreatorRows;
}
// Match if no creators
if (!aCreatorRows && !bCreatorRows.length) {
if (!aCreatorRows && !bCreatorRows) {
return 1;
}
@ -315,11 +316,11 @@ Zotero.Duplicates.prototype._findDuplicates = function () {
for each(var aCreatorRow in aCreatorRows) {
var aLastName = normalizeString(aCreatorRow.lastName);
var aFirstInitial = aCreatorRow.fieldMode == 0 ? normalizeString(aCreatorRow.firstName.substr(1)) : false;
var aFirstInitial = aCreatorRow.fieldMode == 0 ? normalizeString(aCreatorRow.firstName).charAt(0) : false;
for each(var bCreatorRow in bCreatorRows) {
var bLastName = normalizeString(bCreatorRow.lastName);
var bFirstInitial = bCreatorRow.fieldMode == 0 ? normalizeString(bCreatorRow.firstName.substr(1)) : false;
var bFirstInitial = bCreatorRow.fieldMode == 0 ? normalizeString(bCreatorRow.firstName).charAt(0) : false;
if (aLastName === bLastName && aFirstInitial === bFirstInitial) {
return 1;