From 60f7c8fccd93931d0ed461f0489044876d274f46 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 6 Jun 2006 08:02:29 +0000 Subject: [PATCH] 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... --- .../content/scholar/xpcom/data_access.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/chrome/chromeFiles/content/scholar/xpcom/data_access.js b/chrome/chromeFiles/content/scholar/xpcom/data_access.js index 5dc6db0e6b..5d2f61ff98 100644 --- 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; @@ -890,6 +891,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 **/