In this tutorial we will walk through the steps necessary to integrate Magnolia 5.4.6 with Solr 5.5.0. Once integrated we will see how to create localized search pages for a multi-language website. In this case we will use the travel demo website provided with Magnolia CMS as the example website. The travel demo website is a single-site-multi-language example where we will use filters to filter out one language when searching for content in the other. If you have any issues or questions about the tutorial please comment at the bottom of the page.
- Magnolia 5.4.5+ EE: 5.4 Releases
- Magnolia Solr 5.0.2 Content Indexer Module: https://documentation.magnolia-cms.com/display/DOCS/Solr+module
- Magnolia Solr 5.0.2 Search Provider Module: https://documentation.magnolia-cms.com/display/DOCS/Solr+module
- Apache Solr 5.5.0: http://archive.apache.org/dist/lucene/solr/5.5.0/
Install Apache Solr
Apache Solr is a standalone search server. Solr module for more instructions on installing Solr 5. These instructions also cover creating a core for your Magnolia instance so be sure to complete all steps.and extract the zip to your computer. See
Install Magnolia with Solr Modules
This tutorial is using Magnolia 5.4.6 bundle. However, another version should also be fine or a Magnolia running in your IDE should also work as well.
Be sure to also install the required Magnolia Solr models as they are not part of the standard bundle. You can either download them from our nexus or include them as dependencies in your Maven project. See Solr module for more.
This tutorial also requires that the travel demo be installed but this is not a hard requirement. You may want to use it as a guide for indexing your own website.
I do recommend working through this tutorial using the travel demo first if you are new to Magnolia.
Indexing website content
We need to configure a separate index for each language served by the demo site. The Magnolia Content Indexer module will provide you with an example of how to index content located in the website workspace. That example can be found here
Create a default index
The default index will index the content for our default language. In the case of the travel demo that would be the English content.
- Locate the example index found here
- Set the
The field mappings defines how Magnolia content properties are mapped to Solr fields. Left side is Magnolia, right side is Solr. Essentially we are telling Solr which properties we would like to index. These properties get mapped to fields in Solr documents.
In our example indexer there are some field mappings set up for you. For the tutorial we'll use these mappings.
Depending on your project you may want to add additional fields. The default mappings probably do not cover every property you want to index on your pages.
You can use the fields available in the schema. If a field does not exist in Solr's schema you can use a dynamic field
mgnlmeta_* . For instance if you have information nested in a deep leaf of your page stored with property
specComponentAbstract , you can map this field with
mgnlmeta_specComponentAbstract . The indexer contains a recursive call which will explore the node's child leaves until it finds the property.
Create a German content index
- Rename the duplicated index to
websiteIndexer_deto signify it's the German content indexer.
- Change the value of the
Change the names and values of all field mappings to have the suffix
_desuffix to the names of the field mappings will instruct Solr to look for those properties which store German content in a single-site-multi-language implementation. See Storing and serving localized content for more information on how multi-language data is stored in a single tree structure.
Trigger the initial indexing
To trigger the initial indexing of the content set the
enabledproperty to true on both indexing configurations.
Watch the log file for the following messages of indexing confirmation.
- There is also a confirmation of successful indexing shown in the UI at the bottom of admincentral using a INFO type banner message.
Finally you should see a new
indexedproperty at both indexing configurations
websiteIndexer_de. You may need to refresh the node to see the property. A simple close-open toggle of the indexer configuration node should do the trick in making it appear.
You can always trigger the indexing mechanism by setting the
indexedproperty to false and waiting a few seconds for the confirmation.
Create a search results template
Most likely your website already has a design in-place or is in-the-works. This is the case with our travel demo site. It has a search results template already available. All we need to do is make a Solr version of this template. On the other hand if you're just getting started with Magnolia there are some example page templates provided by the Search Provider module. See Creating a search results page for both MTE and STK examples.
Locate the travel demo search results template here
This file is found in the
resourcesworkspace using the Resource Files app.
Make a copy of the existing template and use it to create a Solr version.
Notice my copy exists in the
resourcesworkspace. This is indicated by the JCR icon in the Origin column of the Resource Files app. This is fine for the tutorial but ideally you would want to create your template in a custom module.
The Magnolia Search Provider module provides us with a page dialog (
/modules/solr-search-provider/dialogs/pages/pageProperties) and search result component (
/modules/solr-search-provider/templates/components/solrSearchResult) that we can use in our search results page template.
Add a page
titleset to Travel Solr Search Results
Change the page
templateIdof the auto-generated component to use
headlineof the auto-generated component to Solr Powered Search Results
- Make the new template available in the travel site definition using the Site app.
- Duplicate the node
- Rename it to
- Change the
- Duplicate the node
Create the search results pages
For this tutorial we will use the approach of a separate search results page for each language. In this case two pages, one for English results and one for German results.
Internationalize the result page link field
The travel demo has a special page dialog for the page templates used within it's site. This dialog provides a field for the location of the search results page. Since we will have two results pages, one for each language we must internationalize the field to accommodate this.
- In the Resources app locate the page dialog used by the travel demo website here
- Click Edit file.
- Locate the
tabSearchportion of the dialog definition and set the
i18nproperty to true on the
For the tutorial it's quite easy to just edit the dialog from the Resources app. In a real project you would want to edit the dialog definition located inside your module.
Create the search results pages
The travel demo keeps it's search result page under the meta section of the website here
/travel/meta/search-results. We'll follow the same convention.
- Create a new web page for English search results called
- Create a new web page for German search results called
Open the Travel Home page for editing. Open the page properties dialog for the Travel Home page and set the search results pages for each language.
The search result page must be configured on the home (or root) page of the website. Even though the entire travel demo uses the same page dialog for every page, the search mechanism will look for the configured results pages on the home (root) of the site.
Configure the search results pages
Each search result page needs to be configured for the language it supports using a filter. This is done through the page dialog of each result page in the Additional filters field.
solr-search-results-enfor editing. Open the page properties dialog for the English Results page and set the filter field to
solr-search-results-defor editing. Open the page properties dialog for the German Results page and set the filter field to
Test it out
Try performing some searches. For example search the term "unique" on both the English and German travel sites. You should only find matches in the English site. Likewise try searching the term "beispielprojekt" on both sites. You should not find any matches on the English site.
Sometimes re-indexing can help clear issues. In rare cases rebuilding the entire core seemed to help. This is especially true in you had started this project in earlier versions of the Magnolia Solr modules. Localization support was not added until 5.0.2.