apache solr

tech2022-12-24  76

apache solr

In this tutorial, we will look at what Apache Solr is and how it works. We are going to look at some powerful Solr features and how it is different than MySQL. We will see benefits of integrating Solr into our WordPress website. We will also cover how to install WordPress Solr plugin and also how to host Apache Solr. Finally, we will wrap by looking at some popular websites using Solr.

在本教程中,我们将了解什么是Apache Solr及其工作方式。 我们将研究一些强大的Solr功能以及它与MySQL的不同之处。 我们将看到将Solr集成到我们的WordPress网站中的好处。 我们还将介绍如何安装WordPress Solr插件以及如何托管Apache Solr。 最后,我们将介绍一些使用Solr的流行网站。

This tutorial is for both WordPress developers and users. If you’re not a developer and using WordPress just to setup websites in that case you should only care about Solr benefits and setting up. However, if you are a WordPress developer then learning the internals of Solr and technical implementations will help you.

本教程适用于WordPress开发人员和用户。 如果您不是开发人员,而仅使用WordPress来建立网站,那么您应该只关心Solr的好处和设置。 但是,如果您是WordPress开发人员,那么学习Solr的内部知识和技术实现将为您提供帮助。

什么是Apache Solr? (What Is Apache Solr?)

Apache Solr is an Open Source, enterprise search server. It stores information in such a way that searching is very fast. In a nutshell, it’s also a storage system like SQL and NoSQL.

Apache Solr是一个开源的企业搜索服务器。 它以快速搜索的方式存储信息。 简而言之,它还是像SQL和NoSQL这样的存储系统。

Solr is written in Java and uses the Lucene search library for its core functionality. You don’t need to know Java to work with Solr.

Solr用Java编写,并使用Lucene搜索库实现其核心功能。 您不需要了解Java即可与Solr一起使用。

与MySQL有何不同? (How It Is Different than MySQL?)

If you’re new to Solr, the best way to understand the internals of Solr is to compare it with MySQL.

如果您是Solr的新手,那么了解Solr内部的最佳方法是将它与MySQL进行比较。

MySQL stores information in the form of tables and rows. Whereas Solr stores information in form of schema and XML documents. Schema defines the structure of the documents.

MySQL以表和行的形式存储信息。 而Solr以架构和XML文档的形式存储信息。 模式定义了文档的结构。 You can have multiple tables in MySQL, similarly you can have multiple schemas in Solr.

在MySQL中可以有多个表,类似地,在Solr中可以有多个模式。 Columns in a table define the structure of the table similarly in Solr fields define the structure of the schema.

表中的列定义表的结构类似,在Solr字段中定义表的结构。 In MySQL you store in the form of rows whereas in Solr you store in the form of documents.

在MySQL中,您以行的形式存储,而在Solr中,您以文档的形式存储。

In MySQL when columns are indexed the rows get arranged in a tree like structure. Whereas in Solr when a field is indexed it is arranged into a inverted index data structure.

在MySQL中,当索引列时,行以树状结构排列。 而在Solr中,当对字段进行索引时,会将其安排为反向索引数据结构。

是什么使搜索速度更快? (What Makes It Fast for Search?)

Solr uses inverted index data structure to search for words in documents and intersects the final result. No other storage system uses this kind of data structure.

Solr使用倒排索引数据结构搜索文档中的单词并与最终结果相交。 没有其他存储系统使用这种数据结构。

Solr的其他功能是什么? (What Are Other Features of Solr?)

Solr offers many other features like spell correction, faceting, highlighting, result grouping, auto completion etc. Implementing these features into your WordPress site will make it stand out from the crowd. These features provide better user experience and a new way to access content on your WordPress site.

Solr提供了许多其他功能,例如拼写校正,刻面,突出显示,结果分组,自动完成等。在您的WordPress网站中实现这些功能将使其在人群中脱颖而出。 这些功能提供了更好的用户体验,并提供了一种新的方式来访问WordPress网站上的内容。

为什么您应该将WordPress与Solr集成? (Why You Should Integrate WordPress with Solr?)

When the number of posts on your site increases, MySQL starts to perform slow when users search on your site. This is because MySQL loops through every post and uses regular expressions to match search terms. This is a very CPU expensive task. Sometimes users get request timeout errors due to PHP script execution time limit. If there are 10,000 posts then for every search query MySQL is going to hit the file system 10,000 times which is a very expansive task and will slow down your website.

当您网站上的帖子数量增加时,当用户在您的网站上搜索时,MySQL开始执行缓慢。 这是因为MySQL遍历每个帖子,并使用正则表达式匹配搜索词。 这是一项非常耗费CPU的任务。 有时,由于PHP脚本执行时间限制,用户会收到请求超时错误。 如果有10,000个帖子,则对于每个搜索查询,MySQL都会命中文件系统10,000次,这是一项非常艰巨的任务,并且会降低您的网站速度。

Whereas Solr can search 10,000 documents in just a couple of seconds. If you have a medium size blog, then a single Solr instance is enough to power all posts.

而Solr可以在几秒钟内搜索10,000个文档。 如果您有一个中等大小的博客,那么一个Solr实例足以支持所有帖子。

如何将Solr与WordPress集成? (How to Integrate Solr with WordPress?)

To integrate Solr in WordPress you need two things: Solr plugin and Solr hosting. The basic job of a Solr plugin is to intercept the WordPress search requests and provide results from Solr server instead of WordPress naturally fetching the result from MySQL.

要将Solr集成到WordPress中,您需要两件事:Solr插件和Solr托管。 Solr插件的基本工作是拦截WordPress搜索请求并从Solr服务器提供结果,而不是WordPress自然从MySQL获取结果。

Solr plugins also provide features like auto suggestion, spell correction, highlighting search terms, faceting on tags and categories etc. However, to implement these extra features the WordPress theme must be compatible with APIs of that particular Solr plugin. Some plugins allow you to add a custom search.php file to the theme and then the plugin intercepts the template hierarchy and executes the custom search file which has all these advanced features.

Solr插件还提供自动建议,拼写校正,突出显示搜索词,标签和类别刻面等功能。但是,要实现这些额外功能,WordPress主题必须与该特定Solr插件的API兼容。 一些插件允许您将自定义search.php文件添加到主题,然后插件拦截模板层次结构并执行具有所有这些高级功能的自定义搜索文件。

Solr plugin only makes copy of posts and pages into Solr server. Solr is used only during search requests, for example http://example.com/?s=search_query. For all other operations and requests WordPress follows the normal flow, for example it uses MySQL.

Solr插件仅将帖子和页面的副本复制到Solr服务器中。 Solr仅在搜索请求期间使用,例如http://example.com/?s=search_query 。 对于所有其他操作和请求,WordPress遵循正常流程,例如,它使用MySQL。

WordPress的Solr插件 (Solr Plugins for WordPress)

There are two popular WordPress plugins to integrate Solr: Advanced Search by My Solr Server and WPSOLR Search Engine.

有两个流行的WordPress插件可集成Solr: My Solr Server的高级搜索和WPSOLR Search Engine 。

In this tutorial, I will be using WPSOLR Search Engine plugin to integrate Solr into WordPress.

在本教程中,我将使用WPSOLR Search Engine插件将Solr集成到WordPress中。

Solr托管 (Solr Hosting)

You can host Solr on a dedicated server, but this requires some maintenance. Therefore, Solr cloud hosting services are preferred. There are two popular Solr cloud hosting services: OpenSolr and GotoSolr.

您可以将Solr托管在专用服务器上,但这需要进行一些维护。 因此,首选Solr云托管服务。 有两种流行的Solr云托管服务: OpenSolr和GotoSolr 。

In this tutorial, I will use GotoSolr to host our Solr server.

在本教程中,我将使用GotoSolr托管我们的Solr服务器。

安装WPSOLR搜索引擎插件 (Installing the WPSOLR Search Engine Plugin)

Navigate to ‘Plugins’ and then to ‘Add New’ in WordPress Admin Dashboard. Then search for ‘WPSOLR Search Engine’. You will have the plugin listed on top. Install and activate it.

导航到“插件”,然后在WordPress管理员仪表板中选择“添加新项”。 然后搜索“ WPSOLR搜索引擎”。 您将在顶部列出该插件。 安装并激活它。

在GotoSolr上托管Solr (Hosting Solr on GotoSolr)

Here are the steps to host Solr on GotoSolr:

以下是在GotoSolr上托管Solr的步骤:

Create a new GotoSolr account. The first month is free, so it’s good to try it out with your WordPress site first. This way, there’s no risk if you don’t like it.

创建一个新的GotoSolr帐户 。 第一个月是免费的,因此最好先在WordPress网站上试用。 这样,如果您不喜欢它,就不会有风险。

Once you have created an account you will have access to the dashboard.

创建帐户后,您将可以访问仪表板。

An index is a collection of schema, documents and their configurations. You need to create an Index. Click on the + button on the Indexes tab.

索引是模式,文档及其配置的集合。 您需要创建一个索引。 单击“索引”选项卡上的+按钮。

Now you need to download the configuration files of WPSOLR plugin for your Index and upload them.

现在,您需要为索引下载 WPSOLR插件的配置文件并上传它们。

Click on tab “schema.xml” and use the Upload button to upload the previously downloaded schema.xml file. Then click the save button.

单击选项卡“ schema.xml”,然后使用“上载”按钮上载先前下载的schema.xml文件。 然后单击保存按钮。 Click on tab ‘Access keys’, create a new security key/secret by clicking on ‘Add a new key/secret’. Later, you’ll use these keys to let the plugin (and it only) connect to your Solr index, by setting it’s values in the fields user/password used in all Solr https basic authentication calls.

单击选项卡“访问密钥”,通过单击“添加新密钥/秘密”来创建新的安全密钥/秘密。 稍后,通过在所有Solr https基本身份验证调用中使用的用户/密码字段中设置其值,您将使用这些密钥使插件(仅插件)连接至Solr索引。 Click on tab “URL of this index”. Paste the URL of your index in a document for later. Notice how complex the URL is, and that it’s using HTTPS. This, plus your access keys, ensures your index is secured.

