solr學習筆記-入門

solr學習筆記
一、安裝前準備

solr依賴java 8 運行環境,因此咱們先安裝java。若是沒有java環境沒法啓動solr服務,而且會看到以下提示:php

[root@localhost solr-6.1.0]# ./bin/solr start -e cloud -noprompt /*運行solr服務*/
Java not found, or an error was encountered when running java.
A working Java 8 is required to run Solr!
Please install Java 8 or fix JAVA_HOME before running this script.
Command that we tried: 'java -version'
[root@localhost ~]# java -version /*檢測是否已安裝java*/
[root@localhost ~]#  yum install -y java /*安裝java*/

二、下載&安裝&啓動&中止
1.一、下載&安裝:下載安裝包,而後直接解壓到指定目錄便可。
html

[root@localhost ~]# wget http://ftp.meisei-u.ac.jp/mirror/apache/dist/lucene/solr/6.1.0/solr-6.1.0.tgz
[root@localhost ~]# tar zxvf solr-6.1.0.tgz -C /usr/local/
[root@localhost ~]# cd /usr/local/solr-6.1.0
[root@localhost solr-6.1.0]# ls
bin  CHANGES.txt  contrib  dist  docs  example  licenses  LICENSE.txt  LUCENE_CHANGES.txt  NOTICE.txt  README.txt  server
[root@localhost solr-6.1.0]# ./bin/solr -help /*查看solr命令幫助*/
[root@localhost solr-6.1.0]# ./bin/solr status /*查看solr服務啓動狀態*/

1.二、啓動solr服務
[root@localhost solr-6.1.0]# ./bin/solr start -e cloud -noprompt /*啓動solr服務*/
Welcome to the SolrCloud example!
Starting up 2 Solr nodes for your example SolrCloud cluster.
/*省略中間部分*/
SolrCloud example running, please visit: http://localhost:8983/solr /*瀏覽器打開這個url能夠看到solr的運行狀況*/
[root@localhost solr-6.1.0]# ps aux | grep solr /*能夠看到solr服務進程*/
[root@localhost solr-6.1.0]# ./bin/solr start -help /*查看啓動命令幫助*/

1.三、中止solr服務
[root@localhost solr-6.1.0]# ./bin/solr stop -all
[root@localhost solr-6.1.0]# ./bin/solr start -help /*查看中止命令幫助*/

三、生成索引數據
solr使用./bin/post命令生成索引數據。支持多種生成方式:
3.一、指定文件生成索引數據,支持格式:xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted filename.json

3.二、指定目錄生成索引數據
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted ~/docdir

3.三、網絡爬蟲
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted http://lucene.apache.org/solr -recursive 1 -delay 1

3.四、標準輸入/輸出管道
[root@localhost solr-6.1.0]# echo '{commit: {}}' | ./bin/post -c gettingstarted -type application/json -out yes -d

3.五、字符串
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted -type text/csv -out yes -d $'id,value\n1,0.47'

注:文件內容格式能夠參考solr安裝目錄內的/usr/local/solr-6.1.0/example/exampledocs/*下文件。

四、刪除索引數據
咱們能夠指定要刪除記錄的主鍵值來刪除指定記錄,或者在文檔中定義指定記錄的值批量刪除
4.一、刪除主鍵ID值爲SP2514N的記錄,-d參數是能夠是其餘solr支持的格式或文件
[root@localhost solr-6.1.0]# ./bin/post -c gettingstarted -d "<delete><id>SP2514N</id></delete>"

五、搜索
Solr支持多種搜索渠道,如:REST clients, cURL, wget, Chrome POSTMAN等等.理論上支持全部語言。
5.一、CURL方式:
[root@localhost solr-6.1.0]# curl "http://localhost:8983/solr/gettingstarted/select?q=*:*&wt=json&indent=true"
5.二、搜索API經常使用參數說明 5.2.一、參數[q=keyword|field:value|keyword1+keyword2|keyword1+-keyword2]:搜索關鍵字|包含value的字段field|同時包含keyword1和keyword2|包含keyword1,但不包含keyword2。 5.2.二、參數[wt=json]:結果返回格式:json、xml、python、ruby、php、csv等。 5.2.三、參數[start=0]:分頁偏移量,即從第幾條開始。 5.2.四、參數[rows=10]:每頁數量,默認10。 5.2.五、參數[fl=id[,field2,field3,...]]:結果只返回指定的字段,多個用「,」隔開。 5.2.六、參數[indent=false|true]:返回結果個否格式化(縮進)。 5.2.七、參數[fq=field:value]:過濾結果 5.2.八、參數[facet=true|false|on|off]:開始/關閉分組,統計分組數量 5.2.八、參數[facet.field=field]:以field字段分組統計 更多參數說明:https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing
相關文章
相關標籤/搜索