solr介紹
來自官網http://lucene.apache.org/solr/解釋:
Solr is highly reliable, scalable and fault tolerant, providing distributed indexing, replication and load-balanced querying, automated failover and recovery, centralized configuration and more. Solr powers the search and navigation features of many of the world's largest internet sites.
Solr是高可用、可伸縮的和容錯,能提供分布式索引、復制和負載均衡查詢、自動故障轉移和恢復、集中配置並且有更多功能。Solr提供了許多世界上最大的互聯網網站的搜索和導航功能
通俗的說:
Solr是一個企業級搜索應用服務器,對外提供webservice接口,同時提供了多種語言支持的客戶端。
使用solr時,先把數據設置到solr服務器,然后可以通過各種復合查詢進行快速、高效的查詢。如果數據有改動,solr也提供了對應的api去更新相關數據
windows安裝solr
如6.3.0,解壓后:
用cmd 進入solr的bin目錄,使用命令 solr start(為了更方便,可以配置solr的環境變量,配好后可以直接在cmd中使用solr命名)
看到這個界面,說明solr服務啟動成功,端口號為 8983,訪問 http://localhost:8983,會自動跳轉到http://localhost:8983/solr/#/
這里會顯示 solr信息,lucene信息,Java信息,還有一些基礎的solr配置信息
Solr指令
輸入 solr -h 查看solr指令
配置solr
配置核心core
solr create -c mycore -d baisc_configs:-c參數指定定義的核心名稱,-d參數指定配置目錄(baisc_configs為\solr-6.3.0\server\solr\configsets\basic_configs對應的目錄)
執行該命令后,在 \solr-6.3.0\server\solr 目錄下出現一個 對應核心的目錄。
刷新 Solr Admin頁面:http://localhost:8983/,查看core,多了一個 test
也可以在Solr Admin頁面中的 Core Admin中,進行Core管理
在\solr-6.3.0\server\solr\test目錄下有conf和data目錄,分別對應配置和數據。
給core添加數據
solr中的字段,必須先定義好,打開目錄:\solr-6.3.0\server\solr\test\conf,添加一個字段:
<field name="name" type="string" indexed="false" stored="true" required="true" multiValued="false" />
然后重啟solr: solr restart -p 8983
到Solr Admin頁面,選擇core-test-document,在Document(s)中填寫數據:
{ "id":"1", "name":"寶馬" }
點擊submit,返回Status: success,則代表添加數據成功。
多加幾條后,點擊Query,查詢數據:
查詢界面的 q,代表 查詢條件,如輸入:name:"寶馬",再次執行查詢
也可以直接get方式訪問url:http://localhost:8983/solr/test/select?q=name:寶馬