solr5.5-post.jar的使用

来源:互联网 发布:六轴机器人编程 编辑:程序博客网 时间:2024/06/14 03:49

为了方便用户往solr中添加索引,Solr为用户提供了一个post.jar工具,用户只需要在命令行下运行post.jar并传入一些参数就可以完成索引的增删改操作,对,它仅仅是一个供用户进行Solr测试的工具而已,有关post.jar的使用说明如下:

SimplePostTool version 5.1.0Usage: java [SystemProperties] -jar post.jar [-h|-] [<file|folder|url|arg> [<file|folder|url|arg>...]]Supported System Properties and their defaults:  -Dc=<core/collection>  -Durl=<base Solr update URL> (overrides -Dc option if specified)  -Ddata=files|web|args|stdin (default=files)  -Dtype=<content-type> (default=application/xml)  -Dhost=<host> (default: localhost)  -Dport=<port> (default: 8983)  -Dauto=yes|no (default=no)  -Drecursive=yes|no|<depth> (default=0)  -Ddelay=<seconds> (default=0 for files, 10 for web)  -Dfiletypes=<type>[,<type>,...] (default=xml,json,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log)  -Dparams="<key>=<value>[&<key>=<value>...]" (values must be URL-encoded)  -Dcommit=yes|no (default=yes)  -Doptimize=yes|no (default=no)  -Dout=yes|no (default=no)This is a simple command line tool for POSTing raw data to a Solr port.NOTE: Specifying the url/core/collection name is mandatory.Data can be read from files specified as commandline args,URLs specified as args, as raw commandline arg strings or via STDIN.Examples:  java -Dc=gettingstarted -jar post.jar *.xml  java -Ddata=args -Dc=gettingstarted -jar post.jar '<delete><id>42</id></delete>'  java -Ddata=stdin -Dc=gettingstarted -jar post.jar < hd.xml  java -Ddata=web -Dc=gettingstarted -jar post.jar http://example.com/  java -Dtype=text/csv -Dc=gettingstarted -jar post.jar *.csv  java -Dtype=application/json -Dc=gettingstarted -jar post.jar *.json  java -Durl=http://localhost:8983/solr/techproducts/update/extract -Dparams=literal.id=pdf1 -jar post.jar solr-word.pdf  java -Dauto -Dc=gettingstarted -jar post.jar *  java -Dauto -Dc=gettingstarted -Drecursive -jar post.jar afolder  java -Dauto -Dc=gettingstarted -Dfiletypes=ppt,html -jar post.jar afolderThe options controlled by System Properties include the SolrURL to POST to, the Content-Type of the data, whether a commitor optimize should be executed, and whether the response shouldbe written to STDOUT. If auto=yes the tool will try to set typeautomatically from file name. When posting rich documents thefile name will be propagated as "resource.name" and also usedas "literal.id". You may override these or any other request parameterthrough the -Dparams property. To do a commit only, use "-" as argument.The web mode is a simple crawler following links within domain, default delay=10s.

重点在这里:

java [SystemProperties] -jar post.jar [-h|-] [<file|folder|url|arg> [<file|folder|url|arg>...]]

要看懂这个post.jar使用命令规范,你首先需要知道,被中括号包住的参数表示可选参数即这个参数可有可有,| 表示或者,SystemProperties表示属性,什么叫系统属性呢?即你通过System.setProperty();设置的参数,比如:

System.setProperty(key,value);

这里的key,value值都是随便定义的,没什么特别要求,这样你随后通过System.getProperty(key)通过key就能在任意时刻获取到该key对应的参数值,如果是在dos命令行下,你也可以通过java -Dkey=value这种方式指定,至此java [SystemProperties]这部分你应该理解了,至于后面的-jar是java命令的参数,即执行一个jar文件,-jar后面指定一个jar包路径,默认是相对于当前所在路径,-h即表示添加了这个即会打印命令提示信息,就好比你敲java -h是类似的,后面的file,folder,url,args分别表示你要提交的数据的几种不同表示形式,file即表示你要提交的数据是存在于文件中,而folder即表示你要提交的存在于文件夹中,url即表示你要提交的数据是存在于互联网上的一个URL地址表示的资源,它可能是一个HTML页面,可能是一个PDF文件,可能是一个图片等等,args即表示你要提交的数据直接在命令行敲出来,但arges并不是随随便便一个字符串就行的,它需要有固定的格式,solr才能解析

