在看solr之前 可以看一下 :lucene的基础入门
1.Solr的相关目录
1.1 在window下运行
将下载的solr解压后/example/webapps/solr.war复制tomcat/webapps目录下。启动tomcat并且进行访问
访问http://localhost/solr 我的tomcat端口为80
查看tomcat日志:
十一月 22, 2018 10:27:24 上午 org.apache.catalina.core.StandardContext filterStart 严重: Exception starting filter SolrRequestFilter java.lang.NoClassDefFoundError: Failed to initialize Apache Solr: Could not find necessary SLF4j logging jars. If using Jetty, the SLF4j logging jars need to go in the jetty lib/ext directory. For other containers, the corresponding directory should be used. For more information, see: http://wiki.apache.org/solr/SolrLogging at org.apache.solr.servlet.CheckLoggingConfiguration.check(CheckLoggingConfiguration.java:28) at org.apache.solr.servlet.BaseSolrFilter.<clinit>(BaseSolrFilter.java:31) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.lang.Class.newInstance(Class.java:442) at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:140) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258) at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4809) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5485) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1073) at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) 十一月 22, 2018 10:27:28 上午 org.apache.catalina.core.ApplicationContext log 信息: ContextListener: contextInitialized() 十一月 22, 2018 10:27:28 上午 org.apache.catalina.core.ApplicationContext log 信息: SessionListener: contextInitialized() 十一月 22, 2018 10:27:28 上午 org.apache.catalina.core.ApplicationContext log 信息: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@1715338d')
Could not find necessary SLF4j logging jars.
If using Jetty, the SLF4j logging jars need to go in the jetty lib/ext directory.
For other containers, the corresponding directory should be used.
For more information, see: http://wiki.apache.org/solr/SolrLogging
at org.apache.solr.servlet.CheckLoggingConfiguration.check(CheckLoggingConfiguration.java:28)
缺少jar包:
将这些jar 拷贝到
然后再重启tomcat,再次访问 http://localhost/solr
500错误
需要配置索引库的位置 solr home ,修改web.xml
在此处配置solr home 的位置 在目录结构中已经说了solr的家
为了方便我直接把solr 拷贝到E盘根目录下
<env-entry> <env-entry-name>solr/home</env-entry-name> <env-entry-value>e:/solr</env-entry-value> <env-entry-type>java.lang.String</env-entry-type> </env-entry>
重新开启服务器,再次访问. http://localhost/solr
成功访问
二 solr home
2.1 solr.xml
<solr> <solrcloud> <str name="host">${host:}</str> <int name="hostPort">${jetty.port:8983}</int> <str name="hostContext">${hostContext:solr}</str> <int name="zkClientTimeout">${zkClientTimeout:30000}</int> <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool> </solrcloud> <shardHandlerFactory name="shardHandlerFactory" class="HttpShardHandlerFactory"> <int name="socketTimeout">${socketTimeout:0}</int> <int name="connTimeout">${connTimeout:0}</int> </shardHandlerFactory> </solr>
<solrcloud>:配置solr集群(监听web服务器的端口)
2.2 collection1
1、data:存储索引文件(数据)
2、conf:索引库中相关的配置文件
3、core.properties:配置索引库名称、配置solr集群后的分片(shard)规则
内容: name=collection1
2.2.1 core.properties
作用:配置索引库名称 修该索引库的名字
选择索引库
2.2.2conf
作用:索引库的配置文件
2.2.2.1 schema.xml文件 --- MySQL中表
作用:配置业务字段。
1、field:配置字段
- name:字段名称
- type:字段类型
- indexed:true or false 是否创建索引
- stored:true or false 是否存储
- multiValued:true or false 是否多值
2、dynamicField:动态字段
匹配相关字段
3、uniqueKey:唯一主键(MySQL中主键)
4、copyField:将源字段的内容复制到目标字段中,后期直接根据目标字段进行检索。
- source:源字段
- dest:目标字段
5、fieldType:定义字段类型
- name:字段类型名称
- class:对应的solr中类型---Lucene类型
2.2.2.2 solrconfig.xml文件 --- sql语法
作用:配置solr的运行规则(solr服务请求方法)
1、luceneMatchVersion:匹配Lucene版本
2、lib:引入额外功能的jar(插件) --- collection1/lib
3、requestHandler:请求的执行句柄(请求的方法)