您能帮助我使用Tomcat配置Apache Solr以及如何使用Solr在MS SQL数据库中编制索引.配置Tomcat以在Tomcat中运行Apache Solr的步骤是什么.
Yav*_*var 20
这是一步一步的程序,可以提供帮助.
第1部分:使用TOMCAT设置SOLR
第1步:下载Solr.它只是一个zip文件.
步骤2:从您的SOLR_HOME_DIR/dist/apache-solr-1.3.0.war复制到您的tomcat webapps目录:$ CATALINA_HOME/webapps/solr.war - 注意war文件名更改.这很重要.
第3步:在您选择的位置创建您的solr主目录.这是该solr安装的配置所在的位置.最简单的方法是将SOLR_HOME_DIR/examples/solr目录复制到您希望solr home容器所在的位置.说把它放在C:\ solr中.
第4步:希望您已设置环境变量,如果没有,请设置JAVA_HOME,JRE_HOME,CATALINA_OPTS,CATALINA_HOME.请注意,CATALINA_HOME引用您的Tomcat目录,CATALINA_OPTS引用您要为Solr提供的堆内存量.
第5步:启动tomcat.请注意,这只是允许tomcat解压缩war文件所必需的.如果您查看$ CATALINA_HOME/webapps,现在应该有一个solr目录.
第6步:停止tomcat
步骤7:进入该solr目录并编辑WEB-INF/web.xml.向下滚动,直到看到如下所示的条目:
<!-- People who want to hardcode their "Solr Home" directly into the
WAR File can set the JNDI property here...
-->
<!--
<env-entry>
<env-entry-name>solr/home</env-entry-name>
<env-entry-value>/Path/To/My/solr/Home/solr/</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
-->
Run Code Online (Sandbox Code Playgroud)
将Solr设置为home(例如:C:\ solr)并取消注释env条目.
第8步:再次启动Tomcat,事情应该很顺利.您应该能够通过尝试URL http:// localhost:8080/solr/admin /来验证solr是否正在运行.
第2部分:使用数据导入处理程序使用MSSQL SERVER设置SOLR
步骤1:下载Microsoft SQL Server JDBC驱动程序3.0.只需提取内容即可.在solr主目录下创建一个文件夹(例如:C:\ solr\lib).将文件sqljdbc4.jar从上面下载的存档中复制到其中.
第2步:所以在你的Solr home下,所需的基本目录是conf和lib.您可能在第1部分和第11部分的第3步中得到的第一个是您在第2部分的第1步中创建的目录.
第3步.转到conf目录.请在编辑器中打开3个文件:data-config.xml,schema.xml和solrconfig.xml.
步骤4.首先编辑data-config.xml.放置您的SQL查询,数据库名称,服务器名称等.例如:
• <dataConfig>
• <dataSource type="JdbcDataSource" driver="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://X.Y.Z.U:1433;databaseName=myDB" user="test" password="tester" />
• <document>
• <entity name="Text" query="select DocumentId, Data from Text">
• <field column="DocumentId" name="DocumentId" />
• <field column="Data" name="Data" />
• </entity>
• </document>
• </dataConfig>
Run Code Online (Sandbox Code Playgroud)
第5步:告诉Solr我们的data-config.xml文件.这可以通过向solrconfig.xml文件添加请求处理程序来完成,该文件是solr配置文件.将以下requesthandler添加到solrconfig.xml:
• <requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
• <lst name="defaults">
• <str name="config">C:\solr\conf\data-config.xml</str>
• </lst>
• </requestHandler>
Run Code Online (Sandbox Code Playgroud)
步骤6:配置schema.xml - 在此文件中,您可以执行几项操作,例如设置字段的数据类型,设置搜索的唯一/主键等.
第7步:启动Tomcat
步骤8:现在访问http:// localhost:8080/solr/admin/dataimport.jsp?handler =/dataimport并开始完全导入.
一些方便的笔记:
• There are a number of reasons a data import could fail, most likely due to problem with
the configuration of data-config.xml. To see for sure what's going on you'll have to look in
C:\tomcat6\logs\catalina.*.
• If you happen to find that your import is failing due to system running out of memory,
however, there's an easy, SQL Server specific fix. Add responseBuffering=adaptive and
selectMethod=cursor to the url attribute of the dataSource node in data-config.xml. That stops the
JDBC driver from trying to load the entire result set into memory before reads can occur.
• Note that by default the index gets created in C:\Tomcat6\bin\solr\data\index. To change this path
just edit solrconfig.xml & change <dataDir>${solr.data.dir:./solr/data}</dataDir>.
• In new Solr versions, I think 3.0 and above you have to place the 2 data import handler
jars in your solr lib directory (i.e. for example apache-solr-dataimporthandler-3.3.0.jar & apache-
solr-dataimporthandler-extras-3.3.0.jar). Search for them in your Solr zip you downloaded. In older
Solr versions this is not required because they are bundled with solr.war. Since we have placed the
data import handlers in the lib directory so we need to specify their paths in solrconfig.xml. Add
this line to solrconfig.xml: (Example: <lib dir="C:/solr/lib/" regex="apache-solr-dataimporthandler-
\d.*\.jar" />)
Run Code Online (Sandbox Code Playgroud)