Sorting entries based on an a bespoke algorithm We have been asked to scope a solution for a new site build that we'd like to use Craft for. There is one requirement I'm not sure how we'd approach though.

In Craft terms, we would have an Articles channel that has a number of fields:


Employer (relationship to a single Employer channel entry)
Sector (relationship to a single category)
Stage (select field)
Tag (tag field)


Then each logged in User would also have the same fields on their profile. I guess it would be easy enough to query the user attributes and pass those to a craft()->entries() call, but the requirements call for a very specific sorting algorithm.

That would work something like this:


Article Employer matches User Employer = score of 10
Article Sector matches User Sector = score of 3
Article Stage matches User Stage = score of 4
Article Tags intersect with User Tags = score of 1 x number of matches


The result of that score would then be added up and used as a sort dimension against a list all the latest Article entries.

Can anybody suggest a practical (processor efficient) way to achieve this? 

My current thinking this:


Get all Article entries.
Loop through each Article them and add the calculated score to an array containing the entry ID and the score.
Order the array by score.
Requery all Articles with pagination enabled, passing in a the list of entry IDs in the order defined by the sorted array.


Would that work? In particular the last step - can we define entries be sorted by an array of ID numbers?

Any other suggestions would be gladly received.
Looks like a solid plan to do this. And to get the entry models it the same order as you're passing the IDs to your ElementCriteriaModel there's this property: fixedOrder(true).

Other suggestions could only be to do this with plugin code, but I don't think this would speed up thing noticeably.