Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

Install Search API Solr

0 (0 Likes / 0 Dislikes)
Install Search API Solr with Joe Shindelar In this tutorial, we're going to start by installing the Search API module and the Search API Solr module, which provides a service class for Search API for interacting with an Apache Solr server. Then we'll use the configuration that's provided by the Search API Solr module in order to reconfigure our existing Apache Solr server so that it has a better understanding of Drupal and Drupal's content and data types. Finally, we'll create a configuration in the Search API user interface that allows for a connection between Drupal and our Apache Solr server. By the end of this lesson, you should have Apache Solr running and Drupal up and running and able to talk to your Apache Solr server and be able to verify that that's the case. Let's go ahead and get started. So the first thing we're going to need to do is install a couple of modules. I'm going to install [https://www.drupal.org/project/search_api] the Search API module because that's kind of the base for everything that we're building here. At the time of this recording, the current version of the Search API module is 7.x-1.14, so that's what we'll be using. The Search API module has a dependency on the Entity API module, also a contributive module. This is what allows the Search API to be really smart about Drupal's content types and fields and their data and able to index all of that without writing a lot of extra code. So we'll have to install the Entity API module as well. At the time of this recording, the current stable version of the Entity API module is 7.x-1.6. And finally [https://www.drupal.org/project/search_api_solr] we're also going to install the Search API Solr Search module. This is what provides the service class for connecting Search API to our Apache Solr server. At the time of recording, the current version of this module is 7.x-1.6, so that's what we'll be using. I'm going to install these using drush. So to do that I'm going to switch over to my terminal. I'm going to verify that I'm in the correct directory. Yeah, looks like I'm in the docroot for the fish database website that we're building. So I'm going to run the command drush dl search_api entity search_api_solr. Those are the machine names of the three modules that we need to download. I'll go ahead and do that. Drush will take care of grabbing the current stable versions of those modules off of drupal.org. And then I can install them. And I'm going to just run drush en for install search_api_solr. In order to install the Search API Solr module, drush is smart enough to recognize that it has dependencies on entity and search_api, so it's asking me if I want to install those as well? Yes, I do. I'll go ahead and let it handle that. There we go. We've got the search_api module installed. If I switch back over to my site, I could confirm that this is working by clicking on Configuration and then navigating down the page. Under Search and Metadata, there's now a Search API option. This didn't exist before, so I can click on that and I can see that yes indeed, the Search API module is installed and working. We'll come back and talk about all the things that you can do on this screen once we've created the appropriate Solr configuration. I'm going to switch to my text editor. In my text editor, I can take a look at the modules we just downloaded, entity, search_api, and search_api_solr. First off, I want to point out that the Search API module in that directory has a subdirectory named contrib. And in the contrib subdirectory are two additional modules, search_api_facetapi, which creates a bridge between the Search API module and the Facet module —we'll look at that in another tutorial—and search_api_views, which exposes the index created by Search API to the views module so you can create views, another one that we'll look at in a future tutorial. We also downloaded this search_api_solr module. If you check out the INSTALL.txt file, it has some really great instructions about both setting up Apache Solr so that you've got an Apache Solr instance to use with your Drupal site as well as some additional steps that we're going to need to take in order to configure Solr to work well with Drupal. All of the content is here. The gist of it is this. Inside of this solr-conf directory nested inside of the Search API Solr module, there are two subdirectories, 3.x and 4.x. These correspond to the version of Apache Solr that we're running. In our case, we're using the 4.x version. Inside of that directory are a bunch of xml and txt files. These are settings files for the Apache Solr server. And we need to copy the settings files from the Search API Solr module to our instance of Apache Solr and then restart our server so that it makes use of these settings. Just to get a sense of what these settings files contain, the solrconfig.xml file, this is kind of like the server settings for Solr. It configures things like the memory limits for your Apache Solr server. It's similar to like a php, ini file or an Apache configuration file. It kind of sets how all of the pieces fit together and are running. I want to point out in this file if you search for the term pink pony, down here towards the bottom of the file is the configuration for the pink pony request handler. I point this out and I think this is interesting because this is the configuration that allows requests from Search API, really from Drupal, to work well with Solr. This particular configuration, and actually all of the configuration that comes with the Search API Solr module, is the exact same configuration that comes with the Apache Solr module, another module that you could have used to integrate Drupal and Solr. The nice thing about this is the Drupal community is starting to standardize on what it considers to be best practices for exposing Drupal's content to a Solr index. So that's what this pink pony request handler takes care of. Another interesting file is this schema.xml file. Again, this is the same schema file that the Search API module will use and the Apache Solr module. What this does is it defines new datatypes in Solr. So up here towards the top, you've got all these field-type definitions: string, boolean, binary. If we scroll down you start to see some more complex datatypes text and the configuration for each of those. So this is saying for a simple text-type field, this is the Solr class that should be used as the sort of indicator of this type of field, and this is how we want to handle fields of that type. We want to use the whitespace tokenizer. We want to use the mapping character filter. In here you can see additional configuration for filters to apply to fields of the type txt. the stop words filter, the word delimiter filter which takes care of part of the tokenizing and figuring out where does a word start and stop? This is all the configuration for how Solr is going to index the content that it's handed from Drupal. So you've got your field types here, and if you scroll down further in this file, you'll see the definition of fields. So we've got field types which kind of indicate the type of data that we're indexing. And then you've got fields which are used to specify an individual field on a document. Think of fields as being the same as fields that you create on a content type using Drupal's field API. You can start to see some Drupal-like fields here, entity_id, entity_type, so things like node_id and maybe node being the type of entity; bundle names, so what content type are we talking about; and some other Drupal specifics. And if you scroll down further, you see a bunch of these fields that are called copyfield and then ts_*, tm_* and then dynamic field. Both these fields that start with a two-letter prefix, underscore, asterisk are what's called dynamic fields. When we create a Search API index, part of what we need to do is map a field in Drupal, so say the title field of a node, to a Solr field type. And we'll be using these field types. So we'll map, for example, a title field for a node to a text field in Solr, ts_*. The prefix here has a special meaning. T is the field type, so text in this case, more string or boolean, and then another value, the second letter, is either m or s indicating whether or not this is a single-value field or a multi-value field. For the most part, you probably don't need to change these things, and you can just leave them as is. However, if you start getting into really customizing your Solr application, you might want to edit some of the schema definition or maybe even the Solr config. If you do, I recommend that instead of editing schema.xml or solrconfig.xml directly, you actually edit these ones labeled _extra.xml. The idea is your customizations go in the extra configuration file. If you ever need to update the Search API Solr module and get new configuration for Solr, that new configuration will always be in the solrconfig.xml file. You can safely replace that in your Solr instance and everything will just work. What you don't want to do is make tweaks to the solrconfig.xml file, save those, and then later on update the Search API Solr module, and now you're in a situation where you need to try to figure out which changes are your specific tweaks and which ones are changes that came with the module? So keep your changes in the extras.xml file. All right. Enough about the configuration. Let's actually make use of this configuration. If I switch over to my finder, inside of the docroot directory, sites, all, modules, search_api_solr, inside of the solr-conf directory we've got this 4.x directory. I'm just going to select all of the files that are in that directory and copy them. I'm going to copy them—not move but copy—into our Solr configuration. So I've got my local copy of Solr. I'm just using the example app that came bundled, great for local development. So I've got the Solr vendor directory inside of there. I've got the collection that we're using. You have to have one or more collections for a Solr index. And then configuration in this case is collection specific. So I'm going to put this in the collection1 conf directory. And I'm just going to paste in all of those files and replace any that are already there. So I've done that, and I've updated the schema.xml and solrconfig.xml, et cetera. Now in my terminal, I need to start or restart our Solr server. In order for configuration changes like this to take effect, if your Solr server is already running you'll need to stop it and start it again. Mine's not running currently, so I'm just going to start it— java.jar, start.jar—run that command. That should start up my Solr server using the new configuration. Great. Now I can configure Drupal to connect to Solr. Over on our site, on the Configuration tab under the Search API settings, I've got this screen which allows me to do a few things. The part we're going to do now is add a new server. You can add any number of different servers for Search API to connect to, so you can have sort of multiple search indexes going at the same time for our site. We're only going to have one here. We're going to click Add a server, and then we're going to go through and fill out this form. We'll call our server—we'll just name it Solr, keep it nice and simple. We'll leave it enabled. This indicates though that there is the ability to configure a server in Search API and have it enabled or disabled depending on your needs. There's also a server description. The name and description here are for administrative purposes only. They'll only ever be displayed in the admin you want. You can fill them in with information that's useful for your team. Then there's service class. We've only got one service class right now. The Search API Solr module is providing the Solr service, so we'll choose that. If we had other service class modules installed, we could choose between those. The Solr service has some Solr-specific configuration that we need to fill in as well. We need to basically tell the Solr service module how to connect to our Solr instance. Would you like to use http or https? If it's available to you, I highly recommend using the https protocol so that your communication between Drupal and your Apache Solr server are encrypted. I don't have it set up on my local host though, so I'm just going to use http. And then you need to define the Solr host port and path. I'm going to leave these all as the default because I'm just using default Solr configuration right now. But what this indicates is that if, for example, I had Solr running on a different server from Drupal, I could put in the IP address or host name of the server that is running Solr. If I'm running Solr on a different port than the standard 8983, I could change that. And then I could also change the path for my Solr configuration, specifically which core do I want to use for my application? There's also some additional configuration that I could add, advanced things like, if my Solr server is behind http authentication, I can put in a user name and password here. I'm going to leave these as is and just click Create server. I'm then taken to a screen which displays sort of the status of my connection to the Solr server. This indicates that yes, Drupal was able to connect to my Solr server. If I turn my Solr server off and refresh this page, I would have an indicator here that Drupal was unable to reach the Solr server. And then it just provides a little bit of additional information. Which schema is it using? So which configuration—and that's correct, because we loaded that up into Solr— as well as what collection it's using. It looks like everything is working fine in this case. So I'm going to say I'm happy that we've been able to connect Drupal and our Search API to our Apache Solr index. In this tutorial, we downloaded and installed the Search API and Search API Solr modules, both of which are required in order to create a search interface between Drupal and an Apache Solr server. We then looked at the configuration files that came with the Search API Solr module and talked about the necessary need to take those configuration files and use them with our Solr instance. These configurations are specially designed to help Solr better understand the data that Drupal will be providing it. Finally, we used the Search API user interface to create a new configuration that allows us to connect Drupal with a running Apache Solr instance. In the next lesson, we'll take a look at creating an index in the Search API so that we can start sending data from Drupal to Solr to be indexed.

Video Details

Duration: 15 minutes and 3 seconds
Country: United States
Language: English
License: All rights reserved
Genre: None
Views: 68
Posted by: drupalizeme on Apr 24, 2015

Install Search API Solr

Caption and Translate

    Sign In/Register for Dotsub to translate this video.