簡體   English   中英

思考獅身人面像和否定ID

[英]Thinking Sphinx and negative IDs

我有一個User模型和一個Message模型,用戶可以在其中相互發送消息,並且我使用Think Sphinx gem進行全文搜索,並將其作為Ruby on Rails中Sphinx搜索的連接器。

在我的User模型中,系統用戶使用負ID,普通用戶使用正ID。

現在,我sender_id了一個問題,即獅身人面像似乎忽略了具有負ID(=- has sender_id外鍵sender_id )的用戶對/向用戶的消息中的搜索。

在我的Message模型中定義的索引:

define_index 'messages_index' do
  indexes title, :sortable => true
  indexes body

  has sender_id, recipient_id, created_at, updated_at
end

搜索在MessagesController完成:

@received_messages = current_user.received_messages.search params[:q]

如果current_user的ID為負,則不會返回任何結果。 當我reindex它表明所有Sphinx都收集了所有消息,沒有一個被遺漏。

有什么辦法教Sphinx接受has -Attributes的負數? 或任何解決方法的想法?

Sphinx的整數類型是無符號的,因此不會收集您的負值。

您可以將類型強制為浮點型,但不要忘記對這些屬性浮點型也進行任何過濾:

has sender_id, recipient_id, :type => :float
has created_at, updated_at

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM