From 9d8c427d1e5e7d6ddbfe74c7ab40f51ce667d74f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 20 Jul 2007 19:06:29 +0000 Subject: [PATCH] Addresses #680, Implement left-bound search pref Implemented for tags and the fulltext word index, which should speed things up a bit. Not implemented for notes and fields, since those might have multiple words -- would have to put them in the fulltext word index... --- .../zotero/xpcom/collectionTreeView.js | 2 +- chrome/content/zotero/xpcom/search.js | 26 ++++++++++++++++--- defaults/preferences/zotero.js | 1 + 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index ba7b61949..ea4d65328 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -887,7 +887,7 @@ Zotero.ItemGroup.prototype.getChildItems = function() var ids = s.search(); } catch (e) { - if (e.match(/Saved search [0-9]+ does not exist/)) { + if (typeof e == 'string' && e.match(/Saved search [0-9]+ does not exist/)) { Zotero.DB.rollbackTransaction(); Zotero.debug(e, 2); return false; diff --git a/chrome/content/zotero/xpcom/search.js b/chrome/content/zotero/xpcom/search.js index c8e760e0f..20f08a2f5 100644 --- a/chrome/content/zotero/xpcom/search.js +++ b/chrome/content/zotero/xpcom/search.js @@ -584,6 +584,7 @@ Zotero.Search.prototype._buildQuery = function(){ field: data['field'], operator: this._conditions[i]['operator'], value: this._conditions[i]['value'], + flags: data['flags'], required: this._conditions[i]['required'] }); @@ -926,7 +927,14 @@ Zotero.Search.prototype._buildQuery = function(){ case 'contains': case 'doesNotContain': // excluded with NOT IN above condSQL += ' LIKE ?'; - condSQLParams.push('%' + condition['value'] + '%'); + if (condition['flags'] && + condition['flags']['leftbound'] && + Zotero.Prefs.get('search.useLeftBound')) { + condSQLParams.push(condition['value'] + '%'); + } + else { + condSQLParams.push('%' + condition['value'] + '%'); + } break; case 'is': @@ -1120,6 +1128,10 @@ Zotero.SearchConditions = new function(){ /* * Define and set up the available advanced search conditions + * + * Flags: + * - special + * - template */ function _init(){ _conditions = [ @@ -1266,7 +1278,10 @@ Zotero.SearchConditions = new function(){ doesNotContain: true }, table: 'itemTags', - field: 'tag' + field: 'tag', + flags: { + leftbound: true + } }, { @@ -1356,6 +1371,9 @@ Zotero.SearchConditions = new function(){ }, table: 'fulltextItemWords', field: 'word', + flags: { + leftbound: true + }, special: true }, @@ -1414,11 +1432,13 @@ Zotero.SearchConditions = new function(){ sortValues[localized] = { name: i, localized: localized, - operators: _conditions[i]['operators'] + operators: _conditions[i]['operators'], + flags: _conditions[i]['flags'] }; } // Alphabetize by localized name + // TODO: locale collation sort sortKeys = sortKeys.sort(); for each(var i in sortKeys){ _standardConditions.push(sortValues[i]); diff --git a/defaults/preferences/zotero.js b/defaults/preferences/zotero.js index 10a2d3a2e..787874cd6 100644 --- a/defaults/preferences/zotero.js +++ b/defaults/preferences/zotero.js @@ -38,6 +38,7 @@ pref("extensions.zotero.keys.copySelectedItemsToClipboard", 'C'); // Fulltext indexing pref("extensions.zotero.fulltext.textMaxLength", 500000); pref("extensions.zotero.fulltext.pdfMaxPages", 100); +pref("extensions.zotero.search.useLeftBound", true); // Export and citation settings pref("extensions.zotero.export.lastTranslator", '14763d24-8ba0-45df-8f52-b8d1108e7ac9');