www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 362e18c7471fc15cf6c7a1f0e10f2bb04f8e5367
parent 751ab9df081b1c2010b0443fae227585e9dfdd08
Author: Dan Stillman <dstillman@zotero.org>
Date:   Thu, 19 Jan 2017 13:32:29 -0500

Fix attachment content search

And always convert ids from GROUP_CONCAT() to integers in search code.

Diffstat:
Mchrome/content/zotero/xpcom/data/search.js | 17+++++++----------
Mtest/tests/searchTest.js | 27++++++++++++++++++++++-----
2 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/search.js b/chrome/content/zotero/xpcom/data/search.js @@ -603,7 +603,7 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable sql += ")"; var res = yield Zotero.DB.valueQueryAsync(sql, this._sqlParams); - var ids = res ? res.split(",") : []; + var ids = res ? res.split(",").map(id => parseInt(id)) : []; /* // DEBUG: Should this be here? // @@ -653,7 +653,7 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable var sql = "SELECT GROUP_CONCAT(itemID) FROM items WHERE " + "itemID NOT IN (SELECT itemID FROM " + tmpTable + ")"; var res = yield Zotero.DB.valueQueryAsync(sql); - var scopeIDs = res ? res.split(",") : []; + var scopeIDs = res ? res.split(",").map(id => parseInt(id)) : []; } // If an ALL search, scan only items from the main search else { @@ -701,7 +701,7 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable if (joinMode == 'all' && !hasQuicksearch) { var hash = {}; for (let i=0; i<fulltextWordIDs.length; i++) { - hash[fulltextWordIDs[i].id] = true; + hash[fulltextWordIDs[i]] = true; } if (ids) { @@ -791,15 +791,12 @@ Zotero.Search.prototype.search = Zotero.Promise.coroutine(function* (asTempTable sql = "SELECT GROUP_CONCAT(itemID) FROM items WHERE itemID IN (" + sql + ")"; var res = yield Zotero.DB.valueQueryAsync(sql); - var parentChildIDs = res ? res.split(",") : []; + var parentChildIDs = res ? res.split(",").map(id => parseInt(id)) : []; // Add parents and children to main ids - if (parentChildIDs) { - for (var i=0; i<parentChildIDs.length; i++) { - var id = parentChildIDs[i]; - if (ids.indexOf(id) == -1) { - ids.push(id); - } + for (let id of parentChildIDs) { + if (!ids.includes(id)) { + ids.push(id); } } } diff --git a/test/tests/searchTest.js b/test/tests/searchTest.js @@ -14,11 +14,7 @@ describe("Zotero.Search", function() { var s = new Zotero.Search; s.name = "Test"; s.addCondition('title', 'is', 'test'); - Zotero.debug("BEFORE SAVING"); - Zotero.debug(s._conditions); var id = yield s.saveTx(); - Zotero.debug("DONE SAVING"); - Zotero.debug(s._conditions); assert.typeOf(id, 'number'); // Check saved search @@ -27,7 +23,6 @@ describe("Zotero.Search", function() { assert.instanceOf(s, Zotero.Search); assert.equal(s.libraryID, Zotero.Libraries.userLibraryID); assert.equal(s.name, "Test"); - Zotero.debug("GETTING CONDITIONS"); var conditions = s.getConditions(); assert.lengthOf(Object.keys(conditions), 1); assert.property(conditions, "0"); @@ -106,6 +101,28 @@ describe("Zotero.Search", function() { }); describe("Conditions", function () { + describe("attachmentContent", function () { + it("should find text in HTML files", function* () { + var s = new Zotero.Search(); + s.libraryID = foobarItem.libraryID; + s.addCondition('fulltextContent', 'contains', 'foo bar'); + var matches = yield s.search(); + assert.sameMembers(matches, [foobarItem.id]); + }); + + it("should work in subsearch", function* () { + var s = new Zotero.Search(); + s.libraryID = foobarItem.libraryID; + s.addCondition('fulltextContent', 'contains', 'foo bar'); + + var s2 = new Zotero.Search(); + s2.setScope(s); + s2.addCondition('title', 'contains', 'foobar'); + var matches = yield s2.search(); + assert.sameMembers(matches, [foobarItem.id]); + }); + }); + describe("collection", function () { it("should find item in collection", function* () { var col = yield createDataObject('collection');