apache - 使用 Apache Solr 检索提取的文本

标签 apache cell solr apache-tika

我是 Apache Solr 的新手,我想用它来索引 pdf 文件。到目前为止,我设法启动并运行它,现在我可以搜索添加的 pdf 文件。

但是,我需要能够从结果中检索搜索到的文本。

我在默认的 solrconfig.xml 中找到了一个与此完全相关的 xml 片段:

<requestHandler name="/update/extract" class="org.apache.solr.handler.extraction.ExtractingRequestHandler" startup="lazy">
<lst name="defaults">
  <!-- All the main content goes into "text"... if you need to return
       the extracted text or do highlighting, use a stored field. -->
  <str name="fmap.content">text</str>
  <str name="lowernames">true</str>
  <str name="uprefix">ignored_</str>

  <!-- capture link hrefs but ignore div attributes -->
  <str name="captureAttr">true</str>
  <str name="fmap.a">links</str>
  <str name="fmap.div">ignored_</str>
</lst>

根据我从这里 (http://www.lucidimagination.com/Community/Hear-from-the-Experts/Articles/Content-Extraction-Tika) 获得的信息,我认为我必须向模式添加一个新字段具有 stored="true"和 indexed="true"的 .xml(例如“内容”)。但是,我不太确定如何准确地完成此操作?

感谢任何帮助,thx

最佳答案

添加如下所示的 schema.xml:

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

<schema name="whatever" version="1.2">
    <types>
        <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
        <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
        <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
        <fieldType name="long" class="solr.TrieLongField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
        <fieldType name="double" class="solr.TrieDoubleField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
        <fieldType name="date" class="solr.TrieDateField" omitNorms="true" precisionStep="0" positionIncrementGap="0"/>
        <fieldType name="text" class="solr.TextField" positionIncrementGap="100">
            <analyzer type="index">
                <charFilter class="solr.HTMLStripCharFilterFactory"/>
                <charFilter class="solr.MappingCharFilterFactory" mapping="../../mapping-ISOLatin1Accent.txt"/>
                <tokenizer class="solr.StandardTokenizerFactory"/>
                <filter class="solr.StandardFilterFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
            </analyzer>
            <analyzer type="query">
                <charFilter class="solr.HTMLStripCharFilterFactory"/>
                <charFilter class="solr.MappingCharFilterFactory" mapping="../../mapping-ISOLatin1Accent.txt"/>
                <tokenizer class="solr.StandardTokenizerFactory"/>
                <filter class="solr.StandardFilterFactory"/>
                <filter class="solr.LowerCaseFilterFactory"/>
            </analyzer>
        </fieldType>
    </types>
    <fields>
        <field name="internal_id" type="string" indexed="true" stored="true"/>
        <field name="cat" type="int" indexed="true" stored="true"/>
        <field name="desc" type="text" indexed="true" stored="true"/>
    </fields>
    <uniqueKey>internal_id</uniqueKey>
    <defaultSearchField>desc</defaultSearchField>
    <solrQueryParser defaultOperator="OR"/>
    <similarity class="org.apache.lucene.search.DefaultSimilarity"/>
</schema>

如果“字段”被“存储”,默认情况下它将显示在结果中。

关于apache - 使用 Apache Solr 检索提取的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4948587/

相关文章:

solr - 使用 solr 6.4.1 配置 Tesseract

apache - 此请求在主机 "/"上请求 "example.com",但没有配置可以满足此请求的站点

swift - UICollectionViewCell 内的文本字段重用文本

ios - 如何使 UITableViewCell 居中,约束无法对齐

excel - 用单元格确定形状位置

java - ElasticSearch 相当于 Solr getBeans

apache - Nginx 重定向与其他端口冲突

apache - httpd 在内部运行但不在外部运行

php - imagesx() 期望参数 1 为资源, bool 值给定

solr - 如何在Solr中编写嵌套的schema.xml?