• 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 来获取文件内容.

    不当之处,敬请指正!

  • 相关阅读:
    [转]Linq to SQL Like Operator
    [转]updatepanel中使用alert弹出框方法
    [转]MSDN 在客户端脚本中为 UpdateProgress 控件编程
    [转].NET Framework 3.5 SP1安装时下载文件问题及精简方法
    Vista系统下IIS安装 用以创建支持vs2008开发的网站
    asp.net 文本框输入时的自动完成
    [转]Raising An Event From CheckBox In A GridView (GridView中模板表的CheckBox的后台事件处理)
    I have my family
    拉了网线 多了机会
    【转】DataGridViewComboBoxColumn的使用
  • 原文地址:https://www.cnblogs.com/a198720/p/4267001.html
Copyright © 2020-2023  润新知