BroadleafCommerce官方关于内嵌SOLR的文档翻译

群号:185686402,欢迎访问blog.ebuzz.cn


写这边文章的目的,了解BroadleafCommerce内嵌的SOLR的工作原理,优势劣势,以及适合的使用场景。另外是方便自己查看一些技术点的解释和后续在生产环境中使用SOLR-CLOUD打下基础,最后由于本人非专业翻译,所以语言可能会比较蹩脚,望大家谅解,欢迎入群讨论。
原文出处:官方文档

Embedded Solr

Embedded Solr is the default deploymentoption with Broadleaf for simplicity's sake. Embedded Solr is a mechanism thatallows Solr to be run as a service inside Broadleaf where the index is writtento the local file system, usually a temp directory. This is the flavor of Solrthat is used with Broadleaf's Demo Site. The configuration works well forgetting started or for development environments. However, it is not usually therecommended configuration for environments like production.

嵌入的SOLR是简易开发BLC的一个默认的选项,嵌入的SOLR机制是允许它可以作为了一个内部服务把索引写到本地文件系统,通常是一个临时的目录。这是BLC DEMO SITE的SOLR风味。这种配置有效的带你入门或者开发环境。然而,并不推荐你用这种配置在你的正式环境中。

 

 

How to configure Embedded Solr

Embedded Solr is configured out of the boxwith Broadleaf Commerce. However, it's important to understand how it works andhow to change configurations to allow Solr to use different local directoriesfor configuration and indexing.

如何配置嵌入的SOLR。

嵌入的SOLR被配置成BLC开箱即用的。然而,了解它是如何工作的,并且知道如何通过改变配置允许SOLR使用不同的本地目录作为配置和索引是非常重要的。

 

When the Site(customer facing site as opposed to the Admin) is started, one of the Springconfigurations is the Broadleaf SearchService, with the Spring bean name blSearchService. The default implementation isorg.broadleafcommerce.core.search.service.solr.SolrSearchServiceImpl.

 

当SITE()启动后,其中SPRING配置就是BLC的SearchService,叫blSearchService,默认实现是

org.broadleafcommerce.core.search.service.solr.SolrSearchServiceImpl

Besides beingresponsible for issuing requests to Solr, this class is responsible for thebasic setup of Solr-related dependencies. It has several constructors:

publicSolrSearchServiceImpl(StringsolrServer) throws IOException,ParserConfigurationException, SAXException {

   ...

}

 

除了为SOLR分配请求,这个类也管理SORL相关依赖的基础设置。它有几个构造方法:

publicSolrSearchServiceImpl(StringsolrServer) throws IOException,ParserConfigurationException, SAXException {

   ...

}

 

 

Several other constructors accept Stringsbut delegate back to the above constructor for consistency:

publicSolrSearchServiceImpl(StringsolrServer, String reindexServer)

    throws IOException,ParserConfigurationException, SAXException {

    this(solrServer);

}

publicSolrSearchServiceImpl(StringsolrServer, String reindexServer, String adminServer)

    throws IOException,ParserConfigurationException, SAXException {

    this(solrServer);

}

其他几个构造方法接受字符串,但是最后都会回调上面的构造方法为保持一致性。

 

 

These constructorsactivate the embedded Solr Server. The details can be found by looking at thesingle argument constuctor, above. However, there are a few things tounderstand about this. First, if the String "solrhome" is passed tothe constructor, then then a directory is created in the temp directory,defined by java.io.tmpdir, which is usually the operating system'stemporary directory. That is the case unless the Java System Property tmpdir.solrhome is set. If tmpdir.solrhome is set as a System Property, thenthe value of this will be used instead (assuming the directory has been createdand that the user running the Java process has read and write access to thedirectory). If any value except "solrhome" is passed to theconstructor, then Broadleaf assumes that it is the directory that you wish touse to store the configuration and index data. The system will create theappropriate subdirectories and put the appropriate files in them to run anembedded Solr instance. By default, two Solr cores are created--"primary"and "reindex". This allows Broadleaf to reindex the catalog in abackground thread to an offline or reindex core,while allowing the online orprimary core tocontinue to serve customer requests. When indexing is complete, Broadleaf swapsthe cores, making the newly reindexed core primary and the former primary coreoffline to be used next time reindexing occurs.

