SOLR托管架构,如何使用它?

问题描述 投票:2回答:2

我让我的SOLR工作,并且它工作正常,但我不知道究竟什么样的托管架构,因为我确实使用了默认版本,其中我添加了几行,我需要我的案例

<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="name" type="text_general" indexed="true" stored="true" default="" />
<field name="brand_id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="brand_name" type="text_general" indexed="true" stored="true" default="" />
<field name="type" type="string" indexed="true" stored="true" required="true" default="0"  />

我不能包含完整的文件,因为它像700行...但完整的xml在这里http://pastebin.com/Z9nc36QD

我是否必须将所有内容保留为默认示例?我不知道......你有一个典型的模式文件的例子吗?

solr
2个回答
4
投票

托管架构应该通过Schema API进行操作,而不是通过编辑存在的文件(其中包括有关这样做的警告)。 schema.xml文件仅在第一次启动时读取一次以创建初始模式,之后的任何更改都必须通过模式API完成。

如果要使用类似旧版Solr版本的schema.xml文件而没有任何Schema API支持,则可以在solrconfig.xml文件中使用ClassicIndexSchemaFactory。见Schema Factory Definition

<schemaFactory class="ClassicIndexSchemaFactory"/>

使用托管架构的替代方法是显式配置ClassicIndexSchemaFactory。 ClassicIndexSchemaFactory需要使用schema.xml配置文件,并且不允许在运行时对Schema进行任何编程更改。 schema.xml文件必须手动编辑,并且仅在加载集合时才加载。

您只需要保留实际使用的模式部分,并且示例模式(取决于用户开始使用的模式)通常会包含许多您不需要的字段和字段。这些可以在需要之前删除,并且可以调整字段类型以启用所需的功能。

但是请记住,对架构的更改将需要重新编制索引内容,以便在搜索时可以看到更改。

您必须使用精确的架构设计并进行实验,以便您能够获得所需的查询配置文件和功能。


1
投票

您应该使用Solr的Schema API。更多信息可以在这里找到:https://lucene.apache.org/solr/guide/7_2/schema-api.html

它基本上意味着你从shell发出curl -X POST(到localhost)来编辑文件。

例:

:curl -X POST -H 'Content-type:application/json' --data-binary '{
 "add-field-type" : {
 "name":"myNewTxtField",
 "class":"solr.TextField",
 "positionIncrementGap":"100",
 "analyzer" : {
    "charFilters":[{
       "class":"solr.PatternReplaceCharFilterFactory",
       "replacement":"$1$1",
       "pattern":"([a-zA-Z])\\\\1+" }],
    "tokenizer":{
       "class":"solr.WhitespaceTokenizerFactory" },
    "filters":[{
       "class":"solr.WordDelimiterFilterFactory",
       "preserveOriginal":"0" }]}}
}' http://localhost:8983/solr/gettingstarted/schema`

个人评论

它是2018年,实际上应该只是来自现有管理控制台的Web界面来构建和发布这些localhost命令。我知道,如果有一个动物园管理员,事情会变得棘手,但对单个服务器的基本探索应该是微不足道的,而目前却不是。这种方法将显示格式化的curl命令,因此它将训练新开发人员正确使用。

开发人员必须将xml从这样的文档转换为POST的正确json。

<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100"> 
  <analyzer type="index"> 
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" ignoreCase="true"
        words="stopwords.txt" />
    <!-- in this example, we will only use synonyms at query time
    <filter class="solr.SynonymFilterFactory"
      synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
    -->
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
  <analyzer type="query">
    <tokenizer class="solr.StandardTokenizerFactory"/>
    <filter class="solr.StopFilterFactory" 
      ignoreCase="true" words="stopwords.txt" />
    <filter class="solr.SynonymFilterFactory" 
      synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
    <filter class="solr.LowerCaseFilterFactory"/>
  </analyzer>
</fieldType>
© www.soinside.com 2019 - 2024. All rights reserved.