2013-09-26 155 views
0

我想在我的Lucene索引中索引2個不同的實體(本例中是SQL中的2個表)。一張包含產品,另一張包含新聞。Solr,多個索引

爲了能夠使用相同的搜索方法(查詢)來搜索產品和新聞項目,我知道他們必須在同一個索引中,所以Solr的幾個核心設置將無法正常工作 - 對嗎?

在data-config.xml中,我已經定義了2個具有相應實體的文檔類型。

在schema.xml中,我也爲產品和新聞項定義了字段。 在我的數據庫設計(表格)中,我的產品表的唯一關鍵字稱爲「ProductID」,其中我的新聞項目的唯一關鍵字稱爲「Id」(由我使用的CMS製作)。

在data-config.xml中,我應該只將我的唯一ID映射到相同的「名稱」。這是否能夠完成這項工作?

我遵循正確的方法嗎?

我在想什麼的例子;

數據-config.xml中

<!-- Products --> 
<document name="products"> 
    <entity name="product" dataSource="sqlServer" pk="ProductID" query="SELECT 
     ProductID, 
     ProductNumber, 
     ProductName, 
     FROM EcomProducts"> 
     <field column="ProductID" name="**Id**"/> 
     <field column="ProductNumber" name="ProductNumber"/> 
     <field column="ProductName" name="ProductName"/> 
    </entity> 
    </document> 

<!-- News items ---> 
    <document name="newsitems"> 
    <entity name="newsitems" dataSource="sqlServer" pk="id" query="SELECT 
     Id, 
     NewsItemTitle, 
     NewsItemContent, 
     FROM ItemType_NewsItems"> 
     <field column="Id" name="**Id**"/> 
     <field column="NewsItemTitle" name="NewsItemTitle"/> 
     <field column="NewsItemContent" name="NewsItemContent"/> 
    </entity> 
    </document> 

schema.xml中

<!-- Products ---> 
<field name="**Id**" type="text_general" indexed="true" stored="true" required="true" /> 
<field name="ProductNumber" type="text_general" indexed="true" stored="true" required="false" /> 
<field name="ProductName" type="text_general" indexed="true" stored="true" required="false" multiValued="false"/> 

<!-- Tips og fif --->  
<field name="**Id**" type="text_general" indexed="true" stored="true" required="true" /> 
<field name="NewsItemTitle" type="text_general" indexed="true" stored="true" required="false" /> 
<field name="NewsItemContent" type="text_general" indexed="true" stored="true" required="false" /> 

標識

回答

0

如果你想搜索他們在一起,我會的元數據映射到公共架構。也許ProductName和NewItemTitle會出現在「標題」字段中。一些元數據對於每種類型都是唯一的。或者您可以將信息索引兩次,一次是ProductName,一次是標題。

除非您可以確定ID始終在兩個來源中始終是唯一的,否則您可能需要爲它們加前綴。有一個標記每個文檔類型的字段也非常方便。這允許只搜索一種類型,並且在DIH中,可以使用它僅刪除一種類型。

在SQL中,您可以添加列如下:

concat('product-',cast(ProductId as char)) as id, 
'product' as type, 

也就是說MySQL的語法,它可能需要調整對SQLServer的。

+0

謝謝Walter。在我的數據配置實體中,我將兩個實體的id映射到字段「Id」,並將productName和itemName映射到「Name」字段。 在架構中,我將幾個字段複製到一個名爲「text」的text_general字段中,並將defaultSearchField設置爲該字段。 所以我的jQuery對象現在由來自產品和項目的字段組成。 – egeek