As noted, Broadleaf is configuredout-of-the-box to use embedded Solr. Here is how the configuration works:

这些构造方法激活了嵌入的SORL服务。具体详情可以通过看上面的那个单个参数的构造方法。然而,这有一些关于它的事情需要理解。首先,如果字符串"solrhome"被传给那个构造方法,那时当在一个临时目录里建立一个目录的时候,就会被定义为java.io.tmpdir  它通常是操作系统的临时目录。换句话说就是要设置JAVA 系统属性tmpdir.solrhome如果tmpdir.solrhome被设置为一个系统属性的话,那么就会用它的值作为取代(假设那个目录已经被创建了,并且使用者所运行的JAVA线程拥有该目录的读和写的权限)。如果除了"solrhome"以外的值被传给构造方法的话,那么BLC就会假设那个目录就是你想用来存储配置和索引数据的目录。系统将会创建适当的子目录和放置适当的文件在目录里面给运行嵌入的SOLR实例。默认情况,两个SOLR的核心块将被创建,他们是--"primary" and"reindex".这将允许BLC对目录分类在后台的线程里对离线的或者是重建索引的数据块重建索引,与此同时允许在线的primary core继续为用户的请求提供服务。当索引完成后,BLC交换核心块,让最新的重建索引块变成主要的核心快,并且刚才的为用户提供服务的主索引块下线以便当下一次重建索引发生的时候。注意,BLC被配置为有创造性的使用嵌入的SOLR。这就是这些配置如何工作的。

 

 

In site/src/main/webapp/WEB-INF, there is a file called applicationContext.xml. This contains the Solr configuration forSite (remember that Admin does not use Solr by default in the CommunityEdition). There is a Spring Bean, defined as solrEmbedded, which is simply aString:

<beanid="solrEmbedded"class="java.lang.String">

    <constructor-argvalue="solrhome"/>

</bean>

在目录site/src/main/webapp/WEB-INF里,有一个文件是 applicationContext.xml.它包含了SITE的SOLR配置(注意,社区版本的ADMIN作为默认,是不使用SOLR的)。有一个 Spring Bean, 定义为 solrEmbedded, 那是个简单的String:

<beanid="solrEmbedded"class="java.lang.String">

    <constructor-argvalue="solrhome"/>

</bean>

 

 

 

As you can see,the value of this String is "solrhome". There isalso a Bean called "blSearchService". This defines the actual searchservice, which must implement the interface org.broadleafcommerce.core.search.service.SearchService. Here is the default configuration:

<beanid="blSearchService"class="org.broadleafcommerce.core.search.service.solr.SolrSearchServiceImpl">

    <constructor-argname="solrServer"ref="${solr.source.primary}"/>

    <constructor-argname="reindexServer"ref="${solr.source.reindex}"/>

    <constructor-argname="adminServer"ref="${solr.source.admin}"/>

</bean>

如你所看到的,那个字符串的值就是"solrhome".这还有一个Bean叫做"blSearchService".这就是定义那个必须实现接口org.broadleafcommerce.core.search.service.SearchService.的搜索服务。下面是默认的配置

<beanid="blSearchService"class="org.broadleafcommerce.core.search.service.solr.SolrSearchServiceImpl">

    <constructor-argname="solrServer"ref="${solr.source.primary}"/>

    <constructor-argname="reindexServer"ref="${solr.source.reindex}"/>

    <constructor-argname="adminServer"ref="${solr.source.admin}"/>

</bean>

 

 

Notice theproperty substitutions. You can replace the property substitutions with aconcrete Spring Bean name. For simplicity, we store the bean names inproperties files so you can use different implementations in differentenvironments. Insite/src/main/resources/runtime-properties/common.properties, you'll notice the settings:

