2012-09-01 14 views
1

我一直在試圖讓獅身人面像通過鏈接2個索引來搜索2個表。這裏有這些指標的來源:用Sphinx查詢2個不同表的索引

source gSrc 
{ #General Source 
type     = mysql 

sql_host  = localhost 
sql_user  = (blahblahblah) 
sql_pass  = (blahblahblah) 
sql_db   = (blahblahblah) 
sql_port  = 3306 # optional, default is 3306 

sql_ranged_throttle = 0 
} 

source mentionActivitySrc : gSrc 
{ 
sql_query  = \ 
    SELECT id, author, thesis, body, created, updated \ 
    FROM activity 

sql_attr_uint  = id 
sql_attr_timestamp = updated 

sql_query_info  = SELECT * FROM activity WHERE id=$id 
} 

source mentionUserSrc : gSrc 
{ 
sql_query  = \ 
    SELECT id, first, last, username, email, updated \ 
    FROM user 

sql_attr_uint  = id 
sql_attr_timestamp = updated 

sql_query_info  = SELECT * FROM user WHERE id=$id 
} 

,並在這裏被索引自己:

index gIndex 
{ #General Index 
docinfo   = extern 
mlock   = 0 
morphology  = none 
min_word_len  = 1 
charset_type  = sbcs 
html_strip  = 0 
} 

index activityMentionIndex : gIndex 
{ 
source   = mentionActivitySrc 
path   = /var/lib/sphinxsearch/data/activityMentionIndex 
} 

index userMentionIndex : gIndex 
{ 
source   = mentionUserSrc 
path   = /var/lib/sphinxsearch/data/userMentionIndex 
} 

我使用sphinxapi.php,當我做

->query('some keywords', 'activityMentionIndex userMentionIndex'); 

領域指數返回的數組顯示它只識別第二個索引(在這種情況下,userMentionIndex,如果我切換它們,它將識別activityMentionIndex)

有人可以告訴我我可能做錯了什麼,或者如果有可能查詢2個不同表的2個索引?

回答

2

我很確定它搜索了兩個索引。就這樣

1)文檔ID需要是唯一的。因此,如果第二個索引中的文檔首先具有相同的ID,則只有第二個索引中的文檔會顯示在結果中。爲了解決這個問題,你需要安排id是唯一的。

2)它沒有嘗試合併字段列表(也沒有屬性) - 它只是使用最後一個。搜索多個索引的正常方法是使用相同的字段名稱(例如,在主+三角洲中),因此它沒有任何問題。

-

而且你

sql_attr_uint  = id 

是錯誤的。它不應該在那裏。文檔ID是自動的 - 它始終是mysql結果集中的第一列。獅身人面像應該足夠聰明,完全可以忽略它,但最好將其刪除以避免混淆。