![]() |
#1 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,722
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Search restrictions and search_getting_ids
I had to jump through quite a few hoops with the Find Duplicates plugin and facing some similar (but not identical) issues with Quality Check.
The issue is search restrictions and a clean way of passing a valid restriction to search_getting_ids(). Originally in QualityCheck I applied an actual search to the library view (like "formats:epub") before grabbing all the ids in the view. Thus I was able to avoid thinking about restrictions, as they were applied transparently in the background to the view, and whether the restriction was or was not in place was irrelevant to my plugin. However this approach does not work if the user has highlighting turned on, as the set of ids I was getting back from the model of course cover all rows with just the epub ones highlighted. So instead I changed to use "db.search_getting_ids()" which is a nicer approach anyway (since I don't have to change the view). The second parameter is the search restriction to be applied. This is where things come unstuck, which is likely entirely due to my ignorance. I need to get a search restriction value to pass to the search_getting_ids() call every time I want to use it, in order to respect any search restriction that might be applied. Where do I get a value from that represents a search restriction that search_getting_ids will understand? I cannot use gui.search.search_restriction as that only works for "current" type search restrictions, not for saved searches. Hopefully there is a simple value somewhere I can use... ? |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,342
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
The search restriction must be a valid search as would go in the search box. It is up to you to generate such a thing.
If what you have is a search restriction name (a saved search name), then the restriction search is generated using something like Code:
'search:"%s"'%(saved_search_name) |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,722
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Perhaps I didn't explain very well. All I want to do is get a value to pass to search_getting_ids for it's second parameter of "restriction", which represents whatever the current restriction is that the user has applied in Calibre. As I said above I cannot use self.gui.search.search_restiction, because I will get a value of a saved search name in some cases, and actual text representing the restriction in others, depending on whether the user last applied a current search or a named restriction.
To get around this I can go down the FindDuplicates route of looking at the text in the combo, seeing if it starts with a * or not and then manipulating that into a value search_getting_ids can cope with. However that is something I would need to repeatedly do everywhere I call search_getting_ids(). I wondered if there was somewhere else that would give me the "underlying" value without requiring me to manipulate it. |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,342
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
You can get the current search restriction (the one in effect because the user did something) via db.data.search_restriction.
|
![]() |
![]() |
![]() |
#5 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,722
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Perfect, thanks. Hoped it was around somewhere...
![]() |
![]() |
![]() |
Advert | |
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Geo Restrictions | emmad | Amazon Kindle | 30 | 09-20-2010 07:22 AM |
More App Restrictions | kennyc | Apple Devices | 12 | 06-02-2010 02:29 PM |
No Geo-restrictions | seagull | Deals and Resources (No Self-Promotion or Affiliate Links) | 3 | 12-14-2009 01:07 AM |
Regional restrictions now in the UK | tech_au | News | 166 | 10-26-2009 02:52 PM |
Google Book Search to search full-text books online | Bob Russell | Deals and Resources (No Self-Promotion or Affiliate Links) | 1 | 08-19-2006 12:13 PM |