【问题标题】:Anyone configured apache solr FieldReaderDataSource?有人配置过 apache solr FieldReaderDataSource 吗?
【发布时间】:2012-05-28 13:17:47
【问题描述】:

我有一个包含 xml 的数据库列,我想在该列中使用 apache solr 内容进行索引,我有以下 data-config.xml(配置)。数据库名是“solrdb”,列名是“xmlfield”,好像有问题,错误在底部说明。

<dataConfig>
        <!--Data source to connect to database-->
        <dataSource 
            name="XmlDocDS" 
            type="JdbcDataSource" 
            driver="com.mysql.jdbc.Driver" 
            url="jdbc:mysql://127.0.0.1/solrdb" 
            user="root" 
            password="root" /> 
        <!-- Data Source for getting xml columne data-->    
        <dataSource 
            name="solrFieldReaderDS" 
            type="FieldReaderDataSource"/>
        <document>
            <entity 
                name="xmltable"
                rootEntity="false"
                datasource="XmlDocDS"
                query="select xmlfield from xmltable">
                <field column="xmldata" blob="true" />
                <entity 
                    name="page" 
                    dataSource="solrFieldReaderDS" 
                    dataField="xmltable.xmldata"                 
                    processor="XPathEntityProcessor"             
                    forEach="/page"> 
                    <field column="id" xpath="/mediawiki/page/id"/> 
                    <field column="Title" xpath="/mediawiki/page/title"/> 
                </entity> 
            </entity>
        </document>
</dataConfig>

错误如下:

SEVERE: Exception while processing: xmltable document : null:org.apache.solr.handler.dataimport.DataImportHandlerException: Unable to execute query: select xmlfield from xmltable Processing Document # 1

【问题讨论】:

    标签: search solr datasource


    【解决方案1】:

    在这部分 JDBC 导入器代码中抛出错误:

    try {
        Connection c = getConnection();
        stmt = c.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        stmt.setFetchSize(batchSize);
        stmt.setMaxRows(maxRows);
        LOG.debug("Executing SQL: " + query);
        long start = System.currentTimeMillis();
        if (stmt.execute(query)) {
          resultSet = stmt.getResultSet();
        }
        LOG.trace("Time taken for sql :"
                + (System.currentTimeMillis() - start));
        colNames = readFieldNames(resultSet.getMetaData());
      } catch (Exception e) {
        wrapAndThrow(SEVERE, e, "Unable to execute query: " + query);
      }
    

    所以连接或查询可能会出错(DB 有问题吗?)。还有“执行 SQL”和“sql 所用时间:”的 grep 日志

    【讨论】:

      【解决方案2】:

      连接出错,由于某种原因,它无法连接到我的本地计算机,我更改了数据库主机并连接了!问题是我已经进行了配置并且 FieldReaderDataSource 似乎工作正常,但是现在当它完成所有内容时,它说文档索引/更新= 0

      这是我的xml配置

      <dataSource
              name="jdbcDataSource"
              driver="com.mysql.jdbc.Driver"
              url="xxxx"
              user="yyyy"
              password="zzzz" readOnly="true"/>
      
              <dataSource 
                  name="solrFieldReaderDS" 
                  type="FieldReaderDataSource"/>
              <document>
                  <entity
                      name="tabledata"
                      dataSource="jdbcDataSource"
                      query="select codeID,codeText from ArticlePoolState where codeID=3">
                      <entity 
                          name="xmldata" 
                          dataSource="solrFieldReaderDS" 
                          forEach="/med"
                          dataField="tabledata.codeText"               
                          processor="XPathEntityProcessor"> 
                          <field column="title" xpath="/title"/> 
                      </entity>
                  </entity>
              </document>
      

      查询没问题。

      【讨论】:

        猜你喜欢
        • 2023-04-06
        • 2012-04-19
        • 1970-01-01
        • 2015-08-12
        • 2023-03-31
        • 2014-05-13
        • 1970-01-01
        • 2012-04-18
        相关资源
        最近更新 更多