【问题标题】:How to retain HTML coding while indexing HTML documents to Apache Solr?如何在将 HTML 文档索引到 Apache Solr 时保留 HTML 编码?
【发布时间】:2020-12-18 00:57:02
【问题描述】:

我正在通过命令行上的 SimplePostTool 将 HTML 文档索引到 Solr,

post -c core0 /mnt/Vancouver/programming/datasci/solr/test/d*.html

尽管对 solrconfig.xml 和 schema.xml(solr.HTMLStripCharFilterFactory 等)进行了各种编辑,但 Solr 不会保留 HTML 源文档中存在的 HTML 内容(URL)。

A new <a href="https://news.ucr.edu/articles/2020/11/06/chemicals-your-living-room-cause-diabetes">UC Riverside study</a> shows flame retardants ...

在 Solr 中显示为

"p":[" A new https://news.ucr.edu/articles/2020/11/06/chemicals-your-living-room-cause-diabetes UC Riverside study shows ...

似乎 Apache Tika 正在从 HTML 中的内容中剥离 HTML 编码

元素,在传递给 Solr 之前。

https://lucene.apache.org/solr/guide/8_7/uploading-data-with-solr-cell-using-apache-tika.html#key-solr-cell-concepts



呈现的网页(注意,例如,一个新的 https://news.ucr.edu/articles/2020/11/06/chemicals-your-living-room-cause-diabetes UC Riverside 研究 ... i> 在第一个文件中)

【问题讨论】:

    标签: solr apache-tika


    【解决方案1】:

    更新:这是一种解决方法。


    url_process.sh

    #!/bin/bash
    
    cd /mnt/Vancouver/programming/datasci/solr/test/url_test/
    
    for FILE in *.html
    do
      cat $FILE | sed 's/<a href/LEFTANGLEBRACKETa href/g ; s%</a>%LEFTANGLEBRACKET/a>%g' > tmp
      post -c core0 tmp
    done
    

    solrconfig.xml

      <updateRequestProcessorChain
        processor="uuid,remove-blank,field-name-mutating,
        parse-boolean,parse-long,parse-double,parse-date">
    
        <processor class="solr.LogUpdateProcessorFactory"/>
        <processor class="solr.DistributedUpdateProcessorFactory"/>
    
        <processor class="solr.RegexReplaceProcessorFactory">
          <str name="fieldName">p</str>
          <str name="pattern">LEFTANGLEBRACKET</str>
          <str name="replacement">&lt;</str>
          <bool name="literalReplacement">true</bool>
        </processor>
    
        <processor class="solr.RunUpdateProcessorFactory"/>
      </updateRequestProcessorChain>
    

    说明

    我通过以下方式颠覆 Apache Tika 预处理:

    • 使用 BASH 脚本预处理 HTML 源文档,将 &lt;a href="..."&gt;...&lt;/a&gt; 中的所有 &lt; 替换为字母字符串。这会混淆来自 Tika 的那些链接。

    • 在建立索引时,solrconfig.xml 中的 RegexReplaceProcessorFactory 处理器交换回那些 &lt; 括号,重新生成 URL。


    结果

    Solr:

    "p":[" A new <a href=\"https://news.ucr.edu/articles/2020/11/06/chemicals-your-living-room-cause-diabetes\">UC Riverside study</a> shows flame retardants ...],"
    

    一个有效的超链接现在出现在 Ajax 呈现的网页中。

    【讨论】:

      猜你喜欢
      • 2012-10-22
      • 2021-03-02
      • 1970-01-01
      • 2013-01-20
      • 2010-12-27
      • 2016-07-24
      • 1970-01-01
      • 2016-05-09
      • 1970-01-01
      相关资源
      最近更新 更多