强大的搜索引擎solr探索

一、序言

Solr做为apache的项目具有十分强大的分词快速检索的开源Apache lucene项目。特别适合大量的检索及查询。这里我们对强大的solr进行一步步的探索吧。

二、安装

solr的安装非常方便,我们只需要去官网http://www.apache.org/dyn/closer.lua/lucene/solr/7.6.0

1、下载最新版版的二进制包

 

images

2、下载后直接上传至服务器中解压安装包

~$ ls solr*
solr-7.6.0.zip

~$ unzip -q solr-7.6.0.zip

~$ cd solr-7.6.0/

3、用solr云模式启动solr

启动用有提示选项直接enter回车默认即可

bin/solr start -e cloud
Starting up 2 Solr nodes for your example SolrCloud cluster.

Creating Solr home directory /solr-7.6.0/example/cloud/node1/solr
Cloning /solr-7.6.0/example/cloud/node1 into
   /solr-7.6.0/example/cloud/node2

Starting up Solr on port 8983 using command:
"bin/solr" start -cloud -p 8983 -s "example/cloud/node1/solr"

Waiting up to 180 seconds to see Solr running on port 8983 [\]
Started Solr server on port 8983 (pid=34942). Happy searching!


Starting up Solr on port 7574 using command:
"bin/solr" start -cloud -p 7574 -s "example/cloud/node2/solr" -z localhost:9983

Waiting up to 180 seconds to see Solr running on port 7574 [\]
Started Solr server on port 7574 (pid=35036). Happy searching!

INFO  - 2017-07-27 12:28:02.835; org.apache.solr.client.solrj.impl.ZkClientClusterStateProvider; Cluster at localhost:9983 ready

看到这里即表示启动成功

直接在浏览器中软件 localhost:8983/solr

会展示出solr Admin UI

images

三、数据导入及查询

1、新建测试collection

bin/solr create -c techproducts -s 2 -rf 2

2、导入测试数据

bin/post -c techproducts example/exampledocs/*

看到如下结果后表示导入成功

SimplePostTool version 5.0.0
Posting files to [base] url http://localhost:8983/solr/techproducts/update...
Entering auto mode. File endings considered are xml,json,jsonl,csv,pdf,doc,docx,ppt,pptx,xls,xlsx,odt,odp,ods,ott,otp,ots,rtf,htm,html,txt,log
POSTing file books.csv (text/csv) to [base]
POSTing file books.json (application/json) to [base]/json/docs
POSTing 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 more_books.jsonl (application/json) to [base]/json/docs
POSTing file mp500.xml (application/xml) to [base]
POSTing file post.jar (application/octet-stream) to [base]/extract
POSTing file sample.html (text/html) to [base]/extract
POSTing file sd500.xml (application/xml) to [base]
POSTing file solr-word.pdf (application/pdf) to [base]/extract
POSTing file solr.xml (application/xml) to [base]
POSTing file test_utf8.sh (application/octet-stream) to [base]/extract
POSTing file utf8-example.xml (application/xml) to [base]
POSTing file vidcard.xml (application/xml) to [base]
21 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/techproducts/update...
Time spent: 0:00:00.822

3、简单的数据查询

 

images

查询的同时会生成solr的查询URL连接

 

四、数据导入

1、生成新的collection

bin/solr create -localDocs -s 2 -rf 2

2、本地生成一个密码数据集password.json

[{
                "password": "eyJtZW1iZXJMaXN0I",
                "userId": "TestUser01"
        },
        {
                "password": "Q4US8wIiwibGFpeXV",
                "userId": "TestUser02"
        },
        {
                "password": "ajVnRXVxWlZyQUNWS",
                "userId": "TestUser03"
        },
        {
                "password": "oi6Zi/6IO257OV5Lu",
                "userId": "TestUser04"
        },
        {
                "password": "In0seyJhZGRyZXNzI",
                "userId": "TestUser05"
        },
        {
                "password": "wiaWNvblVybCI6IiI",
                "userId": "TestUser06"
        }
]

 

3、导入数据至collection中

bin/post -c localDocs password.json

4、进入查询UI界面

发现json数据已经导入至solr了images

目前官方文档中数据导入支持以下几种方式

本地文件模式

数据导入助手 官方ADMIN UI提供的一个导入工具

SOLRJ库 支持JAVA应用调用SOLR方法进行数据导入和查询

文件助手

images

admin

发表评论

电子邮件地址不会被公开。 必填项已用*标注

Post comment