Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add field configuration for :include_in_request. If true, the field will... #783

Merged
merged 1 commit into from
Feb 17, 2014

Conversation

cbeer
Copy link
Member

@cbeer cbeer commented Feb 17, 2014

... be explicitly added to the request made to solr. Otherwise, Blacklight assumes the appropriate configuration is made in the solr config. Attempts were made to keep this change backwards compatible with existing practice.

The configuration looks like:

config.add_facet_field 'yes_facet', include_in_request: true # will be added as a `facet.field`
config.add_facet_field 'no_facet', include_in_request: false # will not be added as a `facet.field`
config.add_facet_field 'some_facet'

config. add_facet_fields_to_solr_request! # add all facet fields to solr
config. add_facet_fields_to_solr_request! 'some_facet' # add the 'some_facet' field to the solr request

Same goes for add_index_field/add_show_field and add_field_configuration_to_solr_request.

@eranhirs
Copy link
Contributor

I want to discuss here what you wrote me in #781 as an usage example:

before_filter only: :index do
  blacklight_config.add_facet_fields_to_solr_request!
end

before_filter only: :facet do
  blacklight_config.add_facet_fields_to_solr_request! params[:id]
end

The problem in this example is that it's not part of the configuration anymore, it's more like a runtime decision. Sounds a bit weird to change the configuration in runtime.

What do you say?

@eranhirs
Copy link
Contributor

@cbeer if you're OK with using the before_filter example you wrote me, I'll be happy to rewrite #781 without using user_params. I can do it quite easily.
@jrochkind what do you think?

@jrochkind
Copy link
Member

I'm still having trouble keeping up.

If you need special local behavior for something not ordinarily included in Blacklight, and you can do it with a before_filter, that seems great.

If you guys are suggesting including default Blacklight CatalogController setup such that it uses a before_filter, that seems undesirable to me.

Including a method off of blacklight_config meant to be called from a before_filter seems confusing to me. If I understand right, it's introducing something that works in parallel with the "solr search logic" stuff, but is different from it, so there are now two mechanisms that both work on the solr parameters, the solr_search_logic stuff, and a before_filter that calls something off blacklight_config. That seems awfully confusing.

Again, while I see the undesirability of the current architecture you are talking about -- there are unfortunately many undesirable parts of the BL architecture, it's important the cure not be worse than the disease as far as maintainability, and complexity of code and cognitive load in understanding it is a big part of maintainability. This part of BL may be too hard to understand now, it's important not to make it worse.

@cbeer
Copy link
Member Author

cbeer commented Feb 17, 2014

I'm not suggesting the default include this behavior, just that it's an option if @eranhirs actually wants/needs that behavior.

We've supported run-time configuration of blacklight for some time now. This patch doesn't introduce any new methods, and just refines an existing one.

(For the purposes of this patch, the before_filter proposal is irrelevant anyway. Allowing the developer more control which parameters Blacklight should send is a helpful step to getting more solr configuration back into the request handler without needing to fully commit at the outset.)

@jrochkind
Copy link
Member

yes, agree that for local behavior, before_filters are appropriate. Not quite sure what we're talking about, but I don't need to be.

@eranhirs
Copy link
Contributor

@cbeer I agree, this is a great PR irrelevant whether I will use it in before_filter or not locally.

return unless blacklight_config.add_field_configuration_to_solr_request

blacklight_config.show_fields.each do |field_name, field|
blacklight_config.show_fields.select { |field_name,field| field.solr_params || field.include_in_request || (field.include_in_request.nil? && blacklight_config.add_field_configuration_to_solr_request) }.each do |field_name, field|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the inner block be a method? It could be resused on line 351 too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Updated.

@jcoyne
Copy link
Member

jcoyne commented Feb 17, 2014

I like it.

…ill be explicitly added to the request made to solr. Otherwise, Blacklight assumes the appropriate configuration is made in the solr config.
jcoyne added a commit that referenced this pull request Feb 17, 2014
Add field configuration for :include_in_request. If true, the field will...
@jcoyne jcoyne merged commit f582aa2 into master Feb 17, 2014
@jcoyne jcoyne deleted the include_in_request branch February 17, 2014 23:46
@cbeer cbeer added this to the 5.2.0 milestone Feb 17, 2014
@jrochkind
Copy link
Member

Why not leave the old add_facet_fields_to_solr_request there ALSO, as a shortcut for specifying : include_in_request => true for every single facet you add? I want them all included, it was convenient to be able to say to include them all.

I don't really understand the use case for wanting to include some of them but not all of them; I trust there is one, but the use case for wanting to include all of them remains and I suspect is common?

@cbeer
Copy link
Member Author

cbeer commented Feb 18, 2014

@jrochkind that's exactly what this commit does.

EDIT:
Oh, I get your confusion now. There's an internal add_facet_fields_to_solr_request variable that records whether the "public" API method add_facet_fields_to_solr_request! was called. I've marked the internal method add_facet_fields_to_solr_request as deprecated because, presumably, it is unnecessary.

I originally had some code that iterated over e.g. all the facet fields when it was called to set include_in_request: true, but we have some code still that expects to be able to call add_facet_fields_to_solr_request! in any order (e.g. add facet fields and then call it, or call it and then add facet fields), which made things confusing. I took it out in the commit we merged, until we decide to drop that 'feature' or have a way of providing global defaults. In any case, it's something to revisit when we're getting ready to break API compatibility in the future, but not an immediate concern.

@jcoyne
Copy link
Member

jcoyne commented Feb 18, 2014

@jrochkind There is a method add_facet_fields_to_solr_request! that adds all of them.

@jrochkind
Copy link
Member

Okay, cool.

Why not leave the backwards compatible way to do this though, instead of requiring code to be changed to do the same thing using a new method?

@cbeer
Copy link
Member Author

cbeer commented Feb 18, 2014

@jrochkind what's backwards incompatible about it? I went to great pains to keep it backwards-compatible.

@jrochkind
Copy link
Member

ah, okay, I guess I misunderstood. I thought :add_field_configuration_to_solr_request => true, was no longer supported as configuration. If it still is, my mistake. (If it's not, then that's what's not backwards compatible about it)

@cbeer
Copy link
Member Author

cbeer commented Feb 18, 2014

Supported, yes, but deprecated. I don't think applications are changing that configuration directly, though.. we want them to use config.add_field_configuration_to_solr_request! instead.

billdueber added a commit to mlibrary/spectrum that referenced this pull request Nov 4, 2020
 Somewhere -- I can't find where -- there's a whitelist of things that are passed
 along. I _think_ it related to [this discussion](projectblacklight/blacklight#783)
 which references doing something in a :before filter.

 Everything in @params that is _not_ whitelisted in the config somehow is thrown away.
 Everything in extra_controller_params is passed through unmolested.

 So, because we're sending lots of stuff not configured in the normal blacklight way
 (i.e., pretty much everything in the foci) we'll just merge @params into
 extra_controller_params and call it a day.

 At this point I do _not_ understand why everything isn't passed through; I'm assuming it's
 for security, which is less of an issue for us since we're behind the firewall. I also
 can't think of anything too nasty one can do with GET parameters if you can't pick the
 target handler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants