collectiveaccess / pawtucket2

Pawtucket Improved
GNU General Public License v3.0
85 stars 76 forks source link

apply sort, without accidental filtering #63

Closed peterjanssens closed 1 year ago

peterjanssens commented 1 year ago

we had an edge case while performing an advanced objects search with a custom sort on related entity labels ie:

sortBy = { Entity = ca_entity_labels.surname;ca_entity_labels.forename, ...

This sorting resulted in zero results in some cases (where none of the objects had entities).

Sorts are handled by INNER joining all the related tables, effectively causing the resultset to be filtered before it can be sorted when there were no related tables. Entities are not required, making it hard to get this default filtering always matching reality. It seems appropriate to do LEFT joins instead, and (force) inner joins only on the 'selecting' joins (hit_table), so that the final resultset is complete for the objects, with empty information for the related tables (in our case entities, entity_labels). Sorting on the emtpy data will make no sense but at least the found/valid objects can be retrieved.

(our case was _getRelatedRowIDsForLabel, that I can confirm works now. I updated the other scenarios too, should work but couldn't test them)

collectiveaccess commented 1 year ago

Yes, I see the point and agree with your change.