2012-07-24 54 views
0

我有一個MySQL數據庫,並命名爲數據表根據拆分規則,這意味着該名稱具有相同的前綴,如:the_table_,並具有後綴的數字,所以表名稱將是the_table_1,the_table_2,the_table_3 。當我們要選擇一排,我們必須找到從SQL SELECT MOD(primary_key_id,64)+1,分片規則表後綴,而64是一個基數,這意味着我們有64個表。Can Solr可以處理表table1,table2,... tableN中的表的數據導入嗎?

現在,我們希望在表格中使用Solr的索引數據,但數據的Solr-config.xml中無法支持動態名稱的SQL查詢,那麼,有沒有任何建議,以解決這個問題?

像這樣的事情?

<entity name="audit" 
     query="select id,monitor_type,city,STATUS,is_history,timeout,author,author_uid,author_ip,operator_uid,operator,created_at,description from `main_table`"> 
     <field column="ID" name="id" /> 
     <field column="MONITOR_TYPE" name="monitor_type" /> 
     <field column="CITY" name="city" /> 
     <field column="STATUS" name="status" /> 
     <field column="IS_HISTORY" name="is_history" /> 
     <field column="AUTHOR" name="author" /> 
     <field column="AUTHOR_UID" name="author_uid" /> 
     <field column="AUTHOR_IP" name="author_ip" /> 
     <field column="OPERATOR_UID" name="operator_uid" /> 
     <field column="OPERATOR" name="operator" /> 

     <entity name="distribution" query="select mod(${audit.ID}, 256)+1 as table_id"> 
      <entity name="details" query="select content from detail${distribution.table_id} where id=${audit.ID}"> 
      <field column="CONTENT" name="content" /> 
      </entity> 
     </entity> 
</entity> 

+0

您是否考慮過使用MySQL視圖爲Solr準備數據? – 2012-07-24 10:33:08

+0

您是否嘗試過使用佔位符?就像$ {dataimporter.tablename}一樣,並在調用dataimport url時傳遞tablename參數。 – javanna 2012-07-24 10:54:47

回答

1

我將創建一個存儲過程來完成你想要什麼,然後從Solr的調用它。這樣

CREATE PROCEDURE `GetAuditDetails`(IN auditID INT) 
BEGIN 
    DECLARE tableID INT DEFAULT 0; 
    DECLARE sqlString VARCHAR(100) DEFAULT ''; 
    SELECT MOD(auditID, 256)+1 INTO tableID; 
    SET @sqlString = CONCAT('select content from detail', tableID, ' where id=', auditID); 
    PREPARE stmt FROM @sqlString; 
    EXECUTE stmt; 
END; 

<entity name="audit" 
    query="select id,monitor_type,city,STATUS,is_history,timeout,author,author_uid,author_ip,operator_uid,operator,created_at,description from `main_table`"> 
     <field column="ID" name="id" /> 
     <field column="MONITOR_TYPE" name="monitor_type" /> 
     <field column="CITY" name="city" /> 
     <field column="STATUS" name="status" /> 
     <field column="IS_HISTORY" name="is_history" /> 
     <field column="AUTHOR" name="author" /> 
     <field column="AUTHOR_UID" name="author_uid" /> 
     <field column="AUTHOR_IP" name="author_ip" /> 
     <field column="OPERATOR_UID" name="operator_uid" /> 
     <field column="OPERATOR" name="operator" /> 

     <entity name="details" query="CALL GetAuditDetails(${audit.ID})"> 
      <field column="CONTENT" name="content" /> 
     </entity> 
</entity> 
+0

雖然有[R有毛病的mysql程序,但它確實解決了我的問題...謝謝...埃文感謝 – 2012-07-27 08:07:07

+0

,我更新了PROC。 – Evan 2012-08-03 19:37:54

0

第一的東西,它不應該在嵌套查詢入口使用audit.ID,但$ {} audit.id,否則會出現異常。 二,對於Mysql程序:

CREATE PROCEDURE `GetAuditDetails`(IN auditID INT) 
BEGIN 
    DECLARE tableID INT DEFAULT 0; 
    DECLARE sqlString VARCHAR(100) DEFAULT ''; 
    SELECT MOD(auditID, 256)+1 INTO tableID; 
    SET @sqlString = CONCAT('select content from detail', tableID, ' where id=', auditID); 
    PREPARE stmt FROM @sqlString; 
    EXECUTE stmt; 
END; 
相關問題