solr.source.primary=solrEmbedded

solr.source.reindex=solrEmbedded

solr.source.admin=solrEmbedded

注意替换属性。你可以用一个实际的SPRING BEAN替换属性值。为了方便起见,我们把BEAN的名称存储到了属性文件里,以便你可以在不同的环境中使用不同的实现。在site/src/main/resources/runtime-properties/common.properties,你会注意到这些配置:

solr.source.primary=solrEmbedded

solr.source.reindex=solrEmbedded

solr.source.admin=solrEmbedded

 

 

This causes Springto replace the property placeholders with the Spring Bean, solrEmbedded, whose value is "solrhome". As described, above, this causesthe constructor which accepts a single String to be invoked, which starts Solr inembedded mode using a temp director as a local data store.

这样SPRING就会用值为"solrhome"的SPRING BEAN- solrEmbedded来替换那些属性占位符。如上面所描述的,以嵌入的方式启动SOLR来作为本地数据存储的时候,单个字符串的构造方法被调用,

 

Using Embedded Solr in Production

It is generally recommended to use adifferent deployment approach in production for Solr than using the embeddedapproach. There are a number of reasons for this:

使用嵌入的SOLR在生产环境中

通常来说,推荐在生产环境中使用一个不同的部署策略会好过使用嵌入策略。这有不少原因如下:

·        You have more control over management and monitoring ofSolr in an environment using SolrCloud or a Stand-Alone Solr Server

·        You can query Solr from a browser when using SolrCloud orStand-Alone Solr, which you cannot do with embedded Solr (helps withtroubleshooting)

·        Embedded Solr does not scale as well for large catalogsor very high traffic

·        With Embedded Solr, if you have a cluster of customerfacing Broadleaf instances, each node needs to reindex when there are changes,as opposed to reindexing a central Solr environment

·        在一个使用SOLRCLOUD的环境中或者是一个单点的SOLR服务中你会对管理和监控SOLR有更多的控制支配权。

·        在一个使用SOLRCLOUD的环境中或者是一个单点的SOLR服务中你可以通过浏览器查询数据,但你不能在嵌入的环境中使用(帮你排查问题)

·        嵌入的SOLR不能处理大量的分类目录或者是高访问量。

·        如果你的BLC是集群的方式,并且使用了嵌入的SOLR,那么每个节点有变化的时候需要重建索引,对比一个SOLR中心环境是截然不同的。

However, if your catalog is relativelysmall (several thousand products or less) and you don't have complex reindexrequirements across multiple nodes, you may be OK using Embedded Solr inproduction. As a general rule, though, we recommend using SolrCloud or aStand-Alone Solr server for more mission critical needs.

然后,如果你的分类目录相对来说比较少(几千个产品甚至更少的话)那么你就没有复杂的重建索引的需求在多个节点中,那么你使用嵌入的SOLR在你生产环境中还是很OK的。一般情况下,我们推荐使用SOLRCLOUD或者是一个单点的SOLR服务来处理更多关键需求的任务。

Upgrading

Something to noteabout upgrading Broadleaf: If you are using Embedded Solr locally or in anotherenvironment and you upgrade to the latest version of Broadleaf, there aresometimes incompatibilities because we do not recreate directories orartifacts. The easiest way to deal with this is to delete or prune thedirectories and files in your solrhome directory, wherever that is on thefile system. You should only need to do this once and only if you are usingembedded Solr after a major upgrade if you see an exception dealing withincompatbilities with Solr or Lucene.

 

升级

升级BLC有些事情需要注意:如果你使用本地嵌入的SOLR或者在另外一个环境中并且你升级到了最新版本的BLC,这有一些事情是不相容的,因为对于目录或者是之前的事物,我们将不会重新创建。最简单的方法就是删除或者是删去多余的文件系统中的目录和文件。这事你应该只需要做一次就行,仅仅是你使用的是嵌入的SOLR在重要升级后如果发生了异常处理不相容的时候。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值