MAGENTO - APACHE SOLR INTEGRATION - PART II (SETUP)

Tue, 03/01/2011 - 18:30

Continuing with the short series about integrating Magento with Apache Solr (started in this post), we'll now see how to set up and put Solr to work together with Magento.

Installing Solr

Integration with Solr has been available since version 1.8 Enterprise of Magento. For now, this is only available for the Enterprise version, not for the Community version.
First thing to do is to download Apache Solr. Grab it from here and extract the file (a typical location - for Linux - would be /usr/local/share/).

Note: to be able to run Solr, you will need Java installed in your server. I'm assuming you already have that. If you don't, just google how to do it, it is everywhere...

Once Solr is downloaded and extracted, we can test if it runs, just go to [solr-path]/example, and type the following in a terminal:

After executing that line, the terminal should start spitting information similar to this:

What's this? This is Solr running inside of Jetty. It comes that way when you download it. You can make it run in other servlets containers (such as Tomcat), but that is outside of the scope of this post. And, hey, Jetty is as cool as Tomcat, okay? :)

This terminal must be kept open while we use Solr. Of course that, in your production environment, you wouldn' t start Solr this way, but will make it automatically available each time the server starts. Take a look here for more info on how to do that.

The last verification to ensure that Solr is running in your machine: go tolocalhost:8983/solr in your browser. You should get this:

Like it says: Welcome!

Configuring Solr for Magento

Great, Solr is working. Now, what do we need to do to make it work with Magento? One of the keys when working with Apache Solr, is defining the right XML config files. The two basic files are:

  • solrconfig.xml: contains most of the parameters for configuring Solr itself.
  • schema.xml: contains all of the details about which fields your site is using, how these fields should be added to the index, and how they should be returned for queries.

These files need to configured according to the job we want Solr do to. Fortunately, the Magento team has already prepared them for us. The only thing we need to do is to copy the Solr conf directory from our Magento Enterprise installation (remember, 1.8 or higher), and replace the original Solrconf directory with it.

In Magento, the folder is located in: [magento-instance-root]/lib/Apache/Solr/conf.
In Solr, the folder is located in [Solr-instance-root]/example/solr/conf.

The trick is just to copy the directory from Magento, and replace the one in Solr. That's it! If you look closely, you'll see that the directory contains not just these two files, but also a bunch of other files, most of them called "protwords_??.txt", or "spellings_??.txt" (replace the ?? for two digit languages codes, such as EN, ES, etc). These are files Solr uses to handle searches in specific languages, and allow you to do a lot of fine tuning in your searches. The Magento config, out of the box, comes with the settings to use many different languages with Solr. 

After replacing the directory, stop Solr (if it was still running) by clicking CTRL + C in the terminal. Then, start it again (java -jar start.jar). This time, you'll see some new stuff:

Those are all good signs. Solr has got its new configuration, and now it's ready to dialogue with Magento.

Enabling Solr In Magento

Solr is ready, it knows about Magento's dialects and tastes. It is ready and eager to work with Magento, but still Magento isn't aware of Solr's existence! Lets change all that and make them good friends.
That is done in Magento admin site. Go to the System menu, then theConfiguration option. In the options in the left panel, click on Catalog. And finally, in the options that appear in the central panel, choose Catalog Search. You'll get this screen:

Here, we can tell Magento to use Solr, by selecting it in the Search Engine dropdown. Once we do that, the options change to this:

The configuration is very simple. Just provide the right info about Solr's server, port, and (if needed) authentication information. We are running it in the same machine as Magento, that's why we left the default options selected (localhost, port 8983). Running Solr in a dedicated server could be a very good idea if your site has lots of traffic.

Now, let's click on that colorful Test Connection button:

Good stuff! We have now Magento relying on Solr, and Solr ready for Magento. We are just one step away from offering a much better search experience to our customers.

Indexing Magento information in Solr

The data must be sent to Solr so it work its magic. That is very simple! We just need to recreate the Magento indexes in the usual way. Go to SystemIndex Management, and recreate them. 
In the Solr console, you'll see a lot of activity while the reindexing goes, with things like this:

It is not crucial to understand what Solr is saying here, but it is reassuring to see that there is movement. That's the signal that the information is being sent to Solr.
Go and grab a cup of coffee while Magento and Solr share the info.

Checking stuff in the Front End

Now, go to your store page, and start searching using Solr. If your catalog is very large, you should notice the performance improvement right away. And you will also have new features available (assuming you enabled them in the search configuration earlier). For example, this is a screenshot of theSuggestions feature:

Out of the box, you get the following features working with Magento:

  • The Product search
  • The Navigation search (if you click "Furniture", Solr can return the products in this category).
  • The Faceted Search
  • The Suggestions
  • Search Recommendations (you can associate terms to another terms. Good for a "You may also like" feature for your customers).

Oddly, it seems that the search autocomplete is not going through Solr. I guess the Magento team could not implement that on time, but I imagine that will be coming in the near future (can anyone on the Magento team confirm this?)

Hoping this has been helpful!

Coming up in this series, we'll publish how to index custom information in Solr from Magento, and how to create an Ajax UI to allow the users to search that info. Stay tuned!

