首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Solr中使用数据导入处理程序编制索引时提取文件名(不带扩展名)

在Solr中使用数据导入处理程序编制索引时提取文件名(不带扩展名)
EN

Stack Overflow用户
提问于 2013-07-03 12:48:01
回答 1查看 1.2K关注 0票数 1

我可以使用solr 4.3.0中的数据导入处理程序成功地索引pdf、doc、ppt等文件。

我的data-config.xml看起来像这样-

代码语言:javascript
复制
<dataConfig>
    <dataSource name="bin" type="BinFileDataSource" />
    <document>
        <entity name="f" dataSource="null" rootEntity="false"
            processor="FileListEntityProcessor"
            baseDir="C:\Users\aroraarc\Desktop\Impdo" 
            fileName=".*\.(DOC)|(PDF)|(pdf)|(doc)|(docx)|(ppt)|(pptx)|(xls)|(xlsx)|(txt)" onError="skip"
            recursive="true">

            <field column="fileAbsolutePath" name="path" />
            <field column="fileSize" name="size" />
            <field column="fileLastModified" name="lastmodified" />
            <field column="file" name="fileName"/>

             <entity name="tika-test" dataSource="bin" processor="TikaEntityProcessor"
            url="${f.fileAbsolutePath}" format="text" onError="skip">
                <field column="Author" name="author" meta="true"/>
                <field column="title" name="title" meta="true"/>
                <field column="text" name="content"/>

          </entity>
        </entity>
    </document>
</dataConfig>

但是,在fileName字段中,我想插入不带扩展名的纯文件名。例如,我只想在fileName字段中插入'HelloWorld‘,而不是’fileName‘。我该如何实现这一点?

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-03 13:07:13

选中ScriptTransformer可在索引之前替换或更改该值。

示例:

数据配置-添加自定义字段-

代码语言:javascript
复制
<script><![CDATA[
        function changeFileName(row){
            var fileName= row.get('fileName');
            // Replace or remove the extension .. e.g. from last index of . 
            file_name_new = file_name.replace ......
            row.put(fileName, row.get('file_name_new'));
            return row;
        }
]]></script>

实体映射-

代码语言:javascript
复制
<entity name="f" transformer="script:changeFileName" ....>
    ......
</entity>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17439874

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档