Query facets in blacklight master

265 views
Skip to first unread message

Chris Beer

unread,
Sep 21, 2012, 1:18:02 PM9/21/12
to blacklight-...@googlegroups.com
Hi all,

Earlier this week, I added some support for query facets into blacklight master. I'm not completely satisfied with the underlying implementation, but it has the benefit of being backwards compatible and seems to mostly work. I added an example to the test app (and, the blacklight demo):

http://demo.projectblacklight.org/


And here's the config behind it:

config.add_facet_field 'example_query_facet_field', :label => 'Publish Date', :query => {
:years_5 => { :label => 'within 5 Years', :fq => "pub_date:[#{Time.now.year - 5 } TO *]" },
:years_10 => { :label => 'within 10 Years', :fq => "pub_date:[#{Time.now.year - 10 } TO *]" },
:years_25 => { :label => 'within 25 Years', :fq => "pub_date:[#{Time.now.year - 25 } TO *]" }
}

I'll try to add documentation to the wiki next week.

Thanks,
Chris

Naomi Dushay

unread,
Sep 24, 2012, 2:28:02 PM9/24/12
to blacklight-...@googlegroups.com
Chris,

This looks great!

One possible gotcha: if you are using a field with a ton of values (for example, call numbers for a huge collection), then range queries with * could be extremely slow. That's true for range queries in general, but I think this may be the first place we use them in our code?

Dunno if we should somehow document that … not sure where or how to do so.

- Naomi
> --
> 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.
>

Jonathan Rochkind

unread,
Sep 24, 2012, 2:41:20 PM9/24/12
to blacklight-...@googlegroups.com, Naomi Dushay
Range queries should NOT be slow if you're using a trie-based field,
even if there are a ton of values, right?

Maybe we should hint that people want to look into the solr trie-based
field types for anything they're going to range query on?

And/or suggest they profile the queries themselves directly against
their actual Solr index to see how they do. As much as some people want
it to, using BL will never get you out of having to understand what's
going on at the Solr level and what it means for your index.

On 9/24/2012 2:28 PM, Naomi Dushay wrote:
> Chris,
>
> This looks great!
>
> One possible gotcha: if you are using a field with a ton of values (for example, call numbers for a huge collection), then range queries with * could be extremely slow. That's true for range queries in general, but I think this may be the first place we use them in our code?
>
> Dunno if we should somehow document that � not sure where or how to do so.

Janna Wemekamp

unread,
Nov 11, 2012, 6:30:37 PM11/11/12
to blacklight-...@googlegroups.com, Chris Beer
Hi,

I'm attempting to implement a query facet - so far unsuccessfully.
Are there Solr config changes needed to make this work?
(Would be useful to see the Solr schema/solrconfig files used on 
http://demo.projectblacklight.org/)

TIA muchly!


Janna
--
Janna Wemekamp
NRM knowledge online

Chris Beer

unread,
Nov 12, 2012, 12:06:00 PM11/12/12
to Janna Wemekamp, blacklight-...@googlegroups.com
demo.projectblacklight.org is just running the test app with additional data, using this CatalogController:


Did you read the Blacklight 3.7 release notes?


Or the section in the Blacklight configuration page about facet queries?


(the release notes seem to be a better source of documentation; I'll try to merge the release note docs into the configuration page soon.)

Janna Wemekamp

unread,
Nov 12, 2012, 4:14:31 PM11/12/12
to Chris Beer, blacklight-...@googlegroups.com
Me bad...

Yes, I'd read the notes and BL's CatalogController but somehow missed the bit about the change to get Blacklight to generate facet.query. Started messing about with the Solr schema to get rid of the RSolr error, etc., etc...
Once I fixed my CatalogController, all is well.

Thanks (and sorry).
And thanks for adding this functionality to Blacklight!


Janna


Jonatan Fournier

unread,
May 22, 2013, 2:26:33 PM5/22/13
to blacklight-...@googlegroups.com
Hi,

It has been a while since that feature came out but I just started using it...

I was wondering how sorting was working for that one?

I have something like this:

(collection_date is a tdate in the schema)

  month_1 = 1.month.ago
  month_4 = 4.month.ago
  month_8 = 8.month.ago
  month_12 = 12.month.ago

  config.add_facet_field 'collection_date_facet', :label => 'Collection Date', :query => {
    :months_1 => { :label => 'within 1 months', :fq => "collection_date:[#{month_1.year}-#{month_1.month}-#{month_1.day}T00:00:00.000Z TO *]" },
    :months_4 => { :label => 'within 4 months', :fq => "collection_date:[#{month_4.year}-#{month_4.month}-#{month_4.day}T00:00:00.000Z TO *]" },
    :months_8 => { :label => 'within 8 months', :fq => "collection_date:[#{month_8.year}-#{month_8.month}-#{month_8.day}T00:00:00.000Z TO *]" },
    :months_12 => { :label => 'within 12 months', :fq => "collection_date:[#{month_12.year}-#{month_12.month}-#{month_12.day}T00:00:00.000Z TO *]" }
  }

And my facet displays like this:

Collection Date
within 8 months (3630109)
within 4 months (3630109)
within 1 months (1385737)
within 12 months (3630109)

It seems to ignore the :sort => 'count/index' param. 

Is it enforced to count then index and can't be customized?

I see that the BL example is:

Publish Date
within 5 Years 3761
within 10 Years 6763
within 25 Years 8173

Which seems to be the definition order in the catalog_controller (this is not what I have in my case..)

I'm using BL 3.8.2

Cheers,

/jonathan


Reply all
Reply to author
Forward
0 new messages