单击选项卡“此索引的URL”。 将索引的URL粘贴到文档中以备后用。 请注意,URL非常复杂,并且使用的是HTTPS。 这加上访问密钥可确保索引的安全。

配置WPSOLR搜索引擎并将其连接到GotoSolr服务器 (Configuring and Connecting WPSOLR Search Engine to GotoSolr Server)

Here are the steps to connect to the GotoSolr server:

以下是连接到GotoSolr服务器的步骤:

Open the WPSOLR settings page on WordPress administration dashboard. Click on ‘I uploaded my 2 compatible configuration files to my Solr core’ button.

打开WordPress管理信息中心上的WPSOLR设置页面。 单击“我将2个兼容的配置文件上传到我的Solr核心”按钮。

Now select “Cloud Hosting” radio button. And then copy server access information from GotoSolr dashboard.

现在,选择“ Cloud Hosting”单选按钮。 然后从GotoSolr仪表板复制服务器访问信息。

Click on ‘Check Solr Status Then Save’. This will validate your settings, and will test the connexion to your Solr index. If any error, you will be warned with a message. If (and only if) the connection is validated, then your settings will be saved.

单击“检查Solr状态,然后保存”。 这将验证您的设置,并测试与Solr索引的连接。 如果有任何错误,将会警告您一条消息。 如果(并且仅当)连接通过验证,那么您的设置将被保存。

Under ‘Solr Options’ tab select what you want to be indexed and also what extra features you need.

在“ Solr选项”标签下,选择要索引的内容以及所需的其他功能。

Now go to ‘Solr Operations’ tab and click on ‘Load data’ button which will copy all your WordPress content into Solr server.

现在转到“ Solr操作”选项卡,然后单击“加载数据”按钮,这会将您所有的WordPress内容复制到Solr服务器中。 From this point forward, if you make any changes or create new pages and posts then this plugin will automatically make a copy of it in the Solr index.

从现在开始,如果您进行任何更改或创建新的页面和帖子,那么此插件将自动在Solr索引中复制它。

This plugin overrides the WordPress search form to implement auto completion feature. If you are using this plugin then you don’t need to create a custom search.php file because this plugin creates it automatically. Here are some screenshots showing auto completion and other features of Solr on a sample WordPress site.

此插件将覆盖WordPress搜索表单以实现自动完成功能。 如果您使用的是此插件,则无需创建自定义search.php文件,因为此插件会自动创建它。 以下是一些屏幕快照,显示了示例WordPress网站上的Solr的自动完成功能和其他功能。

使用Solr的网站 (Websites Using Solr)

There are a lot of popular websites which are using Solr to power their search. Here is just a short list:

有许多受欢迎的网站都在使用Solr进行搜索。 这只是一个简短的清单:

DuckDuckGo uses Solr to provide spell checking, storing webpages etc.

DuckDuckGo使用Solr提供拼写检查,存储网页等。 Drupal.org uses Solr to power all their site features.

Drupal.org使用Solr来支持其所有站点功能。 Last.fm uses Solr for all its search features.

Last.fm使用Solr进行所有搜索。 Some other sites include AOL, Yahoo, Instagram, Yellow Pages etc.

其他一些网站包括AOL,Yahoo,Instagram,黄页等。

最后的想法 (Final Thoughts)

If you’re a developer then you will definitely benefit from learning Solr. If you are a WordPress user, then integrating Solr will surely help you provide a powerful search engine.

如果您是一名开发人员,那么您一定会从学习Solr中受益。 如果您是WordPress用户,那么集成Solr一定会帮助您提供强大的搜索引擎。

Here are some resources where you can get some further information on Apache Solr:

以下是一些资源,您可以在其中获得有关Apache Solr的更多信息:

Solr in 5 minutes: This online resource covers the fundamentals of Solr and will quickly bring you up-to-speed.

5分钟内完成Solr :此在线资源涵盖了Solr的基础知识,并将Swift使您快速入门。

Solr in Action: If you prefer learning through a then this is a great choice.

Solr in Action :如果您喜欢通过a进行学习,那么这是一个不错的选择。

Learning Apache Solr with Big Data and Cloud Computing: This is my own personal video course, it’s a great way to get started with Solr.

通过大数据和云计算学习Apache Solr :这是我自己的个人视频课程,是Solr入门的好方法。

As you’ve seen, it was simple enough to implement Solr in WordPress without too much fuss. Please share your experiences and any Solr and WordPress implementations you’ve come across below.

如您所见,在WordPress中实现Solr足够简单,而不必大惊小怪。 请分享您的经验以及您在下面遇到的所有Solr和WordPress实现。

翻译自: https://www.sitepoint.com/enterprise-search-with-apache-solr-and-wordpress/

apache solr

相关资源:php-docker-boilerplate:适用于Symfony,Wordpress,Joomla或任何其他PHP项目(NGINX,Apache HTTPd,PHP-FPM,MySQL,Solr,Elasticsearch,Redis,FTP)PHP Docker Boilerplate-源码
最新回复(0)