下面列出了post.jar支持的几个自定义系统属性,下面我会对每个自定义系统属性一一做个说明:

-Dc=<core/collection>  -Durl=<base Solr update URL> (overrides -Dc option if specified)  -Ddata=files|web|args|stdin (default=files)  -Dtype=<content-type> (default=application/xml)  -Dhost=<host> (default: localhost)  -Dport=<port> (default: 8983)  -Dauto=yes|no (default=no)  -Drecursive=yes|no|<depth> (default=0)  -Ddelay=<seconds> (default=0 for files, 10 for web)  -Dfiletypes=<type>[,<type>,...] (default=xml,json,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log)  -Dparams="<key>=<value>[&<key>=<value>...]" (values must be URL-encoded)  -Dcommit=yes|no (default=yes)  -Doptimize=yes|no (default=no)  -Dout=yes|no (default=no)

-D是命令行下指定系统属性的固定前缀,

c表示core名称,你需要对solr admin里的哪个core进行索引数据添加/修改/删除

url表示solr admin后台索引更新的请求URL,这个URL是固定的,一般格式是http://host:port/solr/coreName/update,{coreName}和上面的c属性值保持一致

data表示你要提交数据的几种模式,files模式表示你要提交的数据在文件里

web表示你要提交的数据在互联网上的一个URL表示的资源文件里

args表示你要提交的数据你会直接在post.jar命令后面直接输入

stdin表示你要提交的数据需要在dos命令行下通过System.in输入流临时接收,跟args有点类似,

但不同的是,stdin模式下,post.jar后面不需要指定任何参数,直接回车即可,然后程序会等待用户输入,

用户输入完毕再回车,post.jar会接收到用户输入,post.jar重新被唤醒继续执行。而args是直接在post.jar后面

输入参数,没有一个中断过程,而stdin模式下如果用户一直没有输入,那post.jar就会一直阻塞在那里等待用户输入为止。

type表示你要提交数据的MIME类型,默认是application/xml即默认会当作是XML来处理

host表示你要链接的SOlr Admin部署服务器的主机名或者IP地址,默认是localhost

port表示你要链接的Solr Admin部署的Web容器监听的端口号,默认post.jar里设置为8983

port具体值取决于你实际部署环境而定

auto表示是否自动猜测文件类型

recursive表示是否递归,这里递归有两种情况,比如你data=folder即表示是否递归查找文件夹下的

所有文件,如果你data=web即表示是否递归抓取URL,设置为no即表示不递归操作,设置为一个数字,

即表示递归深度

delay:这里的时间延迟也分两种,如果你post的是file,那么每个file的post间隔为0,即不做延迟处理,

而如果你是post的是网络上的一个url资源,因为需要收到对方服务器的访问限制,所以必须要做一个抓取

频率限制即每抓一个睡眠一会儿,否则抓取太快太频率容易被对方封IP。

filetypes表示post.jar支持提交哪些文件类型,后面有列出默认支持的文件类型,如果你想覆盖默认值,那么

请指定此参数

params表示需要追加到Solr Admin的请求URL后面的请求参数如id=1&name=yida之类的

commit表示是否提交到solr admin后台进行索引写入,设置为false表示不提交至sor admin,但设置为true也不一定

就意味着就一定会把索引写入磁盘,这取决于solrconfig中directory配置的实现是什么,如果配置的是RAMDirectory,就仅仅只在内存中操作了。

optimize表示是否需要对索引进行优化操作,默认为no即表示不对索引进行优化

out即OutputStream表示输出流,这个参数作用就是,你请求Solr Admin添加索引数据,Solr Admin后台会返回数据给你,Solr Admin后台返回的数据你拿什么输出流来接收,默认是System.out即表示把后台返回的信息输出打印到控制台

0 0
原创粉丝点击