Solr commands reference

Install Solr8.1
==========
1. Start the solr

cd solr-8.5.1
bin/solr start

2. Enable basic authentication plugin (standalone mode)

cd server/solr
vim security.json

{
   "authentication":{
      "blockUnknown":true,
      "class":"solr.BasicAuthPlugin",
      "credentials":{
         "solr":"vxxGVpJ0SiWA3LgtLCX8U+b3kGnFjS4CsT27Zz3g+MQ= iRFoY1CY1uFO6PgkugiN30eapYJ5SKFiHhBuy8O4rg0="
      },
      "realm":"My Solr users",
      "forwardCredentials":false,
      "":{
         "v":0
      }
   },
   "authorization":{
      "class":"solr.RuleBasedAuthorizationPlugin",
      "permissions":[
         {
            "name":"security-edit",
            "role":"admin"
         }
      ],
      "user-role":{
         "solr":"admin"
      }
   }
}

Referrence:

3. Change the password

The above json will create solr authentication with username "solr" and password "SolrRocks". To change the password do the following
curl —-user solr:SolrRocks http://localhost:8983/solr/admin/authentication -H 'Content-type:application/json' -d '{"set-user": {"solr":"iamadmin"}}'



Old: Solr 4.x
==========

To copy solr files from local to docker container.

sudo docker cp 4.x/. container_php56_1:/opt/solr/solr-4.4.0/example/solr/collection1/conf

(or)

in your Dockerfile you can add this

ADD config/solr/elevate.xml /opt/solr/solr-4.4.0/example/solr/collection1/conf/elevate.xml
ADD config/solr/mapping-ISOLatin1Accent.txt /opt/solr/solr-4.4.0/example/solr/collection1/conf/mapping-ISOLatin1Accent.txt
ADD config/solr/protwords.txt /opt/solr/solr-4.4.0/example/solr/collection1/conf/protwords.txt
ADD config/solr/schema_extra_fields.xml /opt/solr/solr-4.4.0/example/solr/collection1/conf/schema_extra_fields.xml
ADD config/solr/schema_extra_types.xml /opt/solr/solr-4.4.0/example/solr/collection1/conf/schema_extra_types.xml
ADD config/solr/solrconfig.xml /opt/solr/solr-4.4.0/example/solr/collection1/conf/solrconfig.xml
ADD config/solr/solrconfig_extra.xml /opt/solr/solr-4.4.0/example/solr/collection1/conf/solrconfig_extra.xml
ADD config/solr/solrcore.properties /opt/solr/solr-4.4.0/example/solr/collection1/conf/solrcore.properties
ADD config/solr/stopwords.txt /opt/solr/solr-4.4.0/example/solr/collection1/conf/stopwords.txt
ADD config/solr/synonyms.txt /opt/solr/solr-4.4.0/example/solr/collection1/conf/synonyms.txt

for error
Unable to use updateLog: _version_field must exist in schema, using indexed="true" stored="true" and multiValued="false" (_version_ is not indexed

use the following link to resolve.
https://www.drupal.org/project/search_api_solr/issues/1676224

adding following line resolves the problem.
<field name="_version_" type="long" indexed="true" stored="true"/>


Following code can be used to alter the results thats coming from solr (while using search_api module)


function MODULE_search_api_results_alter(array &$results, SearchApiQueryInterface $query) {
  if (!empty($results['results'])) {
    foreach ($results['results'] as $id => $result) {
      if (!empty($result['fields']['search_api_viewed'])) {
        $results['results'][$id]['fields']['search_api_viewed'] = array(
          '#value' => $result['fields']['search_api_viewed'],
          '#sanitize_callback' => FALSE,
        );
      }
    }
  }
}




Comments

Popular posts from this blog

Programatically create layout builder section in Drupal

Code quality analysis of Drupal. Can I use Sonar?

Set up Drupal7 to Drupal8 migration in simple steps (using Drush)