Fix attachment content search
And always convert ids from GROUP_CONCAT() to integers in search code.
This commit is contained in:
parent
751ab9df08
commit
362e18c747
2 changed files with 29 additions and 15 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Add table
Reference in a new issue