We have a project, with several local development servers, test, staging and production server. The project is handled by features, and we needed a way to handle the Solr host configuration where we could overwrite the host,port and path in settings.php.

I have made a patch which handles it.

* In admin/config/search/search_api it tells you if the configuration is hardcoded in settings.php, and you cannot change it.
* The patch works by getting the variables from settings if set, else it takes it from the original configuration.
* If you only want to have separate path and leave host and port the same, then you can decide to only set that in settings.php.

Ex. 1. settings.php
$conf['search_api_solr_host'] = 'localhost';
$conf['search_api_solr_port'] = '8983';
$conf['search_api_solr_path'] = '/solr/instance';

Ex. 2. settings.php (only the path changed).
$conf['search_api_solr_path'] = '/solr/instance3';

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ramlev’s picture

I have just checked, and the patch applies to 7.x-1.x as well.

ramlev’s picture

New version of the patch added, the first one is corrupted :(

Silicon.Valet’s picture

I could also use this feature, and this makes a lot of sense.

Anonymous’s picture

Thanks for the patch. Before it could be applied, it has to be more generalized:

variable_get('search_api_solr_host', $options['host']);

Since you can have multiple servers, the server ID should be part of the server (machine) name? And when you delete a server, it should delete the variables.

ramlev’s picture

Im working on a new patch which handles multiple servers, should be here in this upcoming weekend.

ramlev’s picture

Changes to the patch is made, and now:

+ Deletes any variables set in database, when removing a server.
+ Supports multiple servers.

The changes to the variables is like

search_api_solr_MACHINE_NAME_host
search_api_solr_MACHINE_NAME_port
search_api_solr_MACHINE_NAME_path

Where the MACHINE_NAME is the machine name of the search_api server, which can be seen when viewing a search_api server.

If you only want to overwrite the path, then you just have to define that in your settings.

ramlev’s picture

Status: Active » Needs review
forestmars’s picture

Status: Needs review » Reviewed & tested by the community

Nice work. I am now using this in a multi-stage environment and it's functioning correctly.

jnettik’s picture

One question I have was if this is reliant of the host config being in a feature? I need the same thing however right now the config is in the DB. Would setting these variables still work or will I have to export everything out into a feature first?

kasperg’s picture

ramlev: The patch does not seem to include username and password for HTTP authentication. Is there a reason for this?

ramlev’s picture

Status: Reviewed & tested by the community » Needs work

No not really :) Simply because i forgot it i think. I will update the patch quickly to support those fields as well.

ramlev’s picture

Status: Needs work » Needs review
FileSize
12.24 KB

The patch is now rewritten to support overwrites of the http auth settings as well. Please test, and we will hopefully be able to get the patch applied.

danquah’s picture

Status: Needs review » Reviewed & tested by the community

I applied the patch in #12 and did a test with a Solr-server that had basic auth protecting it. Works like a charm, thanks!

derhasi’s picture

Hm, I think that is not a good approach, as
* this should, if it is done, be done in the search api in a generic way
* we already got a generic way by using existant hooks (see Search API Solr Overrides or a Features based approach).

kasperg’s picture

#14: None of the existing hooks support configuration through settings.php out of the box. I guess this is the primary use case for the patch.

I agree that it would be nice to have this Search API in a generic way. In that regard your module Search API Override seems like an optimal solution. Why not submit it as a patch to Search API? 5-10 lines of code does not warrant a separate module.

drunken monkey’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for the idea and your patch! It looks rather good.
However, a few things need improving:
- I think you should make the config variable a single array, with the machine name and then the individual settings as nested keys. (Similar to derhasi's Override module, just without the additional options key.)
- That way you could also get rid of the form alter magic and just delete that variable once the module is uninstalled. (Also, if you still wanted to delete the individual servers' settings when they are deleted, hook_search_api_server_delete() would be a better place to do that.) (Actually, I'm not sure you even have to delete a variable you never set yourself in the module. After all, if the user manually sets the variable, you'd think he could delete it himself, too.)
- You should reflect the fixed option values also in the settings form, instead of only disabling the elements.

@ derhasi: I think it would be hard to do this in a generic way in the Search API, as you'd have a considerably harder time reflecting this in the server's config form. Also, for other backends it might not make so much sense. And lastly, this would probably introduce an API change, which I like to avoid now.

derhasi’s picture

@drunken_monkey, sorry, I have to disagree. There is a very simple and very generic approach that uses existing api and does not create any new one: @see http://drupalcode.org/project/search_api_solr_overrides.git/blob/refs/he...

Overriding it for other backends will make sense, as we are dealing with search api servers, simply by definition there might be differences for different stages.

drunken monkey’s picture

@drunken_monkey, sorry, I have to disagree. There is a very simple and very generic approach that uses existing api and does not create any new one: @see http://drupalcode.org/project/search_api_solr_overrides.git/blob/refs/he...

As said:

you'd have a considerably harder time reflecting this in the server's config form.

On the other hand, admins should generally be aware that they've overridden the settings. If you document this properly, and maybe implement hook_help() or some other means of alerting admins to the fact that changes to the server settings won't take effect – then the problem should be largely mitigated, and a custom solution really unnecessary.

Any more opinions on this?

derhasi’s picture

@drunken_monkey: I'll try to work out a solution in my sandbox that will take your notes into account and the work done in search_api_solr_overrides.module. I opened an issue in the sandbox for that #1963624: Merge functionality with search_api_solr_overrides.

helmo’s picture

A similar issue for Search API was filed in #1606732: Allow override of search index (and servers) settings in settings.php and closed in order to focus on the contrib approach like #19

derhasi’s picture

I finally had some time to work on the sandbox. The lates code is in 7.x-1.x-merge. Feel free to post some review in #1963624: Merge functionality with search_api_solr_overrides.

Beanjammin’s picture

It seems to me that the underlying issue here is that when working with features the solr server configuration can not be separated from the index configuration. Were it possible to separate the two then we could put the index configuration in one feature and use it across dev/staging/production with separate per-site server configuration, either in a separate feature module (my preference) or settings.php.

Beanjammin’s picture

Hmmm, actually it seems my info is/was out of date. The ability to split out server/index configuration within features is now available.

derhasi’s picture

Beanjammin, split of server/index was never a problem, as server and index were allways only linked by the server's machine name. The problem is/was, that maintaining different features for only providing different credentials for the solr server is much overhead. So maintaining that credentials as part of the settings.php. As mentioned above, that is now generally possible for search api, by using search api override.

lambic’s picture

Any chance of getting this out of the sandbox sometime soon?

derhasi’s picture

I just promoted the project to full project: https://drupal.org/project/search_api_override

lambic’s picture

Thanks derhasi!

DamienMcKenna’s picture

Issue summary: View changes
Status: Needs work » Fixed

I think this is good to go now :)

That said, maybe this project's main project page could be updated to include a note about the new module?

drunken monkey’s picture

Great to hear, thanks again for your work!
I've added the module to the list of extension modules in the handbook and to this module's "Pecularities" handbook section. Hopefully, this will be enough for people to find it.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.