在Solr中的两个不相关的表上创建索引

时间:2011-11-16 07:11:05

标签: solr indexing lucene

我想在两个表,股票和拍卖之间创建索引。基本上我正在一个产品网站上工作。所以我必须在两个表上创建索引。他们根本没有关系。

在我创建索引的data-config.xml中,我编写了以下代码

<dataConfig>
    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/database" user="root" password=""/>
    <document name="content">
        <entity name="stock" query="select ST_StockID,ST_StockCode,ST_Name,ST_ItemDetail from stock where estatus = 'Active' limit 100">
            <field column="ST_StockID" name="stock_ST_StockID" />
            <field column="ST_StockCode" name="stock_ST_StockCode" />
            <field column="ST_Name" name="stock_ST_Name" />
            <field column="ST_ItemDetail" name="stock_ST_ItemDetail" />
        <entity name="auction" query="select iauctionid,rad_number,vsku,auction_code from auction limit 100">
            <field column="iauctionid" name="auction_iauctionid" />
            <field column="rad_number" name="auction_rad_number" />
            <field column="vsku" name="auction_vsku" />
            <field column="auction_code" name="auction_auction_code" />
        </entity>
        </entity>

    </document>
</dataConfig>

并且schema.xml包含以下字段。

 <field name="stock_ST_StockID" type="string" indexed="true" stored="true" required="true"/>
    <field name="stock_ST_StockCode" type="string" indexed="true" stored="true" required="true"/>
    <field name="stock_ST_Name" type="string" indexed="true" stored="true" required="true"/>
    <field name="stock_ST_ItemDetail" type="text" indexed="true" stored="true" required="true"/>

    <field name="auction_iauctionid" type="string" indexed="true" stored="true" required="true"/>
    <field name="auction_rad_number" type="string" indexed="true" stored="true" required="true"/>
    <field name="auction_vsku" type="string" indexed="true" stored="true" required="true"/>
    <field name="auction_auction_code" type="text" indexed="true" stored="true" required="true"/>

但是这种方式正在以错误的方式创建索引,因为我将其他表数据放入data-config.xml中的第一个表中。如果我创建两个如下所示的实体元素,那么就不会创建索引。

<dataConfig>
    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/lc" user="root" password=""/>
    <document name="content">
        <entity name="stock" query="select ST_StockID,ST_StockCode,ST_Name,ST_ItemDetail from stock where estatus = 'Active' limit 100">
            <field column="ST_StockID" name="stock_ST_StockID" />
            <field column="ST_StockCode" name="stock_ST_StockCode" />
            <field column="ST_Name" name="stock_ST_Name" />
            <field column="ST_ItemDetail" name="stock_ST_ItemDetail" />

        </entity>
        <entity name="auction" query="select iauctionid,rad_number,vsku,auction_code from auction limit 100">
            <field column="iauctionid" name="auction_iauctionid" />
            <field column="rad_number" name="auction_rad_number" />
            <field column="vsku" name="auction_vsku" />
            <field column="auction_code" name="auction_auction_code" />
        </entity>
    </document>
  </dataConfig>

我没有得到你的答案,你能再详细说明一下吗?我也有同样的要求。我有两张桌子和拍卖。基本上我正在一个产品网站上工作。所以我必须在两个表上创建索引。他们根本没有关系。

请帮忙

1 个答案:

答案 0 :(得分:0)

索引数据时是否会出现任何错误?

以下数据配置很好,因为您有两个不相关的项目。

<dataConfig>
    <dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/lc" user="root" password=""/>
    <document name="content">
        <entity name="stock" query="select ST_StockID,ST_StockCode,ST_Name,ST_ItemDetail from stock where estatus = 'Active' limit 100">
            <field column="ST_StockID" name="stock_ST_StockID" />
            <field column="ST_StockCode" name="stock_ST_StockCode" />
            <field column="ST_Name" name="stock_ST_Name" />
            <field column="ST_ItemDetail" name="stock_ST_ItemDetail" />

        </entity>
        <entity name="auction" query="select iauctionid,rad_number,vsku,auction_code from auction limit 100">
            <field column="iauctionid" name="auction_iauctionid" />
            <field column="rad_number" name="auction_rad_number" />
            <field column="vsku" name="auction_vsku" />
            <field column="auction_code" name="auction_auction_code" />
        </entity>
    </document>
</dataConfig>

然而,缺少一些东西?

  • 该实体的id字段是什么?由于每个文档都应具有唯一ID,因此上面似乎缺少配置。
  • 此外,id对于参与者来说应该是唯一的,否则股票和拍卖应该互相覆盖。
  • 所以你可能希望id附加为stock_&amp;拍卖_
  • 您还可以将静态字段作为Stock和auction添加到您的架构中并填充它们,这将有助于您在搜索时过滤掉结果,从而提高性能。

分配ID -

您可以使用以下命令创建id值 - 这应该将Stock_附加到ST_StockID字段值。

<field column="id" template="Stock_#${stock.ST_StockID}" />

OR

在sql中使用别名,例如SELECT 'Stock_' || ST_StockID AS ID .....使用 -

<field column="id" name="id" />