Solr 配置文件之schema.xml
发布时间:2020-12-16 08:59:25 所属栏目:百科 来源:网络整理
导读:schema.xml 这个配置文件的根本目的是为了通过配置告诉Solr如何建立索引。 solr的数据结构如下: document:一个文档、一条记录 field:域、属性 solr通过搜索某个或某些field,返回若干个符合条件的document,或者按搜索的score排序返回。 如果跟数据库对比
schema.xml这个配置文件的根本目的是为了通过配置告诉Solr如何建立索引。
solr的数据结构如下:
solr通过搜索某个或某些field,返回若干个符合条件的document,或者按搜索的score排序返回。
如果跟数据库对比,document相当于数据库的表,field相当于表中的字段。而schema.xml就是为了定义一个表的结构(定义各个field的名字、类型、约束、等等)。
schema.xml的基本结构如下:
<schema>
<types>
<fields>
<uniqueKey>
<copyField>
</schema>
常用的配置说明:
一个简单的例子:
<?xml version="1.0" encoding="UTF-8" ?> <schema name="course_video" version="1.5"> <field name="id" type="int" indexed="true" stored="true" required="true" multiValued="false" /> <field name="_version_" type="long" indexed="true" stored="true"/> <field name="title" type="string" indexed="true" stored="true" required="true" multiValued="false" /> <field name="tags" type="string" indexed="true" stored="false" required="false" multiValued="false" /> <field name="content" type="string" indexed="true" stored="true" required="false" multiValued="false" /> <field name="info_text" type="text_general" indexed="true" stored="false" multiValued="true" /> <copyField source="title" dest="info_text" /> <copyField source="content" dest="info_text" /> <copyField source="tags" dest="info_text" /> <uniqueKey>id</uniqueKey> <fieldType name="string" class="solr.StrField" sortMissingLast="true" /> <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/> <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100"> <analyzer type="index"> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> <analyzer type="query"> <tokenizer class="solr.StandardTokenizerFactory"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType> </schema>
注:solrconfig.xml配置文件中,requestHandler "/select"的缺省“df”是“text”。如果按照上面的配置,我们想要的缺省搜索info_text,所以需要在solrconfig.xml中修改:
<requestHandler name="/select" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="defType">edismax</str>
<str name="df">info_text</str>
</lst>
</requestHandler>
可以通过http api获取schema信息:
http://<ip>:8983/solr/<collection>/schema?wt=json
http://<ip>:8983/solr/<collection>/schema/fields?wt=json
http://<ip>:8983/solr/<collection>/schema/dynamicfields?wt=json
http://<ip>:8983/solr/<collection>/schema/copyfields?wt=json
(原创文章,转载请注明转自Clement-Xu的博客)
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |