zoukankan      html  css  js  c++  java
  • FileListEntityProcessor

    一个简单的实体处理程序,可以用于枚举标准文件系统中的文件列表,它不需要使用DataSource.属性如下:

    • fileName:(必填) 用正则表达式来标记文件名
    • baseDir:(必填) 基础目录,绝对路径.
    • recursive:是否递归文件列表,默认为false.
    • excludes:不包括的文件名的正则表达式
    • newerThan:日期参数,格式: (yyyy-MM-dd HH:mm:ss),它也可以是一个数学日期,如('NOW-3DAYS'),其中的单引号是必填的.也可以是一个有效的变量格式,如(${var.name}).
    • olderThan :日期格式,规则同上.
    • biggerThan:整型参数.
    • smallerThan:整型参数.
    • rootEntity:它一般情况下都是false(除非你只索引文件名).直属于<document>下的实体才是根实体.那就意味着,根实体发出的每一行都会被solr/lucene创建.但是在这种情况下,我们不希望一个文件对应一个文档(document).我们希望生成一个文档(document),每一行的发出都是由下面的实体'x'来完成的.因为实体'f'包含了rootEntity=false,直属实体f下的实体就变成了一个根实体.
    • dataSource:这里不需要数据源,因此可以设置为null.

    例1:

    <dataConfig>
        <dataSource type="FileDataSource" />
        <document>
            <entity name="f" processor="FileListEntityProcessor" baseDir="/some/path/to/files"
                fileName=".*xml" newerThan="'NOW-3DAYS'" recursive="true" rootEntity="false"
                dataSource="null">
                <entity name="x" processor="XPathEntityProcessor" forEach="/the/record/xpath"
                    url="${f.fileAbsolutePath}">
                    <field column="full_name" xpath="/field/xpath" />
                </entity>
            </entity>
        </document>
    </dataConfig>

     例2:从文件列表中读取文件内容,并将文件名称处理掉文件名后缀.

    <dataConfig>
        <script><![CDATA[
            id = 1;
            function GenerateId(row) {
                row.put('id', (id ++).toFixed());
                return row;
            } 
            function WipOffHtml(row) {
                var file = row.get('file');
                row.put('file',file.substr(0,file.indexOf('.')));
                return row;
            }          
           ]]>
        </script>
        <dataSource name="binFile" type="BinFileDataSource" />
        <document>
            <entity name="f" processor="FileListEntityProcessor" baseDir="D:/solr/source_data/ah/"
                recursive="true" fileName=".*.html" rootEntity="false" dataSource="null"
                transformer="script:WipOffHtml">
                <field column="file" name="title" />
                <entity processor="TikaEntityProcessor" name="tika"
                    dataSource="binFile" url="${f.fileAbsolutePath}" format="text"
                    transformer="HTMLStripTransformer,RegexTransformer,script:GenerateId">
                    <field column="id" name="id" />
                    <field column="text" name="content" stripHTML="true" regex="	|
    |
    |s"
                        replaceWith="" />
                </entity>
            </entity>
        </document>
    </dataConfig>

    注意:不要丢失rootEntity这个属性.FileListEntityProcessor 产生的隐式字段是:fileDir,file,fileAbsolutePath,fileSize,fileLastModified ,

    这些变量在实体x中都是可以使用的.应该注意的是FileListEntityProcessor返回的是文件路径列表,所以子实体必须使用FileDataSource 来获取文件内容.

    不当之处,敬请指正!

  • 相关阅读:
    动态规划_leetcode416
    动态规划_leetcode377
    基础整理
    super使用简介
    PHP替换指定字符串
    yii安装redis扩展(Windows)
    PHP多维数组去重
    git pull
    vue页面部署并移除url里面的#号
    fatal: refusing to merge unrelated histories(git pull)
  • 原文地址:https://www.cnblogs.com/a198720/p/4267001.html
Copyright © 2011-2022 走看看