Fixes #621, saved search displays child items in black even if only parent item matches search criteria

Addresses #597, Don't iterate Array with for...in

Also fixes child items displaying twice in saved search reports and adds proper collation support in reports
This commit is contained in:
Dan Stillman 2007-04-21 21:18:05 +00:00
parent beba35b44a
commit 46a5e4b195
2 changed files with 54 additions and 36 deletions

View file

@ -22,6 +22,7 @@
Zotero.Search = function(savedSearchID){
this._scope = null;
this._scopeIncludeChildren = null;
this._sql = null;
this._sqlParams = null;
this._maxSearchConditionID = 0;
@ -235,8 +236,9 @@ Zotero.Search.prototype.addCondition = function(condition, operator, value, requ
/*
* Sets scope of search to the results of the passed Search object
*/
Zotero.Search.prototype.setScope = function (searchObj) {
Zotero.Search.prototype.setScope = function (searchObj, includeChildren) {
this._scope = searchObj;
this._scopeIncludeChildren = includeChildren;
}
@ -323,6 +325,21 @@ Zotero.Search.prototype.search = function(asTempTable){
this._buildQuery();
}
var joinMode = 'all';
for each(var condition in this._conditions) {
switch (condition.condition) {
case 'joinMode':
if (condition.operator == 'any') {
joinMode = 'any';
}
break;
case 'blockStart':
var hasQuicksearch = true;
break;
}
}
if (this._scope) {
// If subsearch has post-search filter, run and insert ids into temp table
if (this._scope.hasPostSearchFilter()) {
@ -343,15 +360,18 @@ Zotero.Search.prototype.search = function(asTempTable){
Zotero.DB.query(sql);
}
// Search ids in temp table and their child items
// Search ids in temp table
var sql = "SELECT itemID FROM items WHERE itemID IN (" + this._sql + ") "
+ "AND ("
+ "itemID IN (SELECT itemID FROM " + tmpTable + ") OR "
+ "itemID IN (SELECT itemID FROM itemAttachments"
+ "itemID IN (SELECT itemID FROM " + tmpTable + ")";
if (this._scopeIncludeChildren) {
sql += " OR itemID IN (SELECT itemID FROM itemAttachments"
+ " WHERE sourceItemID IN (SELECT itemID FROM " + tmpTable + ")) OR "
+ "itemID IN (SELECT itemID FROM itemNotes"
+ " WHERE sourceItemID IN (SELECT itemID FROM " + tmpTable + "))"
+ ")";
+ " WHERE sourceItemID IN (SELECT itemID FROM " + tmpTable + "))";
}
sql += ")";
var ids = Zotero.DB.columnQuery(sql, this._sqlParams);
Zotero.DB.query("DROP TABLE " + tmpTable);
@ -363,25 +383,9 @@ Zotero.Search.prototype.search = function(asTempTable){
//Zotero.debug('IDs from main search: ');
//Zotero.debug(ids);
var joinMode = 'all';
for each(var condition in this._conditions) {
if (condition.condition == 'joinMode') {
if (condition.operator == 'any') {
joinMode = 'any';
}
break;
}
}
//Zotero.debug('Join mode: ' + joinMode);
for each(var condition in this._conditions) {
if (condition.condition == 'blockStart') {
var hasQuicksearch = true;
break;
}
}
// Filter results with fulltext search
//
// If join mode ALL, return the (union of main and fulltext word search)

View file

@ -107,19 +107,28 @@ function ChromeExtensionHandler() {
case 'search':
var s = new Zotero.Search(ids);
var items = Zotero.Items.get(s.search());
var ids = s.search();
break;
case 'items':
case 'item':
var items = Zotero.Items.get(ids.split('-'));
var ids = ids.split('-');
break;
default:
var type = 'library';
var s = new Zotero.Search();
s.addCondition('noChildren', 'true');
var items = Zotero.Items.get(s.search());
var ids = s.search();
}
var results = Zotero.Items.get(ids);
var items = [];
// Only include parent items
for (var i=0; i<results.length; i++) {
if (!results[i].getSource()) {
items.push(results[i]);
}
}
if (!items){
@ -128,18 +137,13 @@ function ChromeExtensionHandler() {
break generateContent;
}
// Convert item objects to export arrays
for (var i in items) {
items[i] = items[i].toArray();
}
// Sort items
if (!sortBy) {
sortBy = 'title';
}
var sorts = sortBy.split(',');
for (var i in sorts) {
for (var i=0; i<sorts.length; i++) {
var [field, order] = sorts[i].split('/');
switch (order) {
case 'd':
@ -157,17 +161,23 @@ function ChromeExtensionHandler() {
};
}
var collation = Zotero.getLocaleCollation();
var compareFunction = function(a, b) {
var index = 0;
// Multidimensional sort
do {
var result = a[sorts[index].field] > b[sorts[index].field] ?
sorts[index].order
: a[sorts[index].field] < b[sorts[index].field] ?
(sorts[index].order * -1)
: 0;
var cmp = collation.compareString(0,
a.getField(sorts[index].field),
b.getField(sorts[index].field)
);
if (cmp == 0) {
continue;
}
var result = cmp * sorts[index].order;
index++;
}
while (result == 0 && sorts[index]);
@ -177,6 +187,10 @@ function ChromeExtensionHandler() {
items.sort(compareFunction);
// Convert item objects to export arrays
for (var i=0; i<items.length; i++) {
items[i] = items[i].toArray();
}
// Pass off to the appropriate handler
switch (format){