How do I show Apache Solr results in Panels?

David Needham

9

March 14, 2012 - 10:24am

Dear Chapter Three,

I'm in Drupal 7 and have Apache Solr running on my Pantheon site and we need to customize the layout of the search results page. We've been using Panels for every other page, so we'd really like to use Panels here as well. We noticed that there is an existing panel page template titled: "search-apachesolr_search", but when we enable it our searches always return no results. What's the deal?

Thanks!
Ricki

 

Thanks for writing Rikki. Unfortunately the "search-apachesolr_search" panel template seems to be broken and won't work for you. Fortunately for us there's a great module called Apache Solr Panel which is exactly what you need. Here's some pseudo-code to get you started:

  • Install the best release for apachesolr_panels module.
    • If you get the errors we saw, apply the patch. (Hopefully this will be rolled into a new release soon. Currently 7.x-1.0 does not include this patch.)
  • Create a new custom panel page following the instructions in the apachesolr_panels readme:
    1. Create a new custom panel page.
    2. Make the URL: some-search-url-you-want/!query
    3. When prompted, make the argument in the url = 'string' and give it the name 'search query'.
    4. Fill out all other forms as usual.
    5. When asked to add panel panes, add in the search and results ones in the Apache Solr Panels fieldset.
    • It may ask what context - tell it the query you created ('search query' if you followed the directions above).

But what about the search block? If you try it now, it's pointing to the old search page - not the custom panel page you just created. The Apache Solr Panels module has you covered there as well.

  • If you're using the search block in a region:
    • Remove the search block and use the apachesolr search block instead.
    • It will ask you what the url is for your custom search page and you will say whatever you called it above. (For our example, you'd put: 'some-search-url-you-want').
  • If you're using a search box provided by the theme (in a tpl.php):
    • You will have to do a hook_form_alter on the form to change the url.

    Good luck! Let us know if you have any more questions.

Comments

Hi,

After following these steps, I created a page panel. When I try to search from the search block it take me to the URL of the page with keyword replaced with "!query".

But it doesnt render any content or panel block. Please help me to fix that.

Did you check out the readme I linked to? Make sure you follow each step carefully. It's very important that you set the context in the last step.

Add search elements from the "Apache Solr Search" category of the
57 "Add content" dialog (click the cogwheel of a region within the Content tab) Means?

It means that once you've clicked to add a pane within a region, the specific panes you're looking for can be found within a category called "Apache Solr Search", which should be found on the vertical tab list to the left.

I want to modify a Solr search page that shows the links on the left to show dropdowns with taxonomy terms across the top instead which can be used to filter down the results. Is this possible with this module, or do I need another combination of tools or a custom module?

Solar Panels module works great, but when I use Facets panes, they redirect to default search page.

Is there an 'out the box' way display an exposed filter by content type

By out of the box do you mean by not using panels? Or are you interested in using the above to get a listing of content types?

Hi Mark, I'm using panels, and Apache solr views integration. Im new to Apache Solr/Facets and so far if appears as though I can only filter by content type once I have already submitted the query I need to do this a step earlier.

I was thinking I could create a submit handler which would effectively build the url and then redirect to the desired result eg a search keyword 'australia' of content type 'news item' would look like /solr/australia?f[0]=bundle%3Anews_item

Ive played around with apache solr views but it doesnt seem to work the same as a typical view ie there are missing fields for the specified c/t.

Am i missing something here?

Post a comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
Let us know you're human by typing in this code. The code is case sensitive.
Image CAPTCHA
Enter the characters shown in the image.
To prevent automated spam submissions leave this field empty.