The apachesolr module uses variables to store its configuration data, meaning that I was able to make sure dev and staging sites didn't write to my solr index by putting a line into a local settings.inc.php file:

$conf['apachesolr_read_only'] = 1; // D6

$conf['apachesolr_environments']['acquia_search_server_1']['conf']['apachesolr_read_only'] = TRUE; // D7

This module seems to provide similar functionality for overriding the server configuration, but in my case I'd like to use the same server but in read-only mode.

Since this module has the generic name "Search API Override" and not "Search API Server Override", I thought I'd ask here if this feels like a reasonable feature request :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

derhasi’s picture

I couldn't have thought about any use case regarding indexes, but that seems to be a valid one. Can you provide a patch for that?

mvc’s picture

Glad you agree it would be useful. I'll ask my client for a mandate to write that patch, and post here if that's approved.

brenk28’s picture

Version: 7.x-1.x-dev » 7.x-1.0-rc1
FileSize
12.51 KB

Attached a patch (against 1.0-rc1) that adds the index override functionality.

sheise’s picture

Thank you for the patch!

I could not get read_only to work as overridden as part of the options array as it needs be a top level item in the array.

Here's an updated patch.

sheise’s picture

Sorry, missed a line in my patch. Here's the correct one.

Jody Lynn’s picture

Status: Active » Needs work
  1. +++ b/search_api_override.info
    @@ -2,3 +2,10 @@ name = Search API Overrides
    +; Information added by Drupal.org packaging script on 2014-02-25
    +version = "7.x-1.0-rc1"
    +core = "7.x"
    +project = "search_api_override"
    +datestamp = "1393356206"
    +
    

    Don't add this

sheise’s picture

Fixed issues from comment #6.

New patch with fixes from #3 and #5.

sheise’s picture

Status: Needs work » Needs review
jsst’s picture

Setting solr to readonly is easy in apachesolr, but not so using search_api. We've solved this use-case using this patch and the following settings:

        $conf['search_api_override_mode'] = 'load';
        $conf['search_api_override_indexes'] = array(
          'search_index_machine_name' => array(
            'name'      => 'Search (read-only)',
            'read_only' => TRUE,
          ),
        );

I believe this patch should be merged into the 1.0 release because:

- the new feature is documented in the README file
- overriding indexes is solved in a similar fashion to how overriding servers works, without code duplication
- follows the drupal coding styleguide

jsst’s picture

Status: Needs review » Reviewed & tested by the community
nlambert’s picture

Status: Reviewed & tested by the community » Needs work

I'm seeing this:

SearchApiException: Unknown index default_node_index. in SearchApiDbService->search() (line 916 of /srv/repos/lcom_www/sites/all/modules/contrib/search_api_db/service.inc).
SearchApiException: No field settings for index with id default_node_index. in SearchApiDbService->indexItems() (line 586 of /srv/repos/lcom_www/sites/all/modules/contrib/search_api_db/service.inc).

To overcome I have to save the form @admin/config/search/search_api/index/default_node_index/fields

Edit: I actually have to change a value in that form for indexing to work on an overridden index

DamienMcKenna’s picture

DamienMcKenna’s picture

This may not be working as intended. I have indexes configured to use Solr. I override them via search_api_override_indexes to use a database instead, like so:

$conf['search_api_override_mode'] = 'load';
$conf['search_api_override_indexes'] = array(
  'teachings' => array(
    'name' => 'Teachings (local db)',
    'server' => 'database',
    'options' => array(
      'cron_limit' => 5,
    ),
  ),
);

However, when it runs the SearchApiDbService::indexItems() method throws an error because $this->options['indexes'] doesn't exist.

osopolar’s picture

Version: 7.x-1.0-rc1 » 7.x-1.x-dev
FileSize
13.24 KB

I ported patch to current dev version (7.x-1.0-rc1+1-dev) and did some minor changes on comments (line breaks) and:

+          $message = t('Settings for some Search API @components are overriden via %mode-mode. Look at their settings page for more details: !links.', array(
+            '@components' => $component_plural,
+            '!links' => implode(', ', $links),
+            '%mode' => $settings['mode'],
           ));

instead of

+          $message = t('Settings for some Search API servers|indexes are overriden via %mode-mode. Look at their settings page for more details: !links.', array(
+            '!links' => implode(', ', $links),
+            '%mode' => $settings['mode'],
           ));

@DamienMcKenna: Did you find the source for your problem?

There is one thing that I am wondering about, I have set 'read_only' => TRUE it works so far as changing content won't re-index the item – (it does not change on the (solr) search server). But it gets marked as dirty, as drush sapi-s shows one item less indexed as before the change. Is that expected behavior?

solideogloria’s picture

Re #14, it sounds like that's right, because if you were to change the index to no longer be read-only, those "dirty" items should probably be re-indexed, right?

Also, if nobody is still complaining about issues with the current state of the patch, I think it should be moved to RTBC. I've been using patch #7 for several months, and I think the ability to override indexes should be merged into a 2nd release candidate.

solideogloria’s picture

Also, make sure to update README.md

DamienMcKenna’s picture

FYI you can use the patches to override the config like so..

If you want to make the "my_index" search index use the "local_solr" config, add this to your settings.php file:

// Search API Override.
$conf['search_api_override_mode'] = 'load';
$conf['search_api_override_indexes'] = array(
  'my_index' => array(
    'name' => 'My index',
    'server' => 'local_solr',
  ),
);

None of the 'options' values need to be given if you want to just use the existing configuration.

In my sites I've started building a local Solr config and exporting it to a Feature which I only enable locally, this reduces the amount of configuration changes / overrides necessary to make it work.

solideogloria’s picture

Does anyone have a good idea on what description could be added to the README.md file to document the functionality added by overriding indexes?

solideogloria’s picture

I gave it a shot. I started with patch #14 and added an index example to the README.md based on code from previous comments.

solideogloria’s picture

solideogloria’s picture

Title: Override indexes as well? » Override indexes as well

  • ilchovuchkov committed c1f5b23 on 7.x-1.x
    Issue #2371091 by sheise, solideogloria, brenk28, osopolar,...
vuil’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

vuil’s picture