Solr入门-Solr服务安装(windows系统)

安装Solr

首先保证已经正确安装了Java

下载Solr,当前最新版6.1.0

Solr各个版本下载地址

Solr从6.0之后需要Java1.8所以如果使用Solr6.0及其以上版本,请确保Java版本在1.8之上

将Solr下载之后解压在电脑的某个目录,我解压到了D盘根目录下

启动Solr

启动Solr(windws版,以下都是windows下的)

进入solr的解压目录

cd bin
solr.cmd start

Solr启动成功!

管理控制台地址为

http://localhost:8983/solr/

第一次使用的时候提醒No cores available

什么是core

先来看一段官方说明。

In Solr, the term is used to refer to a single index and associated transaction log and configuration files core
(including the and Schema files, among others). Your Solr installation can have multiple solrconfig.xml
cores if needed, which allows you to index data with different structures in the same server, and maintain more
control over how your data is presented to different audiences. In SolrCloud mode you will be more familiar with
Behind the scenes a collection consists of one or more cores. the term collection.

Cores can be created using script or as part of SolrCloud collection creation using the APIs. C bin/solr ore-spe
cific properties (such as the directories to use for the indexes or configuration files, the core name, and other
options) are defined in a core.properties file. Any core.properties file in any directory of your Solr
installation (or in a directory under where solr_home is defined) will be found by Solr and the defined properties
will be used for the core named in the file.

主要的意思是which allows you to index data with different structures in the same server
允许用户以不同的数据结构来对数据进行索引。

可以使用

bin/solr create -c <name>

来创建core

运行示例数据

这里我们使用官方给的示例。

先停掉solr
停掉solr必须指定端口号,也可以使用 -all来停掉所有的solr服务

solr.cmd stop -all

使用示例core启动solr(没有特殊说明所处的目录为solr解压路径\bin下)

solr.cmd -e techproducts

我们来看一下上面的命令solr都做了什么操作

  1. 创建目录在example下创建了techproducts\solr目录
  2. 启动solr使用-s指定了solr.home
  3. 创建core
  4. 索引
  5. 上传文件
    等操作

其中启动命令使用了-s 我们来看一下-s的含义

Sets the solr.solr.home system
property; Solr will create core
directories under this directory. This
allows you to run multiple Solr instances
on the same host while reusing the
same server directory set using the -d
parameter. If set, the specified directory
should contain a solr.xml file, unless
solr.xml exists in ZooKeeper. The
default value is . server/solr
This parameter is ignored when running
examples (-e), as the solr.solr.home
depends on which example is run.

我们看一下原始的solr下example目录

执行之后example目录

techproducts下面有logs和solr目录

执行post命令提交了一下文件

再回控制台

在此进入

http://localhost:8983/solr/#/

我们在core admin中就可以看到创建的techproducts了

Solr is built to find documents that match queries. Solr’s schema provides an idea of how content is structured
(more on the schema ), but without documents there is nothing to find. Solr needs input before it can do later
much.

solr是用来查找关键字匹配的文档的。solr的schema决定了内容的结构,没有文档,就无从查询。

刚才我们使用的-e启动命令已经将示例文档提交了。

接下来我们来查询(依然以官方的示例,查询video)

http://localhost:8983/solr/techproducts/select?q=video

结果如下

还有很多详细的查询可以参考官方文档

快速预览

下图简单描述了Solr如何集成到应用中

In the scenario above, Solr runs along side other server applications. For example, an online store application
would provide a user interface, a shopping cart, and a way to make purchases for end users; while an inventory
management application would allow store employees to edit product information. The product metadata would
be kept in some kind of database, as well as in Solr.

Solr使用步骤如下

  1. 定义schema,schema告诉Solr文档如何被索引,在在线商店示例中,schema可以用来定义商品名称,描述,价格,制造商等字段。
  2. 部署Solr
  3. 将solr文档提供给用来来检索
  4. 在应用中暴露搜索接口

更进一步

You already have some idea of Solr’s schema. This section describes Solr’s home directory and other
configuration options.
When Solr runs in an application server, it needs access to a home directory. The home directory contains
important configuration information and is the place where Solr will store its index. The layout of the home
directory will look a little different when you are running Solr in standalone mode vs when you are running in
SolrCloud mode.
The crucial parts of the Solr home directory are shown in these examples:

Solr的主目录

当Solr在应用服务器上运行的时候,它需要访问主目录,主目录包含重要的配置信息,也是Solr存储索引的地方。主目录的结构如下

最主要的文件如下
solr.xml
为Solr实例指定配置
core.properties
定义每一个core的配置,比如名字,所在的core,schema的位置和其他参数

转http://blog.csdn.net/frankcheng5143/article/details/52291176