Secondary sort by year
bohemicus - January 13, 2009 - 13:30
| Project: | Bibliography Module |
| Version: | 6.x-1.0-rc5 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
I'm building a personal bibliography on my site and like most academics, I have my default display by type. However, within each type, the publications are sorted by title rather than by year. In fact, I cannot really think of a scenario where the title would be the preferable secondary sort rather than author or year.
Would it be possible to have that as an option in the settings? I would even be willing to go to the inadvisable inconvenience of hacking the biblio.pages.inc but couldn't figure out how to do it with my meager PHP/SQL skills.

#1
This is a long standing feature request which (with a bit of luck) I will try to get into the 1.0 release.
Ron.
#2
I second this request, this feature is one of the last missing for our academic needs, too!
#3
Done.
It's hard coded right now, but I'll work on making user configurable.
Ron.
#4
Thanks Ron, I really do believe this is a default that will make sense for most people. Is it in dev now? I can't wait to test it on my site.
Dominik
#5
It hasn't been checked in yet (the site was down most of the day yesterday) look for it later today.
#6
Ok, it's been committed to the -dev version.
Ron.
#7
OK, I checked the -dev version, and it seems there is a side-effect (or an other bug?)
In previous version, selecting sorting by publication type would make the types appear in this order : book, book chapter, journal article, conference paper...
but now, the order is more like : book, conference paper, journal article.
It seems the type are now order by alphabetical order, but the previous sorting was by publication type id and was better (for me and most academics, I believe...)
#8
Indeed, they are sorted alphabetically (which, although might not fit your desires, is probably more understandable)
I could put an option to sort by type ID or Name.
#9
That would be great!
#10
Ok, here is a patch (against head) that does it!
#11
Thanks for this Ron. I installed it on my system and it works just as advertised.
Re option to sort by ID or name, wouldn't it be better to make it possible to assign weights to the reference types? I solved the sorting problem by going into the database and changing the names of the types but I'm afraid that might have a knock on effect later on. And I assume the IDs need to stay constant. But it might be too much work to solve a relatively marginal problem.
#12
That's a good idea, and they actually already have "weight" values, you just can't see them or change them :-(
If I add "table drag" to "admin/settings/biblio/fields/type" then you could just rearrange them to your hearts content.
Ron.
#13
Will this also work as "sort by year, within year by (weighted) type"? Because our main sort is by year on the global publication list, but within the years we would like to chose a sort-by-type order.
What I wonder is if we can also get this for inline calls. When I call
biblio_db_searchwith two order options, only the last one is taken. Using sth. likebiblio_db_search('order', 'year,type')doesn't work. If biblio could evaluate more complex order elements it would be possible to do sth. likebiblio_db_search('order', 'year,field(biblio_type,102,100,205)')reaching what you plan with the drag&drop.Do you think this is possible or would parsing be too complicated? Maybe some syntatic sugar like
('order', 'year', 'and_order', 'field...')?Note: I'm currently using the following patch for my site:
--- biblio.pages.inc.orig 2009-02-12 03:33:28.000000000 +0100
+++ biblio.pages.inc 2009-02-24 09:57:03.000000000 +0100
@@ -361,6 +361,10 @@
$where[] = 'n.status = 1 ';
}//show only published entries to everyone except admin
+ $alter_params = array(&$args);
+ $alter_params['__drupal_alter_by_ref'] = array(&$where, &$published,
+ &$limit, &$sortby, &$sort_attrib);
+ drupal_alter('biblio_build_query', $alter_params);
$joins = implode(' ', $join);
$where_clause = count($where) > 1 ? '('. implode(') AND (', $where) .')': $where[0];
This allows any module implementing
<module>_biblio_build_query_alter(...)to change the query to do thinks like that. Adding the field sort option etc. is simple, so I can provide the field option to my users. This might help people who need sth. like this in case you don't see chances to implement this in biblio itself.#14
Hi Frank,
Some good ideas here, and I think it may be time to completely re-think/write the query building.
Also, FYI, it has come to my attention recently that some of these "sub-sorts" are absolutely killing large (40K+) databases. Especially if there are opposing sort orders (one is DESC and one is ASC) also the title sorts are a killer. The bottom line is that some may want sub-sorting to be optional. (See #306014: biblio causing massive use of resources)
#15
I see... Maybe an additional "sort" tab like the "filter" tab that allows to add sort criterias one after another? While still having the basic sort options on the main page... Because it seems like adding sort options is very much like adding filters. One would just need the possibility to save the chosen sort criterias as default one.
#16
I noticed that the secondary sort disappeared in 6.x-1.5. Is it still in dev? Or am I missing something?
#17
Actually, I don't think it ever made it into the code, (at least not that I remember).
You might want to start looking into the use of Views. Biblio now has reasonably complete Views support and this allows some fairly complex sorting and filtering to be done.
Ron.
#18
It was in the DEV version I was using until I upgraded to 1.5. But I'll look into Views. That was the flexibility, I was looking for anyway. Thanks.
#19
Yep, I agree on this too. I currently have the default display by year, but it would be nice to to have the option to then sort them under each year by the first named author alphabetically.
For displaying on user profile pages, I agree too that most default displays are likely to be by type and strongly support the idea of being able to then have an option to set the sort order to be by title rather than by year.
#20
I was able to recreate this functionality with views and then some. The only bit that is missing is the export function. I submitted it as a new feature request here: #484872: export links in views
I think all the development efforts should now go towards tighter Views/CCK integration - which is where Ron seems to be headed.