在Solr中的两个不相关的表上创建索引 [英] Create index on two unrelated table in Solr

查看:177
本文介绍了在Solr中的两个不相关的表上创建索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to create index between two tables, stock and auction. Basically I am working on a product site. So I have to create index on both tables. and they are not related at all.

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

In data-config.xml, that I created to create index, I wrote the following code

<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包含以下字段。

and the schema.xml contains the fields are given below.

 <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中的表。如果我创建了两个如下所示的实体元素,那么就不会创建索引。

But this way the indexes are being created in wrong way as I put the other table data into the first table in data-config.xml. If I create two entity element like given below then the indexes are not being created.

<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>

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

I did not get your answer, can you pls elaborate a little more. I also have the same requirement. I have two tables stock and auction. Basically I am working on a product site. So I have to create index on both tables. and they are not related at all.

请帮助

推荐答案

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

Do you get any errors when indexing the data ??

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

The following data config is fine as you have two unrelated items.

<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>

然而,缺少一些东西?

However, there are few things missing ?


  • 该实体的 id 字段是什么?由于每个文档都应具有唯一的ID,因此上面的配置似乎缺失。

  • 此外, id 对于entites而言应该是unqiue,否则股票和拍卖应该相互覆盖。

  • 所以你可能希望id附加为stock_&拍卖_

  • 您还可以将静态字段作为库存和拍卖添加到您的架构中并填充它们,这将有助于您在搜索时过滤掉结果,从而提高性能。

  • Whats the id field for the entity ? As each document should have a unique id, the configuration seems missing above.
  • Also the id should be unqiue for the entites, else the stock and auction should overwrite each other.
  • So you may want the id append as stock_ & auction_
  • You can also add a static field as Stock and auction to your schema and populate them, which would help you the filter out the results when searching and hence improve the performance.

用于分配ID -

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

You can use the following to create the id value - This should append the Stock_ with the ST_StockID field value.

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

OR

在sql中使用别名,例如选择'Stock_'|| ST_StockID作为ID .....作为使用 -

Use alias in sql e.g. SELECT 'Stock_' || ST_StockID AS ID ..... as use -

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

这篇关于在Solr中的两个不相关的表上创建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