solr 5.4 创建core

来源:互联网 发布:学人工智能10本必看书 编辑:程序博客网 时间:2024/06/05 05:08


创建Core

  如果你没有使用solr自带的实例配置,你必须自己创建一个core来建立索引和搜索。命令如下:

   

$ bin/solr create -c <name>

 这将会创建一个数据驱动架构的core,此架构会在你添加Document到索引的时候尝试猜测合适的字段类型。可以使用如下命令查看所有create 命令可选项:

$ bin/solr create -help

添加Document

   solr创建的目的就是根据查询来搜索匹配的文档(Document)的。Solr的架构提供了一种关于内容是如何组织的的视图,但是如果没有文档就无从查起了。在索引自己的内容之前,你可能想添加一些实例文档到索引。Solr的安装文件中包含了不同类型的实例文档,位于你的安装文件的 example/  子目录下。

 bin目录下是post脚本,一种可以用来索引不同文档的命令行工具。关于索引的详细见 索引详情

查看更多的 bin/post 命令,使用 -help 选项。 

 bin/post可以提交(post )各种各样类型的内容给Solr,包括Solr自支持的XML格式,CSV格式,JSON格式,包含了许多文档的目录树,甚至一个简单的web爬虫。

 继续,添加XML实例文件中全部文档。命令和输出如下:

$ bin/post -c gettingstarted example/exampledocs/*.xmlSimplePostTool version 5.0.0Posting files to [base] url http://localhost:8983/solr/gettingstarted/update...Entering auto mode. File endings considered are xml,json,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,logPOSTing file gb18030-example.xml (application/xml) to [base]POSTing file hd.xml (application/xml) to [base]POSTing file ipod_other.xml (application/xml) to [base]POSTing file ipod_video.xml (application/xml) to [base]POSTing file manufacturers.xml (application/xml) to [base]POSTing file mem.xml (application/xml) to [base]POSTing file money.xml (application/xml) to [base]POSTing file monitor.xml (application/xml) to [base]POSTing file monitor2.xml (application/xml) to [base]POSTing file mp500.xml (application/xml) to [base]POSTing file sd500.xml (application/xml) to [base]POSTing file solr.xml (application/xml) to [base]POSTing file utf8-example.xml (application/xml) to [base]POSTing file vidcard.xml (application/xml) to [base]14 files indexed.COMMITting Solr index changes to http://localhost:8983/solr/gettingstarted/update...Time spent: 0:00:00.153

索引搜索

 最简单的搜索是 创建一个包含了查询参数的URL,这与其他任何HTTP URL几乎是一样的。例如如下查询所有包含了 字段"video"的全部文档。

  http://localhost:8983/solr/gettingstarted/select?q=video

注意到,URL包含了主机名(localhost),solr server服务监听的端口号,应用名称(solr)


0 0
原创粉丝点击