当前位置:首页 > CN2资讯 > 正文内容

搭建windows的solr6服务器(二)

4小时前CN2资讯

首先搭建solr环境,如:solr6.0学习(一)环境搭建

修改各种配置文件。

1、修改solrhome下的solr.xml文件

注解掉zookeeper搭建集群配置,我们后面会采用master-slave的形式。

至于zookeeper的形式可以阅读以下这篇文章【solrCloud集群配置指导】:http:///thread-9432-1-1.html

[html] view plain copy 
  • <!-- 结合zookeeper配置solrColound start -->  
  •   <!-- 采用master-slave的方式  
  •   <solrcloud>  
  •   
  •     <str name="host">${host:}</str>  
  •     <int name="hostPort">${jetty.port:8983}</int>  
  •     <str name="hostContext">${hostContext:solr}</str>  
  •   
  •     <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>  
  •   
  •     <int name="zkClientTimeout">${zkClientTimeout:30000}</int>  
  •     <int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:600000}</int>  
  •     <int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:60000}</int>  
  •   
  •   </solrcloud>  
  •   
  •   <shardHandlerFactory name="shardHandlerFactory"  
  •     >  
  •     <int name="socketTimeout">${socketTimeout:600000}</int>  
  •     <int name="connTimeout">${connTimeout:60000}</int>  
  •   </shardHandlerFactory>  
  •   -->  
  • <!-- 结合zookeeper配置solrColound end -->  
  • 2、在sorlhome文件夹下创建【my_solr】文件夹。

    3、在【my_solr】文件夹中添加core.properties配置,内容如下:

    [html] view plain copy 
  • name=my_solr  
  • 这个name的值实际上就core的名称,可以任意命名,为了保证统一和方便阅读,个人觉得最好和文件夹名称一致。

    4、将【solr-6.0.0\example\example-DIH\solr\solr】下的conf文件夹拷贝到【my_solr】文件夹下。包含如下文件:

    【conf】中文件目录如下:

    5、solr-5.0 以上默认对schema的管理是使用managed-schema,不能手动修改,需要使用Schema Restful的API操作。

    如果要想手动修改配置,把【conf】文件夹中managed-schema拷贝一份修改为schema.xml,在solrconfig.xml中修改如下:

    [html] view plain copy
  • <codecFactory />  
  •   <!-- 解除managed-schema管理模式 start -->  
  •   <schemaFactory />  
  •   <!-- 解除managed-schema管理模式 end -->  
  • 重启tomcat8,可能会报错,查看tomcat日志发现,比喻:

    缺少DataImportHandler的jar等,那么将【solr-6.0.0\dist】下的solr-dataimporthandler-6.0.0.jar和solr-dataimporthandler-extras-6.0.0.jar

    拷贝到【apache-tomcat-8.0.33\webapps\solr\WEB-INF\lib】下。

    重启tomcat8。如果缺少其他jar包,根据报错信息添加即可。没有异常,

    访问:【http://localhost:8080/solr/index.html#/】

    会出现如下界面:

    选择my_solr,会出现如下界面:

    至此其实由于没有索引数据,其实solr是个空壳,那么下面写一个应用程序插入solr索引数据。

    参考:http://www.open-open.com/lib/view/open1452062296995.html

    1、首先需要修改schema.xml文件,添加

    [html] view plain copy
  • <field name="content_test" type="text_general" indexed="true" stored="true" multiValued="true"/>  
  • field的属性和配置,可以google一下schema.xml 说明很多,用法也很多,这里就不赘述。

    2、添加索引数据,代码如下:

    编写过程中可能会报错,最简便的方法是将web-inf下lib里所有jar包添加进来,然后运行,出什么错,就添加什么jar包即可。

    [java] view plain copy
  • package com.solr.insertData;  
  •   
  •   
  • import java.io.IOException;  
  • import java.util.ArrayList;  
  • import java.util.List;  
  •   
  • import org.apache.solr.client.solrj.SolrClient;  
  • import org.apache.solr.client.solrj.SolrServerException;  
  • import org.apache.solr.client.solrj.impl.HttpSolrClient;  
  • import org.apache.solr.common.SolrInputDocument;  
  •   
  • public class InsertProgarm {  
  •     //solr 服务器地址  
  •     public static final String solrServerUrl = "http://localhost:8080/solr";  
  •     //solrhome下的core  
  •     public static final String solrCroeHome = "my_solr";  
  •     //待索引、查询字段  
  •     public static String[] docs = {"Solr是一个独立的企业级搜索应用服务器",  
  •                                     "它对外提供类似于Web-service的API接口",  
  •                                     "用户可以通过http请求",  
  •                                      "向搜索引擎服务器提交一定格式的XML文件生成索引",  
  •                                     "也可以通过Http Get操作提出查找请求",  
  •                                     "并得到XML格式的返回结果"};  
  •     public static void main(String[] args) {  
  •         SolrClient client = getSolrClient();  
  •         int i=0;  
  •         List<SolrInputDocument> solrDocs = new ArrayList<SolrInputDocument>();  
  •         for (String content : docs) {  
  •             SolrInputDocument doc = new SolrInputDocument();  
  •             doc.addField("id", i++);  
  •             doc.addField("content_test", content);  
  •             solrDocs.add(doc);  
  •         }  
  •         try {  
  •             client.add(solrDocs);  
  •             client.commit();  
  •         } catch (SolrServerException e) {  
  •             // TODO Auto-generated catch block  
  •             e.printStackTrace();  
  •         } catch (IOException e) {  
  •             // TODO Auto-generated catch block  
  •             e.printStackTrace();  
  •         }  
  •           
  •     }  
  •     public static SolrClient getSolrClient(){  
  •         return new HttpSolrClient(solrServerUrl+"/"+solrCroeHome);  
  •     }  
  •   
  • }  
  • 3、运行成功后,会在【solrhome/my_solr】文件夹下创建一个【data】的文件夹,这个文件夹中的内容就是我们的solr索引。

    其实其对于的是solconfig.xml中如下配置:

    [html] view plain copy
  • <!-- Data Directory  
  •   
  •        Used to specify an alternate directory to hold all index data  
  •        other than the default ./data under the Solr home.  If  
  •        replication is in use, this should match the replication  
  •        configuration.  
  •     -->  
  •   <dataDir>${solr.data.dir:}</dataDir>  
  • 4、访问http://localhost:8080/solr/index.html选择【my_solr】core,选择query得到如下界面:




    红色区域是针对不同的ui,因为浏览器版本问题,我这里面选择使用【Use original UI】,会跳转到http://localhost:8080/solr/old.html#/

    选择【my_solr】core,选择query,点击【Execute Query】查询结果如下:

    其实其访问的url实际为:http://localhost:8080/solr/my_solr/select?q=*%3A*&wt=json&indent=true

    至于q、wt、indent等参数,代表的含义,可以搜索solr查询语法。

    那么至此,我们就将solr插件完毕,结合了core和创建索引、查询程序,完成!

      你可能想看:

      扫描二维码推送至手机访问。

      版权声明:本文由皇冠云发布,如需转载请注明出处。

      本文链接:https://www.idchg.com/info/31403.html

      分享给朋友:

      “搭建windows的solr6服务器(二)” 的相关文章

      Virmach Coupons: 轻松获取超值优惠,优化你的VPS选择

      Virmach成立于2014年,作为一家美国VPS服务商,在业内享有良好的声誉。它的总部位于加利福尼亚州洛杉矶,正是这样得天独厚的地理位置让它能迅速成长并服务全球用户。到现在为止,Virmach已经发展成为一家提供各种配置和价格方案的服务商,特别以低价VPS而闻名,吸引了大量希望降低运营成本的个人和...

      BT下载机的使用技巧与软件下载推荐

      在数字时代,文件共享变得越来越普遍,BT下载机作为一种基于BitTorrent协议的P2P(Peer-to-Peer)文件共享工具,扮演着重要的角色。我记得第一次接触BT下载机时,发现它的操作不仅简单,还能快速下载大型文件,这让我对它产生了浓厚的兴趣。BT下载机允许用户通过种子文件(.torrent...

      Nginx Cache Control: 如何使用 No Cache 精确管理缓存策略

      作为一名开发者,我一直非常欣赏 Nginx 作为高性能 HTTP 和反向代理服务器的能力。Nginx 不仅在稳定性和可扩展性方面表现出色,它的缓存控制功能也相当强大。通过设置响应头,Nginx 能有效地管理客户端和代理服务器的缓存行为,让我在开发和部署时能够更灵活地处理资源的缓存。 使用缓存控制的好...

      国外VPS:高性价比虚拟专用服务器选择指南

      什么是国外VPS? 当我提到国外VPS时,它指的就是虚拟专用服务器(Virtual Private Server),这是一种把物理服务器分割成多个独立的小型服务器的技术。每一个VPS都拥有自己的公网IP地址和操作系统,资源如磁盘空间、内存和CPU都可以独立配置。这种固有的隔离性,可以让我在同一个物理...

      瓦工职业特征与发展前景分析

      瓦工,这个听起来有些古老的职业,实际上在我们的社会中扮演着举足轻重的角色。它主要负责砌筑工作,用砖块、砌块和砂浆等材料建造房屋、烟囱等不同结构。北方地区的人们常常把瓦工称为泥工,虽然这两者有些细微差别,但归根结底,瓦工是建筑行业不可缺少的一个部分。 在瓦工的工作范围里,涉及到建筑砌体、隔墙、瓦片铺装...

      菲律宾用户如何通过VPS提升TikTok访问速度

      在菲律宾使用VPS访问TikTok,这个话题对很多喜欢在TikTok上进行电商活动或内容创作的人来说非常重要。首先,我想谈谈VPS的概念以及它的优势。VPS,全称是虚拟专用服务器,它提供了一种比共享主机更为灵活和高效的解决方案。对于菲律宾的用户来说,通过使用VPS,可以在一定程度上绕过地区限制,更流...