Currently when the bibliography is sorted by publication year the secondary sort is by publication title. Either provide an option to select a secondary sort by primary author or title. Author secondary sort is most preferred by academics.

Thanks!

Comments

ulysse68’s picture

I had the same problem, and I solved it patching the biblio.pages.inc page -- sorry I don't use Git, so my patch isn't in the proper form. These lines affect lines 355 sq.

  switch ($arg_list['s']) {
    case 'type':
      //$sortby = "ORDER BY bt.name %s, b.biblio_year DESC ";
      $query->addField('n', 'title');
      $query->orderBy($type_name, $arg_list['o']);
-      $query->orderBy('biblio_sort_title', $arg_list['o']);
+      $query->innerJoin('biblio_contributor', 'bc', 'b.vid = bc.vid');
+      $query->join('biblio_contributor_data', 'bcd', 'bc.cid = bcd.cid');
+      $query->condition('bc.rank', 0);
+      $query->addField('bcd', 'lastname');
+      $query->orderBy('bcd.lastname', 'asc');
            break;
    case 'title':
      $query->addField('n', 'title');
      $query->orderBy('biblio_sort_title', $arg_list['o']);

      break;
    case 'author':
      //$last_name = $query->addField('bcd', 'lastname');
      $query->innerJoin('biblio_contributor', 'bc', 'b.vid = bc.vid');
      $query->join('biblio_contributor_data', 'bcd', 'bc.cid = bcd.cid');
      $query->condition('bc.rank', 0);
      $query->addField('bcd', 'lastname');
      $query->orderBy('bcd.lastname', $arg_list['o']);
      // $query->condition('bc.auth_category', 1);
      break;
    case 'keyword': // added msh 070808
      $word = $query->addField('bkd', 'word', 'biblio_keyword');
      $query->orderBy($word, $arg_list['o']);
      $query->innerJoin('biblio_keyword', 'bk', 'b.vid = bk.vid');
      $query->innerJoin('biblio_keyword_data', 'bkd', 'bk.kid = bkd.kid');
+      $query->innerJoin('biblio_contributor', 'bc', 'b.vid = bc.vid');
+      $query->join('biblio_contributor_data', 'bcd', 'bc.cid = bcd.cid');
+      $query->condition('bc.rank', 0);
+      $query->addField('bcd', 'lastname');
+      $query->orderBy('bcd.lastname', 'asc');
      break;
    case 'year':
    default:
      $query->addField('b', 'biblio_year');
      $query->addField('b', 'biblio_date');
      $query->orderBy('biblio_year', $arg_list['o']);
-      $query->orderBy('biblio_sort_title');
+      $query->innerJoin('biblio_contributor', 'bc', 'b.vid = bc.vid');
+      $query->join('biblio_contributor_data', 'bcd', 'bc.cid = bcd.cid');
+      $query->condition('bc.rank', 0);
+      $query->addField('bcd', 'lastname');
+      $query->orderBy('bcd.lastname', 'asc');
  } //end switch

Hope that helps,
U.

ulysse68’s picture

Well, forget the patch above: it produces undesired side effects -- when you filter by authors, results are not correctly displayed. I am trying another method: if it works, I'll let you know here -- but if the developers have a good solution...

U.

sunhuaifeng’s picture

I need the function too.
And i suggest to add a field in the module to support the function instead of modifying the code for general use.

Users can define the first field to sort and the secondary, also the third etc.
Different users have different needs.

thanks for your work and I'm waiting for your good news.

dystopic’s picture

Version: 7.x-1.x-dev » 6.x-1.15

I would like to suggest, that the secondary sort field should be configurable, because the specific needs for the secondary order varies depending on the environment in which the bibliography module is used. The possibility to use a custom field for the secondary order would be sufficient i would assume.

For me personally, i would like to have a secondary order depending on the publication type (papers before conference posters etc.) while the primary order is chronologically.
If the the primary order is set to publication type, i would prefer a secondary order based on the publication year.

Alphabetical order is not very helpful for me personally.

Thank you for your work!

ulysse68’s picture

