Specbee: How to set up Apache Solr Plugin on Ubuntu in a Lando environment and configure Search API Solr in Drupal

Imagine delivering faster, more accurate search results to your users. Apache Solr makes that possible. Built on Apache Lucene, this open-source search platform powers enterprise-level search and analytics. It’s not just about speed—Solr's advanced features like full-text search, hit highlighting, faceted search,  real-time indexing, and more can significantly enhance your business's data handling and customer experience. In this article, you’ll learn how to set up Apache Solr on Ubuntu within a Lando environment and configure it with the Search API. By the end, you'll understand how to leverage Solr's powerful search capabilities to enhance your Drupal website’s performance and user experience. What You’ll Need Ubuntu Server (20.04 or Later): Ensure you have a server running Ubuntu 20.04 or a more recent version. Java Development Kit (JDK) or Java Runtime Environment (JRE): Apache Solr requires either JDK or JRE to function properly. Make sure Java is installed on your server. Terminal/Command Line Access: You'll need access to a terminal or command line interface to execute commands during the setup. Familiarity with Linux Commands: Basic knowledge of Linux commands is essential to navigate and configure the server efficiently. Setting Up : A Step-by-Step Process Step 1: Update the System Before diving into the installation, it's crucial to ensure your system is up-to-date. This helps prevent compatibility issues and ensures you have the latest security patches. Open the terminal and execute the following command: sudo apt-get update && sudo apt-get upgrade -y Updating your system's package list before installing new packages is always recommended. This command updates your package list and upgrades any outdated packages. Step 2: Install Java Apache Solr requires Java to run. To get started, you'll need to install the Java Development Kit (JDK). sudo apt-get install default-jdk -y Verify Installation: java -version Once installed, verify the Java installation to ensure it's set up correctly. Java is essential for running Solr, so make sure this step is completed without errors. Step 3: Download and Install Solr Next, you'll download the latest version of Apache Solr and install it on your server with this command: wget https://downloads.apache.org/lucene/solr/8.11.3/solr-8.11.3.tgz Extract the downloaded archive: tar xzf solr-8.11.3.tgz Navigate to the Solr installation script directory: cd solr-8.11.3/bin/ Run the installation script with sudo: sudo ./install_solr_service.sh ../solr-8.11.3.tgz Looking to enhance your Drupal site’s performance even further? Our expert team specializes in custom Drupal development and can help you optimize your search functionality for better user engagement. Step 4: Start and enable Solr Service After Solr is installed, you need to start the Solr service and enable it to start automatically on system boot. sudo systemctl start solrsudo systemctl enable solr Starting the Solr service allows it to begin running on your server. Enabling the service ensures it starts automatically whenever your server reboots, ensuring Solr is always available. Step 5: Configure Solr for Your Drupal Project To integrate Solr with your Drupal project, you'll need to modify the .lando.yml file. Add the Following Code to .lando.yml: services:   search:     type: solr:8     config:       dir: ./solr_8.x     core: drupal     portforward: trueAfter adding the above code, run the following command to rebuild your Lando environment: lando rebuild Step 6: Install & Configure Search API Solr With Solr configured, the next step is to install and enable the Search API Solr module in your Drupal project. Use Composer to install the Search API Solr module.lando composer require 'drupal/search_api_solr:^4.3'  Enable the module by navigating to admin > Extend > Search API Solr or running this command from the terminal:lando drush en search_api_solr  After enabling go to Configuration > Search and metadata > Search API Click on Add server to configure Solr as your search server and save the configuration. How to Add a Search Index Now, let’s create a search index that will allow your site to use Solr for searching content. Navigate to Add index within the Search API configuration. Choose a name for your index. Pick the datasources from which Solr will pull content. Choose the Solr server you configured earlier. Click on Save to save the configuration. After setting up the index, you'll need to configure the fields that Solr will index. Navigate to the Fields tab. Click Add fields and select fields like Title and Body. Add content fields based on your requirements, then save the changes. Access the newly created index and click on Index Now to begin indexing your site’s content. Enable Highlighting in Apache Solr To enhance user experience, enable highlighting in Solr to emphasize matching search terms. Steps: Go to the Processors tab in the Search API configuration. Check the Highlight option. Configure the settings as needed and save the configuration. Highlighting will make it easier for users to see relevant search terms in the search results, improving the overall usability of your site. Final Thoughts By following these steps, you'll have a fully operational Solr search setup, optimized for integration with Drupal. This setup not only improves search performance but also enhances the user experience by delivering faster and more relevant search results. Need help with your Drupal setup? Our Drupal development services can assist with fine-tuning your search functionality. Reach out for expert support.
PubDate

Tags