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...
This commit is contained in:
Dan Stillman 2006-06-06 08:02:29 +00:00
parent 9675ac9d01
commit 60f7c8fccd

View file

@ -783,6 +783,7 @@ Scholar.Items = new function(){
this.reload = reload; this.reload = reload;
this.reloadAll = reloadAll; this.reloadAll = reloadAll;
this.getNewItemByType = getNewItemByType; this.getNewItemByType = getNewItemByType;
this.search = search;
this.erase = erase; this.erase = erase;
this.unload = unload; 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 * Delete item from database and clear from internal array
**/ **/