commit 60f7c8fccd93931d0ed461f0489044876d274f46
parent 9675ac9d0159078425523889f759e006e5773bfc
Author: Dan Stillman <dstillman@zotero.org>
Date: Tue, 6 Jun 2006 08:02:29 +0000
Scholar.Items.search(text) -- (extremely) simple fulltext search on all fields -- returns an array of ids of matching items
The real search function will be considerably more advanced/flexible, but this should work as a placeholder for the moment. Probably quick enough for FAYT, at least with a ~0.5 second delay to avoid unnecessary calls while people are typing (which is probably a good idea anyway). This search doesn't use indexes at all, so if more speed is needed, one option would be to maintain a manual FULLTEXT-type index (using triggers, ideally) that could be quickly searched, but we'd lose intra-word filtering, which people would probably expect...
Diffstat:
1 file changed, 23 insertions(+), 0 deletions(-)
diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js
@@ -783,6 +783,7 @@ Scholar.Items = new function(){
this.reload = reload;
this.reloadAll = reloadAll;
this.getNewItemByType = getNewItemByType;
+ this.search = search;
this.erase = erase;
this.unload = unload;
@@ -891,6 +892,28 @@ Scholar.Items = new function(){
/**
+ * Fulltext search on all fields
+ *
+ * TODO: more
+ **/
+ function search(text){
+ if (!text){
+ text = '';
+ }
+
+ var sql = "SELECT itemID FROM items WHERE title LIKE ?1 UNION "
+ + "SELECT itemID FROM itemData WHERE value LIKE ?1 UNION "
+ + "SELECT itemID FROM itemCreators WHERE creatorID IN "
+ + "(SELECT creatorID FROM creators WHERE firstName LIKE ?1 "
+ + "OR lastName LIKE ?1) UNION "
+ + "SELECT itemID FROM itemKeywords WHERE keywordID IN "
+ + "(SELECT keywordID FROM keywords WHERE keyword LIKE ?)";
+
+ return Scholar.DB.columnQuery(sql, [{'string':'%' + text + '%'}]);
+ }
+
+
+ /**
* Delete item from database and clear from internal array
**/
function erase(id){