From: Demian Katz
Sent: Wednesday, April 20, 2011 9:38 AM
To: 'Harmon, Kelly'; email@example.com
Subject: RE: Sort by Date Question
The date sort is very simple – it’s just an alphabetical sort on
the publishDate field. This works great when all of the values in the
field are four-digit years, but in other circumstances it creates problems like
the one you describe.
Fixing it probably isn’t too hard, but it may require a little
bit of programming. I think this is the general idea:
Add a new field to solr/biblio/conf/schema.xml to use for
sorting by date. Something like this:
indexed="true" stored="true" />
Update your web/conf/searches.ini file to replace references to
“year” with “publishDateSort” in the [Sorting] section so that you can sort on
the new sort field rather than on the existing publishDate field, which will
now be used only for display purposes.
Here’s where the programming comes in: create a new copy of the
function you are currently using to populate the publishDate field that returns
a sortable version of the date instead of a human-readable string. For
example, if it would normally return “May 2011” have it return “20110500”
instead. If it would normally return plain old “2011”, you could do
something like “20110000”.
The idea here is that you keep the current behavior for the
publishDate field, since that is used for display… but the new publishDateSort
field will contain a machine-sortable equivalent.
Also, one other important note: the publishDate field is
currently multi-valued, since a single record may contain multiple publication
dates. However, you can’t sort on a multi-valued field, so I removed the
‘multivalued=”true”’ setting when I created the publishDateSort field in the
example above. This means that in your import settings, you may need to
add “first” to the end of the line to ensure that only one value gets put into
the sort field.
In fact, I will probably officially add a “publishDateSort”
field to the VuFind trunk in the near future – in Solr 1.4.1, sorting on a
multi-valued field is technically legal but can have unpredictable
results. Once we upgrade to Solr 3.1, I believe that sorting on a
multi-valued field will become illegal and will result in errors, so we will
actually be forced to adopt a variation of this approach anyway. Once
that happens, steps 1 and 2 will be taken care of for you automatically… but you’ll
still need to have the custom indexing script from step 3, since VuFind will
continue to expect four-digit years by default.
From: Harmon, Kelly
Sent: Wednesday, April 20, 2011 9:09 AM
Subject: [VuFind-General] Sort by Date Question
Can someone point me to a location that describes how the date
sort function works? (Also: is it relatively easy for a non-programmer
type to alter?)
We have combined our two databases into one in the solr index–
and have added the Marc 008 field to capture the dates of Journals/Articles, so
that we can have one big happy db for folks to search.
The problem arises with dates such as “May 2011” and other
non-standards. For example, true
descending order would be:
May 2011 – Apr 2011 – Feb 2011 –
Aug 2010 – May 2010
But dates are sorting Apr 2011, Feb 2010, Mar 2011, etc.
Is there a method to handle this in Vufind? If not,
can you provide suggestions on how to handle? (
Thanks in advance,
Kelly A. Harmon
Webmaster, National Agricultural Library
10300 Baltimore Avenue
Beltsville, MD 20705