玩轉(zhuǎn)Apache Solr 6.5.1

以下都是基于linux環(huán)境
參考鏈接:http://lucene.apache.org/solr/quickstart.html

目錄:
  1. solr 基本命令總結(jié)
  2. solr 命令參數(shù)詳解
  3. solr 查詢語法詳解
  4. solr schema配置詳解

1. solr基本命令總結(jié):


進(jìn)入solr解壓后的文件夾

cd solr-6.5.1/

啟動solr service在8080端口

bin/solr start -p 8080(端口號) 

停止所有solr service

bin/solr stop -all     

重新啟動solr service在8080端口

bin/solr restart -p 8080      

啟動solrcloud示例cloud;對應(yīng)的core示例是gettingstarted

bin/solr start -e cloud        

啟動solr示例techproducts;對應(yīng)的core示例是techproducts

bin/solr start -e techproducts    

啟動solr的Web頁面

open http://localhost:8080/solr       

創(chuàng)建一個core

bin/solr create -c core0(core的名字)

solr索引結(jié)構(gòu)化內(nèi)容 示例結(jié)構(gòu)化文件路徑example/exampledocs

bin/post -c core0(自己的core的名字)   docs/*.xml(需要索引的文件路徑或父文件夾,文件格式可以是xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods)

打開索引搜索模式的Web界面。這是一個示例鏈接,端口號和core名字要寫自己的

open localhost:8080/solr/core0/browse       

刪除id=SP2514N的文件

bin/post -c gettingstarted -d "<delete><id>SP2514N</id></delete>"   

2. solr命令參數(shù)詳解:


solr start [-f] [-c] [-h hostname] [-p port] [-d directory] [-z zkHost] [-m memory] [-e example] [-s solr.solr.home] [-a "additional-options"] [-V]

-f
設(shè)置前臺啟動solr,并將標(biāo)準(zhǔn)輸出或錯誤信息發(fā)送到solr-PORT-console.log; solr默認(rèn)是在后臺啟動的

   -f:   Start Solr in foreground; default starts Solr in the background 
  and sends stdout/stderr to solr-PORT-console.log

-c or -cloud
在SolrCloud模式下啟動Solr;如果沒有指定-z,zookeeper將在port+1000的端口啟動

  -c or -cloud:    Start Solr in SolrCloud mode; if -z not supplied, an embedded Zookeeper
  instance is started on Solr port+1000, such as 9983 if Solr is bound to 8983

-h <host>
指定solr實例的主機名

-h <host>:    Specify the hostname for this Solr instance

-p <port>
指定啟動solr http 偵聽器的端口,默認(rèn)值為8983。指定的端口也用于停止/重啟solr服務(wù)以及進(jìn)行其他的solr操作。

 -p <port>:    Specify the port to start the Solr HTTP listener on; default is 8983
 The specified port (SOLR_PORT) will also be used to determine the stop port
 STOP_PORT=($SOLR_PORT-1000) and JMX RMI listen port RMI_PORT=($SOLR_PORT+10000). 
  For instance, if you set -p 8985, then the STOP_PORT=7985 and RMI_PORT=18985

-d <dir>
指定solr服務(wù)器目錄,默認(rèn)為服務(wù)器

-d <dir>:  Specify the Solr server directory; defaults to server

-z <zkHost>
zookeeper連接字符串;僅在-c/-cloud模式下使用。

-z <zkHost>:    Zookeeper connection string; only used when running in SolrCloud mode using -c
    To launch an embedded Zookeeper instance, don't pass this parameter.

-m <memory>
設(shè)置 jvm 的最小 (-xms) 和最大 (--xmx) 堆大小

-m <memory>:    Sets the min (-Xms) and max (-Xmx) heap size for the JVM, such as: -m 4g
    results in: -Xms4g -Xmx4g; by default, this script sets the heap size to 512m

-s <dir>
設(shè)置solr.solr.home系統(tǒng)屬性。將在這個目錄創(chuàng)建核心目錄。這使您可以在統(tǒng)一主機運行多個solr實例。默認(rèn)自帶目錄/solr

-s <dir>:     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.
 This parameter is ignored when running examples (-e), as the solr.solr.home depends
 on which example is run. The default value is server/solr.

-e <example>
要運行的實例的名稱可以使用自帶示例techproducts

 -e <example>:  Name of the example to run; available examples:
  cloud:         SolrCloud example
  techproducts:  Comprehensive example illustrating many of Solr's core capabilities
  dih:           Data Import Handler
  schemaless:    Schema-less example

-a
啟動時傳給jvm的附加參數(shù)

 -a:       Additional parameters to pass to the JVM when starting Solr, such as to setup
    Java debug options. For example, to enable a Java debugger to attach to the Solr JVM
     you could pass: -a "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=18983"
    In most cases, you should wrap the additional parameters in double quotes.

- noprompt
不提示輸入;在運行接受用戶輸入的示例時接受所有默認(rèn)值

 -noprompt: Don't prompt for input; accept all defaults when running examples that accept user input

-v and -q
使用調(diào)試或一般記錄。將默認(rèn)日志級別設(shè)置為 "調(diào)試" 或 "警告" 而不是 "信息"

 -v and -q:Verbose (-v) or quiet (-q) logging. Sets default log level to DEBUG or WARN instead of INFO
  -V or -verbose Verbose messages from this script

3. solr 查詢語法詳解

支持的參數(shù)
  • q
    主查詢參數(shù)
    寫法:q=<field_name>:<value>field_name可省略
    樣例:q=*:*(返回全部);q=西夏q=name:西夏*q=(博物館 OR type_i:0)
  • sort
    按照升序或降序?qū)Σ樵兊捻憫?yīng)進(jìn)行排序
    可選參數(shù):asc(倒序),desc(正序,默認(rèn)值)【不區(qū)分大小寫】
    寫法:sort=<field name>+<direction>,<field name>+<direction>],...
    樣例:sort=id ascsort=updated_at_d+descsort=log_id asc ,start_time desc
  • start
    起始數(shù)據(jù)偏移量,用于分頁(默認(rèn)值:0)
    樣例:start=0
  • rows
    控制一次返回的數(shù)據(jù)量,用于分頁(默認(rèn)值:10)
    樣例:rows=20
  • fq [filter query]
    返回搜索結(jié)果的過濾器查詢
    寫法:fq=<field_name>:<value>
    樣例:fq=net_type:1fq=net_type:1 AND (idt_id:12011 OR idt_id:5004) AND time_type:1fq=net_type:1&fq=idt_id:12011
  • fl [fields to list]
    限制查詢響應(yīng)中返回的指定字段列表。
    寫法:fl=<field_name>,<field_name>fl=<field_name>+<field_name>
    樣例:fl=*+namefl=log_id,start_time,end_time
  • wt (response writer)
    指定用于格式化查詢響應(yīng)的響應(yīng)寫入器格式。
    樣例:wt=rubywt=xmlwt=json
  • timeallowed
    定義允許處理查詢的時間。如果時間過去了
    查詢響應(yīng)完成,可能返回部分信息。
  • debug
    在響應(yīng)中請求其他調(diào)試信息。
    指定debug = timing參數(shù)只返回時間信息;
    指定debug = results參數(shù)為返回的每個文檔返回“說明”信息;
    指定debug = query參數(shù)返回所有調(diào)試信息。
    可選參數(shù):query; timing; results; all
    *hl
    是否高亮
    寫法:hl=truehl.<field_name>,<field_name2>
  • defType
    用于選擇要用于處理查詢的查詢解析器類型
    可選參數(shù):dismaxedismax
    Solr默認(rèn)有三種查詢解析器(Query Parser):
    • Standard Query Parser
    • DisMax Query Parser
    • Extended DisMax Query Parser (eDisMax)
      第一種是標(biāo)準(zhǔn)的Parser,最后一種是最強大的,也是Sunspot默認(rèn)使用的Parser。
分組查詢:

stats=true
stats.field=<field_name>
多組
facet=true
facet.field=

特殊符號:

+ - * ? && || () {} ^ " ~ : /

+ 必須滿足
- 剔除
? 匹配單個字符
樣例:te?ttex?
*匹配0到多個字符
~
1’ 模糊匹配
樣例:<value>~<0~1>
2’ 臨近檢索
樣例:<value>~<0~10>
^權(quán)重
^=指定分?jǐn)?shù)
[number TO number]指定范圍
/轉(zhuǎn)義字符

邏輯操作:

AND/&& 與
OR/ || 或
NOT/! 非

4. solr schema配置詳解

參考鏈接:
Solr高效利用:Solr實現(xiàn)SQL的查詢與統(tǒng)計[轉(zhuǎn)]
Solr查詢

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容