Debugging a Solr search

Last updated on
28 March 2026

Sometimes when using this module, you might come across a search that doesn't return the expected result (or facet, highlighting, etc.). When you've looked at the other sections in this handbook (especially Special server features and pitfalls) and not found anything, looking at the Solr request directly to see where the problem is might be the best next step. (It is also often a great help when you create support requests in the issue queue.) This is usually (depending on your server setup) not particularly complicated.

The simplest option for doing is to enable the “Search API Solr Devel” module that is already included when downloading the Search API Solr module. Its only additional dependency is the Devel module. This will print all Solr requests sent, and their responses, to the screen for all admins (that is, users with the access devel information permission).

Retrieving the request made to Solr

First, you need to locate Solr's log files. This depends on how you've set up Solr. When you have set it up locally, Tomcat's logs/ directory usually contains the log files (you want the access logs). The example server also prints log messages to the standard output, which you can redirect to a file or maybe access directly (depending on how you are running it). If none of these yield the needed log files (which list the requests made to the Solr server), try to consult the documentation of the Java webserver you are using to run Solr to see where it might save log files, or how you can bringt it to do that.

When you are using a hosted solution, they might supply the log files to you in some way, maybe through some admin UI. Otherwise, try contacting the hoster to get the relevant ones. If this is still not possible, you can also add a debugging statement to your site's code (on a development/test site, of course) to output the Solr request there. E.g., in search_api_solr/includes/solr_connection.inc add a line a few lines below protected function makeHttpRequest:

    drupal_set_message(check_plain($url)); // <-- Add this line.
    $result = drupal_http_request($url, $options);

This will output all the Solr search requests sent to the Solr server directly in your browser.

If you have a log file, just search it for the line containing the search keywords used by you, or received at the right time (if there aren't too many requests on your server). Remember that the keywords will be URL-encoded in most cases in log files, though.

The request, once you have it, can already tell you a lot, if you know a bit about how Solr works. Maybe a parameter that's necessary for the functionality in question isn't even passed to Solr, or maybe there is some other apparent error. In that case, the problem probably lies somewhere on the Drupal side, in the Search API or Search API Solr Search modules.

Retrieving a Solr response

If the request itself looks OK, looking at the response that Solr returns for that request is the logical next step. For that, there are several options:

  • Adding a debug statement to the code: If you already did this for getting the request, this will probably be the easiest way. In search_api_solr/includes/solr_connection.inc add a line a few lines below protected function makeHttpRequest:
        $result = drupal_http_request($url, $options);
        drupal_set_message(check_plain($result->data)); // <-- Add this line.
    
  • If you have access to Solr's admin UI, you can also issue requests through there. Just go to "Query" for the core you are using (for Solr 4.x, for Solr 3.x there is of course only one), clear the already filled fields and put all the query parameters from the request into the "Raw Query Parameters" field.
  • If Solr is protected from outside access (as it should always be for production sites), log onto your server and instead issue the request using a command line tool like wget or curl. The URL to retrieve is constructed by using the Solr server URL as displayed in the server's "View" tab in Drupal (along with the core name, if not included, at the end), followed by /select? and the request parameters.
  • Lastly, you can also use the Devel module's "Execute PHP" page/block to send a request to Solr:
    parse_str('YOUR REQUEST PARAMETERS', $params);
    dpm(search_api_server_load('SERVER MACHINE NAME')->getSolrConnection()->search(NULL, $params));
    

    The "response" part is the best for browsing through the response, "data" is better for posting in the issue queue.

The response might yield further insight into where the error in question happens. If the request is OK but the response isn't, then wrong Solr configuration (or a bug in Solr itself) is probably the cause. If the response still looks OK, then the code is most likely in some postprocessing done by the Drupal modules involved.

Help improve this page

Page status: No known problems

You can: