Solr: Does the PatternReplaceFilterFactory able to

2019-09-01 21:20发布

I have indexed the data from solr.xml and monitor.xml that came with the solr package, and I added the below configuration in the schema.xml file

<field name="my_field" type="my_field_type" indexed="true" stored="true" required="false"/>
<copyField source="name" dest="my_field" />
<fieldType name="my_field_type" class="solr.TextField">
      <analyzer type="index">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.PatternReplaceFilterFactory" pattern=".*" replacement="NameChanged" replace="all" />
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
</fieldType>

It copies the (name) field to (my_field) of the fieldType (my_field_type). In the (my_field_type), I used PatternReplaceFilterFactory trying to replace everything with the string "NameChanged". The result is that it did copy the (name) field and its value to (my_field), but the value still stays the same.For example the below returned results with the (name) and (my_field) fields, the values of those two fields are the same, it didn't change the value to "NameChanged" for the field (my_field)

<?xml version="1.0" encoding="UTF-8"?>
<response>

<lst name="responseHeader">
  <int name="status">0</int>
  <int name="QTime">2</int>
  <lst name="params">
    <str name="fl">id,name,my_field,</str>
    <str name="indent">true</str>
    <str name="q">*:*</str>
    <str name="_">1380593840070</str>
    <str name="wt">xml</str>
  </lst>
</lst>
<result name="response" numFound="2" start="0">
  <doc>
    <str name="id">SOLR1000</str>
    <str name="name">Solr, the Enterprise Search Server</str>
    <str name="my_field">Solr, the Enterprise Search Server</str></doc>
  <doc>
    <str name="id">3007WFP</str>
    <str name="name">Dell Widescreen UltraSharp 3007WFP</str>
    <str name="my_field">Dell Widescreen UltraSharp 3007WFP</str></doc>
</result>
</response>

So, does the PatternReplaceFilterFactory able to replace the field value for copyField and then index it? If yes, what did I do wrong in the above configuration?

1条回答
淡お忘
2楼-- · 2019-09-01 21:38

The analyzer chain is for tokenized (searchable) representation of the field. The result you are showing is for original stored representation. That's why you will not see any changes that way.

Instead, check the tokenized representation in Admin interface either in field analyzer screen or in schema description field (one with checkmark to load tokens). Or, for a quick test, use my_field as a facet, as facet uses the actual tokens.

If you are trying to change the actual stored representation, as well as indexed one, you are better off with UpdateRequestProcessor chain using CloneFieldUpdateProcessorFactory and RegexReplaceProcessorFactory. That's defined in solrconfig.xml and applies on the document before it is stored/indexed at all.

查看更多
登录 后发表回答