Applescript event RFLD returns results in different order?

A place for users to ask each other questions, make suggestions, and discuss Bookends.
Post Reply
iandol
Posts: 481
Joined: Fri Jan 25, 2008 2:31 pm

Applescript event RFLD returns results in different order?

Post by iandol »

Hi,

I am trying to use the applescript event RFLD to return multiple results (to optimise the performance of my Bookends Tools scripts), but I'm finding the order is returned differently to the order in the request. This demonstration uses 4 UIDs to return the same UIDs, but the order returned isn't the same:

Code: Select all

tell application "Bookends"
	set uid to «event ToySRFLD» "47648,5100,36271,27008" given string:"uniqueID"
end tell
It returns (I've replaced ASCII \x00 with a space to read more easily):

Code: Select all

uid = "47648 5100 27008 36271"
It would be much better if RFLD could return results in the same order.

[p.s. of course I do not need to use RFLD to return uniqueID (as I already have them) this is just for demonstration of the problem, I do need to return title, thedate, authors etc. with the same order as the request]
Jon
Site Admin
Posts: 10291
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Applescript event RFLD returns results in different order?

Post by Jon »

That's not the way SQL works. You should not assume the order of the references returned. If you need a specific order then query one at a time. Or query in a group and rearrange (or sort) the references yourself when they're returned.

Jon
Sonny Software
iandol
Posts: 481
Joined: Fri Jan 25, 2008 2:31 pm

Re: Applescript event RFLD returns results in different order?

Post by iandol »

I'm trying to run the Apple events from Ruby[1], where each apple event request is expensive performance wise when I may have 30 or 40 references and I need to return back to Alfred without a large delay, so I'm trying to save time by running as few Apple events as possible. I run an initial SQL search to get the uniqueIDs then I want to get the author/year/title. If I do it for each reference, it takes around 10 seconds for 15 refs which is far too long, so I wanted to do a group find, but then I lose the link between the uniqueID and the results, unless I spend time on another request to return the uniqueID from the uniqueID as in my demonstration.

Can I guarantee that the order is the same for each invocation of RFLD, i.e. if I get authors in one request and thedate in a second, is the order at least the same for authors and thedate even if it is different than the uniqueID I submit? Is there any relationship between uniqueID submitted and references returned can exploit to not need to do another request?

Thanks for any advice!

----
[1] Ruby is much better for script programming and dealing with JSON, which is what Alfred requires...
Jon
Site Admin
Posts: 10291
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Applescript event RFLD returns results in different order?

Post by Jon »

You'll have to experiment yourself and see. No order is guaranteed for the results of SQL searches, but I'm sure there are some underlying principles that will generate the order. Of course you can enforce the order by adding " order by x" in an SQL search, where x is a field or property (e.g. it could be the uniqueid). If you're not familiar with them, you might want to read up a bit on SQL searches, nothing complicated.

Jon
Sonny Software
iandol
Posts: 481
Joined: Fri Jan 25, 2008 2:31 pm

Re: Applescript event RFLD returns results in different order?

Post by iandol »

Great idea, thanks Jon! I'm not sure how I pass SQL options to the RFLD event, you are suggesting I rewrite them as SQLS events?
iandol
Posts: 481
Joined: Fri Jan 25, 2008 2:31 pm

Re: Applescript event RFLD returns results in different order?

Post by iandol »

By batching up my requests into one request my Ruby code is now reliably 0.3 seconds for any number of records, which is fast enough (so I now just request uniqueID with RFLD and replace my original uniqueIDs with the searched version). For anyone that uses Bookends Tools could you please download the new beta and test if it is working for you? I've added multiple authors and optional year for the becite search tool...

https://raw.githubusercontent.com/iando ... edworkflow
Post Reply