设为首页 收藏本站
查看: 959|回复: 0

[经验分享] Solr自学笔记 1 —— Solr部署,添加,更新,删除

[复制链接]

尚未签到

发表于 2017-3-2 10:00:45 | 显示全部楼层 |阅读模式
  1.solr介绍:自查wiki



2.环境部署
     1)下载地址:http://lucene.apache.org/solr/mirrors-solr-latest-redir.html
     2)需要的环境:         
              1.Java 1.7 or greater. Some places you can get it are from Oracle, Open JDK, or IBM.
Running java -version at the command line should indicate a version number starting with 1.7.
Gnu's GCJ is not supported and does not work with Solr.
         2.A Solr release.
3)官方文档
     docs目录下,如下图所示:
DSC0000.png

3.教程详情
     1)启动solr服务
          这里使用的是官方自带的例子:start.jar ,将下载的压缩包解压到E:盘中,通过以下命令行

  • E:\solr-4.8.0\example>java -jar start.jar

     这里执行的是含有Solr WAR的jetty服务器和相应的配置文件

Solr can run in any Java Servlet Container of your choice, but to simplify this tutorial, the example index includes a small installation of Jetty.

To launch Jetty with the Solr WAR, and the example configs, just run the start.jar ...
      此时,可以通过浏览器,输入  http://localhost:8983/solr/ 就可以查看Solr的管理界面
     2)此时Solr服务已经运行,但是它并不包含任何数据,你可以通过修改Solr索引,使用POST命令的方式向Solr中增加,更新和删除信息。
     3)添加数据
     这里通过以下命令行,要保证上面的solr服务一定要运行   
    添加数据的的数据格式,包含:
          xml: application/xml,text/xml;
          json: application/xml,text/json;
          csv : application/csv,text/csv;
          javabin: application/javabin;
    向Solr中添加数据的方式,包含:   



    • Import records from a database using the Data Import Handler (DIH). 数据库
    • Load a CSV file (comma separated values), including those exported by Excel or MySQL. CSV文件
    • POST JSON documents  JSON文档
    • Index binary documents such as Word and PDF with Solr Cell (ExtractingRequestHandler).Solr格式的pdf和word字节文档
    • Use SolrJ for Java or other Solr clients to programatically create documents to send to Solr.使用SolrJ或者Solr客户端编码的方式创建文档



  • E:\solr-4.8.0\example\exampledoc> java -jar post.jar solr.xml monitor.xml

     执行成功结果:
      SimplePostTool version 1.5
Posting files to base url http://localhost:8983/solr/update using content-type a
pplication/xml..
POSTing file solr.xml
POSTing file monitor.xml
2 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/update..
Time spent: 0:00:00.840


  • solr.xml中内容:

     <add>
<doc>
  <field name="id">SOLR1000</field>
  <field name="name">Solr, the Enterprise Search Server</field>
  <field name="manu">Apache Software Foundation</field>
  <field name="cat">software</field>
  <field name="cat">search</field>
  <field name="features">Advanced Full-Text Search Capabilities using Lucene</field>
  <field name="features">Optimized for High Volume Web Traffic</field>
  <field name="features">Standards Based Open Interfaces - XML and HTTP</field>
  <field name="features">Comprehensive HTML Administration Interfaces</field>
  <field name="features">Scalability - Efficient Replication to other Solr Search             Servers
</field>
  <field name="features">Flexible and Adaptable with XML configuration and Schema</field>
  <field name="features">Good unicode support: h&#xE9;llo (hello with an accent over the            e)
</field>
  <field name="price">0</field>
  <field name="popularity">10</field>
  <field name="inStock">true</field>
  <field name="incubationdate_dt">2006-01-17T00:00:00.000Z</field>
</doc>
     </add>
      此时通过一下的URL可以查询到增加的结果: http://localhost:8983/solr/collection1/select?q=solr&wt=xml  
      浏览器结果如下:

   {
    "responseHeader": {
        "status": 0,
        "QTime": 1,
        "params": {
            "q": "solr",
            "_": "1474873714872",
            "wt": "json"
        }
    },
    "response": {
        "numFound": 1,
        "start": 0,
        "docs": [
            {
                "id": "SOLR1000",
                "name": "Solr, the Enterprise Search Server",
                "manu": "Apache Software Foundation",
                "cat": [
                    "software",
                    "search"
                ],
                "features": [
                    "Advanced Full-Text Search Capabilities using Lucene",
                    "Optimized for High Volume Web Traffic",
                    "Standards Based Open Interfaces - XML and HTTP",
                    "Comprehensive HTML Administration Interfaces",
                    "Scalability - Efficient Replication to other Solr Search Servers",
                    "Flexible and Adaptable with XML configuration and Schema",
                    "Good unicode support: héllo (hello with an accent over the e)"
                ],
                "price": 0,
                "price_c": "0,USD",
                "popularity": 10,
                "inStock": true,
                "incubationdate_dt": "2006-01-17T00:00:00Z",
                "_version_": 1546511824707387400
            }
        ]
    }
}
     
          4)更新数据:
       更新数据的规则:Whenever you POST commands to Solr to add a document with the same value for the uniqueKey as an existing document, it automatically replaces it for you(根据文档唯一值是否存在,替换文档的内容)
     查看Solr中的文档数URL:
        http://localhost:8983/solr/#/collection1/plugins/core?entry=searcher
     numDocs :某个索引上的可以被搜索到的文档数
     maxDocs :表示某个索引上所有的文档数目,逻辑上可能已被删除,但实现上,并没有在该索引上移除
          5)删除数据:
     可以使用POSTing一个删除命令到相应的URL,明确文档unique key 或者一个查询来匹配多文档。
     执行下面的命令,来删除一个具体的文档:


  java -Ddata=args -Dcommit=false -jar post.jar "<delete><id>SP2514</id></delete>"

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-349140-1-1.html 上篇帖子: spring配置文件 下篇帖子: 消息中间件activemq-5.14.1安全验证配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表