(b).接下来的工作就是在fields结点内定义具体的字段(类似数据库中的字段),就是filed,filed定义包括name,type(为之前定义过的各种FieldType),indexed(是否被索引),stored(是否被储存),multiValued(是否有多个值)等等。
(2)重启tomcat,此时会报如下错误:org.apache.solr.common.SolrException: QueryElevationComponent requires the schema to
have a uniqueKeyField implemented using StrField。
此错误是因为solr版本高的问题,在低版本中不会出错,可以在solrconfig.xml 中删除两个结点(即Elevation 组件)解决此问题:
<!-- a search component that enables you to configure the top results for a given query regardless of the normal lucene scoring.--> <searchComponent name="elevator" class="solr.QueryElevationComponent" > <!-- pick a fieldType to analyze queries --> <str name="queryFieldType">string</str> <str name="config-file">elevate.xml</str> </searchComponent> <!-- a request handler utilizing the elevator component --> <requestHandler name="/elevate" class="solr.SearchHandler" startup="lazy"> <lst name="defaults"> <str name="echoParams">explicit</str> </lst> <arr name="last-components"> <str>elevator</str> </arr> </requestHandler>
手动在 E:/apache-solr-3.1.0/example/exampledocs 创建两个xml 数据文件。分别保存为 demo-doc1.xml 和 demo-doc2.xml,这两个文件中的内容要和schema.xml中定义的数据结构相一致,demo-doc1.xml如下:
<?xml version="1.0" encoding="UTF-8" ?> <add> <doc> <field name="id">1</field> <field name="user">chenlb</field> <field name="title">solr 应用演讲</field> <field name="content">这一小节是讲提交数据给服务器做索引,这里有一些数据,如:服务器,可以试查找它。</field> </doc> </add>
demo-doc2.xml:
<?xml version="1.0" encoding="UTF-8" ?> <add> <doc> <field name="id">2</field> <field name="user">bory.chan</field> <field name="title">搜索引擎</field> <field name="content">搜索服务器那边有很多数据。</field> <field name="timestamp">2009-02-18T00:00:00Z</field> </doc> <doc> <field name="id">3</field> <field name="user">other</field> <field name="title">这是什么</field> <field name="content">你喜欢什么运动?篮球?</field> <field name="timestamp">2009-02-18T12:33:05.123Z</field> </doc> </add>
windows默认文件文件是以ANSI编码,注意这两个文件一定要以UTF-8来保存,否则在提交生成索引时会报错
提交数据做索引,到 E:/apache-solr-3.1.0/example/exampledocs,运行:
E:/apache-solr-3.1.0/example/exampledocs>java -Durl=http://localhost:8080/solr/update -Dcommit=yes -jar post.jar demo-doc*.xmlSimplePostTool: version 1.2SimplePostTool: WARNING: Make sure your XML documents are encoded in UTF-8, other encodings are not currently supportedSimplePostTool: POSTing files to http://localhost:8080/solr/update..SimplePostTool: POSTing file demo-doc1.xmlSimplePostTool: POSTing file demo-doc2.xmlSimplePostTool: COMMITting Solr index changes..
此时到E:/apache-solr-3.1.0/example/solr/data/index目录下,可以发现和Lucene创建索引时产生的类似文件