+1 for a secondary sort order; but as Cliff Donath says, the default order within a year should be by author (I've never seen an order by title in references...).

Thanks!

ziemendorf’s picture

+1 for this. I've been trying to figure out a way to make this work, without success.

anfederman’s picture

Related issue?

When pasting a bibtext record and editing secondary author becomes series author.

I.e. it is edited as secondary author but displays as series author.

Title Play and early childhood development.
Publication Type Book
Year of Publication 1999
Authors Johnson, JE
Series Editor Christie, JF
Tertiary Authors Yawkey, TD
Publisher Longman

original +
@Book{
author = "Johnson, J.E.; Christie, J.F. and Yawkey, T.D.",
title = "Play and early childhood development.",
publisher = "Longman",
year = 1999
}

lenov’s picture

+1 for a secondary sort, by first author family name if not configurable.

I also reproduced anfederman's bug.

rkneale’s picture

It's been a while, but add another vote for secondary sort by author last name.... I've just started playing with Biblio and it could be everything we need, except for that problem.

rkneale’s picture

Never mind, I figured it out! Hope everyone else was able to, and I do really hope this shows up as the default in the next release, but until then a tweak of the biblio.pages.inc file made all the difference.

ulysse68’s picture

Could you be more specific, please? I haven't figured it out, yet...

toomanychrises’s picture

You figured it out and didn't post the solution... Please never visit this forum again because you are useless. The point of this is to share information.

toomanychrises’s picture

Issue summary: View changes

For those of you coming to this and perhaps not as adept in code- here is a solution that you can try. I needed to change the secondary sort for "Type" from the Title to the Year. You will notice above the approximate location of the code you need to change and it is a bit intuitive with trail and error, but in the interest of saving time I changed:

line 374
$query->orderBy('biblio_sort_title', $order);
change to:

      // $query->orderBy('biblio_sort_title', $order);
      $query->orderBy('biblio_year', $order);

for primary author as the second sort, this worked for me:

      $query->innerJoin('biblio_contributor', 'bc', 'b.vid = bc.vid');
      $query->join('biblio_contributor_data', 'bcd', 'bc.cid = bcd.cid');
      $query->condition('bc.rank', 0);
      $query->addField('bcd', 'lastname');
      $query->orderBy('bcd.lastname');

It would be great if someone with a better understanding of php and this module could post how to sort $query->orderBy('biblio_year', $order); in descending order from most recent year first.

toomanychrises’s picture

follow-up for the Year secondary sort:

      $ordertype = 'DESC';
      $query->orderBy('biblio_year', $ordertype);

I made a new variable called $ordertype since this if for the Type sort and set it to DESC for descending so it would affect only that sort.

ulysse68’s picture

Version: 6.x-1.15 » 7.x-1.0-rc7
ulysse68’s picture

As stated in this issue, the problem of sorting by year and author could be solved if we could use the "biblio citation" field as a sort criteria.

I could manage, using biblio_views, to sort by year and first author -- but it is not enough if you have many authors.

Does anyone have an idea on where to customize this "biblio citation" field? Is it only created on the fly?

St_B’s picture

yes biblio citation is created each time you run the view, and not stored. It can be a problem if you have many results on the page, the view can become very long. We chose to create some cck fields instead, filled with the result of functions used to generate biblio citation. We store the Harvard citation in one field, Vancouver one in another.

museumboy’s picture

Is there anyway to do this if you don't have access to the biblio module files? A template.php hook? We really need this as a feature.

keramsey’s picture

Here is a patch against biblio version 7.x-1.0-rc7 that sets secondary sorting within year by primary author which needs testing, but seems to work. Based on comment #13 by toomanychrises.

keramsey’s picture

Ran into issues with array variables not being declared (PHP 7.1) and broken author links except when filter was set to title. This was related to the secondary sorting changes (e.g., sort by author, publication title). See comment # 2 at https://www.drupal.org/node/1938512#comment-7168562 for more information.

Patch created against 7.x-1.0-rc7.

My environment:
PHP 7.1
CentOS 7
MariaDB 10.1.25
Aegir 7.x-3.10
Drush 8.1.10

Needs review.

keramsey’s picture

Version: 7.x-1.0-rc7 » 7.x-1.0-rc11
StatusFileSize
new49.1 KB

I found that my earlier patch created an issue that kept non-first authored publications from appearing in a user's publications listing within their profile page.

I created a duplicate of includes/biblio.pages.inc as includes/biblio.profile.pages.inc to allow for separating the sorting logic to for profile publications pages from the rest of biblio pages. I am not sure that the naming convention for the biblio.profile.pages.inc file meets Drupal best practices.

I think there is a more efficient way to modify the sort select case without duplicating the entire include file (biblio.pages.inc). I would appreciate anyone's comments on the include file naming and my approach to separating (filtering) the user profile publications listings from other biblio pages.

I have created a new patch based on biblio-7.x-1.x-dev. Patch needs review.

keramsey’s picture

Status: Active » Needs review

Patch #21 needs review

keramsey’s picture

Version: 7.x-1.0-rc11 » 7.x-1.x-dev

Patch #21 was actually built against 7.x-1.x-dev, not 7.x-1.0-rc11.

liam morland’s picture

Status: Needs review » Needs work

There is no need to duplicate the entire file and having duplicate function names won't work anyway. There can be conditional logic around setting the sort order.

museumboy’s picture

The question I have is how to code the sort so it's by:

Date
Primary Author last name
Secondary Author last name
Tertiary....
Title

If the same author publishes in one year then the next listing should be sorted by the secondary author last name, and so on, then by title

liam morland’s picture

SQL allows as many ORDER BY clauses as you want.

keramsey’s picture

Here is an updated patch against 7.x-1.x-dev. I cleaned up the code to use conditional logic as suggested by Liam.

Needs testing.

keramsey’s picture

Status: Needs work » Needs review
liam morland’s picture

Status: Needs review » Needs work

Thanks for the patch.

I'm not familiar with having more than just a value on the case line. It may work, but I don't see it documented on php.net, so that makes me hesitate to use it. Please write-write using an if statement and remove as much of the code duplication as possible.

Please check your coding standards. Comments are supposed to go on the line before, not at the end of the line.