Custom Sorting in Facets

372 views
Skip to first unread message

Praveen Bysani

unread,
May 23, 2011, 10:09:30 PM5/23/11
to blacklight-...@googlegroups.com
Hi,

Is it possible to customize the sorting of facet fields, apart from the default "count" and "index" ways provided by facet.sort method ?
--
Regards,
Praveen Bysani
Research Assistant, WING
National University of Singapore

Erik Hatcher

unread,
May 23, 2011, 11:45:37 PM5/23/11
to blacklight-...@googlegroups.com

On May 23, 2011, at 19:09 , Praveen Bysani wrote:
> Is it possible to customize the sorting of facet fields, apart from the default "count" and "index" ways provided by facet.sort method ?

Not from the Solr side of things.... those are the only two ways available for facet sorting directly from Solr. Blacklight, of course, _could_ request all facet values and sort them client-side other ways (but I don't think it does anything like that currently).

Erik


Praveen Bysani

unread,
May 24, 2011, 12:48:33 AM5/24/11
to blacklight-...@googlegroups.com
Hi Erik,

Could you give some pointers to help me modify the blacklight code to do so ?



--
You received this message because you are subscribed to the Google Groups "Blacklight Development" group.
To post to this group, send email to blacklight-...@googlegroups.com.
To unsubscribe from this group, send email to blacklight-develo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/blacklight-development?hl=en.

Erik Hatcher

unread,
May 24, 2011, 12:53:37 AM5/24/11
to blacklight-...@googlegroups.com
Praveen -

I'm not deep into the Blacklight Way of doing things at the moment, so I'm not sure exactly what it'd take. I imagine some of committers could provide some tips.

Erik

Molly Pickral

unread,
May 24, 2011, 10:10:38 AM5/24/11
to blacklight-...@googlegroups.com
Praveen,

It may not be very elegant, but I've done some custom sorting in a
helper that gets called by a view. For example, in
app/helpers/application_helper.rb:

def facet_sort!(items=[])
items.sort! { |a,b| a.value.downcase <=> b.value.downcase }
items
end

and in app/views/catalog/facet.html.erb:

<% items = facet_sort!(params[:id], @pagination.items) %>
<% items.each do |item| %>
whatever, whatever
<% end>

We did this because I couldn't figure out how to get solr to sort in a
case-insensitive way, and we wanted eBooks to sort with the other
items that start with "E."

Molly

Praveen Bysani

unread,
May 24, 2011, 11:55:38 PM5/24/11
to blacklight-...@googlegroups.com
Hi Molly,

Thanks for the suggestion. I will try that.

Jonathan Rochkind

unread,
May 25, 2011, 11:29:14 AM5/25/11
to blacklight-...@googlegroups.com

I have done this in my local app, for a facet that only had about 25
values, I fetch em all and sort em differently myself client side before
displaying them. This isn't built into Blacklight, I custom implemented
it in my local app. That exact approach is obviously only feasible if
the number of values is small enough that you're fine displaying them
all. (Otherwise, even if you fetch em all -- what do you do with the
ones you don't display? Do you have to implement some kind of custom
paging too? I guess, if you want to show them).

Another approach, if you have too many facet values to want to fetch em
all at once, but are fine only displaying a handful of them (and not
bothering with paging over the rest), you could use Solr facet.query
feature to only ask for the values you want, and then again put them in
the order you want on display. If you did want to page the rest, still
not sure exactly how you'd do that.

Any of these approaches will require some familiar wtih Solr, with
Rails, and with Blacklight code, they aren't "beginner" level
customizations.

Jonathan

Jennifer Vine

unread,
May 25, 2011, 2:04:46 PM5/25/11
to blacklight-...@googlegroups.com, blacklight-...@googlegroups.com
I'm curious about the use case for sorting facets by something other
than alpha or frequency. Anyone want to share?

JV

Sent from my iPhone

Jonathan Rochkind

unread,
May 25, 2011, 2:14:29 PM5/25/11
to blacklight-...@googlegroups.com, Jennifer Vine
My use case here was for a library shelf location facet, and on the
front page specifically.

We have about a dozen location value values, which includes our five
main libraries and some sub-locations of those main libraries, all just
together in a flat list. But on the first page, before a search has
been done when you're just looking at the facet values over the entire
corpus, we wanted the five main libraries to show up as the values, even
though some of the sub-locations of the large libraries have more
holdings than the main value for one of the smaller main libraries.

Praveen Bysani

unread,
Jun 2, 2011, 7:15:20 AM6/2/11
to blacklight-...@googlegroups.com, Jennifer Vine
Hi,

Is the view 'app/views/catalog/facet.html.erb' used by the blacklight at all? I see that, everything works fine even after removing this view, since it has index view under catalog. Please explain.

Chris Beer

unread,
Jun 2, 2011, 9:36:47 AM6/2/11
to blacklight-...@googlegroups.com, Jennifer Vine
I believe app/views/catalog/facet.html.erb (and CatalogController#facet) are
used by the facet limit feature (which shows X facet items for a field, adds
a "more >" link) that provides a paginated view of a facet.

I don't think there's a good way to deep-link to it, but if you go to
http://demo.projectblacklight.org/

- expand topic
- click "more >>"

You should see the facet browser in a lightbox.


You can also access it directly at
http://demo.projectblacklight.org/catalog/facet/subject_topic_facet/

>>>> <mailto:blacklight-development%2Bunsu...@googlegroups.com> .


>>>> For more options, visit this group at
>>>> http://groups.google.com/group/blacklight-development?hl=en.
>>>>
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Blacklight Development" group.
>> To post to this group, send email to blacklight-...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> blacklight-develo...@googlegroups.com

>> <mailto:blacklight-development%2Bunsu...@googlegroups.com> .

Jonathan Rochkind

unread,
Jun 2, 2011, 11:43:35 AM6/2/11
to blacklight-...@googlegroups.com, Chris Beer, Jennifer Vine
There's definitely a way to deep link to it -- in fact, with pretty much
all of our fancy JS stuff (at least the stuff I've written!), if you
right-click and copy the URL on an 'ajaxy' link, you'll get a deep link.
(That'll probably also work if you right-click and open in new tab/window).

This is an architectural principle I think we should adhere to, and it's
what our stuff currently mostly does.

Here's an example of the facet "more" stuff, that I think Chris is right
uses that view, on my server:

https://catalyst.library.jhu.edu/catalog/facet/language_facet

Reply all
Reply to author
Forward
0 new messages