Managing Partner
Aldo works as a general mentor for the development teams, keeping in direct contact with programming and design.

MAGENTO - APACHE SOLR INTEGRATION - PART II (SETUP)的更多相关文章

  1. Apache Solr vs Elasticsearch

    http://solr-vs-elasticsearch.com/ Apache Solr vs Elasticsearch The Feature Smackdown API Feature Sol ...

  2. 05 Apache Solr: 管理员界面(Admin UI)

         为了方便管理员和工程师调整Solr的配置和访问在线文档和其他的帮助,Solr提供了一个Web界面去查看Solr的配置详情,运行查询语句和分析文档字段.这个界面在第三篇里面提到过就是管理员界面 ...

  3. 03 Apache Solr: 安装和运行

         前面介绍了Solr在项目中的使用和构建高度可用.高度可扩展的Solr服务器的一些想法.但是光说不练假把式,现在开始,把Solr运行起来继续深入了解吧! 安装 安装JAVA Apache So ...

  4. 02 Apache Solr: 概览 Solr在信息系统架构中的位置

    概述:      Apache Solr是一个用JAVA语言构建在Apache Lucene项目上的开源的企业级搜索平台.主要特性包含:全文搜索.命中高亮.片段式搜索.实时索引.动态集群.数据库集成. ...

  5. 01 Apache Solr:提升检索体验 为什么是Solr

    背景:      最近开发一个大型的仓储管理平台项目,项目的前身是无数个版本的历史悠久的基于CS模式的Windows桌面程序.然后对于每一个客户,我们可能需要为之定制比较个性化的特殊功能.于是,有一个 ...

  6. Apache Solr查询语法(转)

    查询参数 常用: q - 查询字符串,必须的. fl - 指定返回那些字段内容,用逗号或空格分隔多个. start - 返回第一条记录在完整找到结果中的偏移位置,0开始,一般分页用. rows - 指 ...

  7. Apache Solr查询语法

    常用: q - 查询字符串,必须的. fl - 指定返回那些字段内容,用逗号或空格分隔多个. start - 返回第一条记录在完整找到结果中的偏移位置,0开始,一般分页用. rows - 指定返回结果 ...

  8. 使用 PHP 和 Apache Solr 实现企业搜索

    原文链接:http://www.ibm.com/developerworks/cn/opensource/os-php-apachesolr/   http://blog.csdn.net/hzcyc ...

  9. org.apache.solr.common.util.ContentStream.java及其实现类

    org.apache.solr.common.util.ContentStream.java 主要是获取文件,URL,字节数组,字符串等的数据流.主要方法又InputStream getStream( ...

随机推荐

  1. 【.NET实战教程】北风网基于ASP.NET多层架构下的企业级进销存软件全程培训

    .Net进销存系统详细课程大纲(开发工具采用VS2008+sqlsever2005) [小编提醒:现在学习的话,可以使用vs2012+sql 2008 学习的是思路,教学环境不一定要一模一样]1.项目 ...

  2. ie与火狐中常见的一些兼容问题

    1. document.form.item 问题 (1)现有问题: 现有代码中存在许多 document.formName.item("itemName") 这样的语句,不能在Fi ...

  3. title与alt的区别

    html中的title属性和alt属性让人有些混淆. 以前不知道有title这个属性,第一次用到它时,就和alt产生了混淆.一位朋友告诉我说,alt是图片img标签里用的,title是超链接里用的, ...

  4. sql server 排名函数:DENSE_RANK

    一.需求 之前sql server 的排名函数用得最多的应该是RoW_NUMBER()了,我通常用ROW_NUMBER() + CTE 来实现分页:今天逛园,看到另一个内置排名函数还不错,自己顺便想了 ...

  5. java中文文档官方下载

    一直在寻找它,今天无意之间终于发现它了! http://download.oracle.com/technetwork/java/javase/6/docs/zh/api/overview-summa ...

  6. Java链栈

    package com.lxm.customDataStructure; public class LinkStack<T>{ class Node<T>{ T data; N ...

  7. Warning: in_array() expects parameter 2 to be array, string given in D:\wamp\www\suiji.php on line 26

    可参考上篇文章  链接 PHP数组简写模式 同样是PHP版本问题:in_array()函数 第二个参数应该为数组 但是 lnmp下,PHP5.3不报错,wamp下PHP5.5报以下错误: echo & ...

  8. 理解 HTTPS 的工作原理

    目标读者:理解HTTP协议,对称和非对称加密,想要了解HTTPS协议的工作原理. 读完本文,你能明白 什么是HTTPS,TLS(SSL),TLS和HTTPS是什么关系? 什么是证书和数字签名,它们是如 ...

  9. mysql返回最后一列数据

    获取MySQL的表中每个userid最后一条记录的方法,并且针对userid不唯一的情况,需要的朋友可以参考下 表结构 CREATE TABLE `t1` ( `userid` int(11) DEF ...

  10. 修改Firefox的User-Agent,伪装修改秘籍

    火狐浏览器修改userAgent的办法一: 在火狐浏览器地址栏输入"about:config",按下回车进入设置菜单. 找到"general.useragent.over ...