1. 程式人生 > >Solr入門-Solr服務安裝(windows系統)

Solr入門-Solr服務安裝(windows系統)

exist img -s cheng should local zookeepe 進行 存儲

安裝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

Solr入門-Solr服務安裝(windows系統)