After thought, I was bothered a bit by purposely limiting the value to bool, especially as it gains no performance. Looking up a key in a dict has the same performance as looking up a key in a set. Both are hashed in the same way.
What I am ready to commit:
Setting API:
db.set_marked_ids(ids) -- ids can be a list or dict. If a list, then a dict is constructed where {id:'true'} for all ids in the list. If it is a dict, then it is copied and checked to be sure that all the values are unicode.
If ids == [] or {}, the right thing happens.
The virtual column is set to the val if id is in the dict, otherwise None.
Search API:
marked:true -- finds anything set. If a list was passed to set_marked_ids, then it finds all the ids in that list.
marked:false -- finds anything not set.
marked:foobar -- if a dict was used, then this will find any book with value foobar. All the string matching search syntax can be used (equals, contains, regexp).
Usage:
1) call db.set_marked_ids(...).
2) call gui.search_box.set_search_string('marked:...') where the ... is what you want.
The user can, of course, make a saved search and then use that search as a restriction. There is no API to do these things.
|