虽然是一个老问题,但我在通过 Solr 8.7.0 索引 HTML 文档时也遇到了这个问题。
<requestHandler name="/update/extract"
class="org.apache.solr.handler.extraction.ExtractingRequestHandler">
....
HTML:
<p>My website is <a href="https://buriedtruth.com/">BuriedTruth.com</a>.</p>
Result:
My website is rect https://buriedtruth.com/ BuriedTruth.com .
[ 我在 Linux 命令行上发布/索引:solr restart; sleep 1; post -c gettingstarted /mnt/Vancouver/programming/datasci/solr/test/solr_test9.html;
]
我 grep (ripgrep:rg --color=always -w -e 'rect' . |less
)该单词的 Solr 代码,但什么也没找到,所以来源rect http...
索引 URL 中的内容让我困惑。
我的解决方案是添加一个正则表达式处理器到我的solrconfig.xml
:
<updateRequestProcessorChain name="add-unknown-fields-to-the-schema" default="${update.autoCreateFields:true}"
processor="uuid,remove-blank,field-name-mutating,parse-boolean,parse-long,parse-double,parse-date,add-schema-fields">
<processor class="solr.LogUpdateProcessorFactory"/>
<processor class="solr.DistributedUpdateProcessorFactory"/>
<!-- ======================================== -->
<!-- https://lucene.apache.org/solr/7_4_0/solr-core/org/apache/solr/update/processor/RegexReplaceProcessorFactory.html -->
<!-- Solr bug? URLs parse as "rect https..." Managed-schema (Admin UI): defined p as text_general -->
<!-- but did not parse. Looking at content | title: text_general copied to string, so added -->
<!-- copyfield of p (text_general) as p_str ... regex below now works! -->
<processor class="solr.RegexReplaceProcessorFactory">
<str name="fieldName">content</str>
<str name="fieldName">title</str>
<str name="fieldName">p</str>
<!-- Case-sensitive (and only one pattern:replacement allowed, so use as many copies): -->
<!-- of this processor as needed: -->
<str name="pattern">rect http</str>
<str name="replacement">http</str>
<bool name="literalReplacement">true</bool>
</processor>
<!-- ======================================== -->
<!-- This needs to be last (may need to clear documents and reindex to see changes, e.g. Solr Admin UI): -->
<processor class="solr.RunUpdateProcessorFactory"/>
</updateRequestProcessorChain>
正如我在该处理器中的评论中提到的,我正在提取<p />
- 将 HTML 内容格式化为p
field (field: p
| type: text_general
).
该内容无法解析RegexReplaceProcessorFactory
处理器。
在 Solr 管理 UI 中我注意到title
and content
被复制为字符串(例如:field: content
| type: text_general
| copied to: content_str
),所以我制作了复制字段(p
>>p_str
)解决了正则表达式问题。
为了完整起见,以下是我的相关部分solrconfig.xml
与 HTML 文档索引相关,
<lib dir="${solr.install.dir:../../..}/contrib/extraction/lib" regex=".*\.jar" />
<lib dir="${solr.install.dir:../../..}/dist/" regex="solr-cell-\d.*\.jar" />
<!-- https://lucene.472066.n3.nabble.com/Prons-an-Cons-of-Startup-Lazy-a-Handler-td4059111.html -->
<!-- startup="lazy" -->
<requestHandler name="/update/extract"
class="org.apache.solr.handler.extraction.ExtractingRequestHandler">
<lst name="defaults">
<str name="lowernames">true</str>
<str name="uprefix">ignored_</str>
<str name="capture">div</str>
<str name="fmap.div">div</str>
<str name="capture">p</str>
<str name="fmap.p">p</str>
</lst>
</requestHandler>
...再次注意到我将字段添加到managed-schema
通过 Solr 管理 UI。
Result:
My website is https://buriedtruth.com/ BuriedTruth.com .
<field name="p" type="text_general" uninvertible="true" indexed="true" stored="true"/>
<copyField source="p" dest="p_str"/>
也可以看看: