0

假设,我有几个字段的 Solr 文档。现在,出于某种特定原因,我必须修改其中一个字段的类型。我知道,修改该字段的“类型”后,我将无法使用该字段进行查询。我可以通过其他字段查询吗?

我的字段定义是

<field name="searchtag" type="text_general" indexed="true" stored="true"/>

新定义是

<field name="searchtag" type="text_ngram" indexed="true" stored="true" multivalued="true"/>

字段类型定义

    <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" enablePositionIncrements="true" />
        <!-- 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" enablePositionIncrements="true" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>

 <fieldType name="text_ngram" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.NGramFilterFactory" minGramSize="3" maxGramSize="15"/>
    </analyzer>
    <analyzer type="query">
                <tokenizer class="solr.StandardTokenizerFactory"/>
                <filter class="solr.StandardFilterFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>
    </fieldType>

谢谢

4

1 回答 1

0

我找到了答案。

我在 Solr-4.2.1 上的数据上尝试了一个小测试用例。正如我所说,以前“搜索标签”的类型是text_general。我拿了一个新的 Solr 实例。在那里,我将 searchtag 定义为 text_general 类型字段。我还定义了一些其他领域。然后我将一些数据索引到这些字段以及searchtag中。因为这是一种简单直接的方式,所以一切正常。我用 searchtag 和其他字段查询并得到了正确的结果。

然后我修改了 schema.xml。我将搜索标签的类型从 text_general 更改为text_ngram。修改架构后,我重新启动了 Solr 实例。现在,我实际上并没有关心为 searchtag 索引的数据。因为我弄乱了该字段的架构。因此,我在其他字段上执行了相同的查询。我很高兴我得到了与以前相同的 Solr 文档。虽然我使用了架构,但其他字段的其他索引完好无损。这就是我想要的。

希望,如果您像我一样遇到此类问题,此测试用例将对您所在的地区有所帮助。

注意:我已经提到了关于“searchtag”的架构定义和问题区域中的字段类型。

于 2014-03-05T06:17:11.963 回答