Thinking Sphinx and negative IDs

依然范特西╮ 提交于 2019-12-11 05:28:10

问题


I have a Usermodel and a Message model where users can send messages to each other, and I use Thinking Sphinx gem for fulltext search as connector for Sphinx Search in Ruby on Rails.

In my User model I use negative IDs for system users, positive IDs for regular users.

Now I have the problem that Sphinx seems to ignore searches in messages by/to users with those negative IDs (=foreign key sender_id as has-Attribute).

Index as definded in my Message model:

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

  has sender_id, recipient_id, created_at, updated_at
end

The search is done in the MessagesController:

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

If the current_user has a negative ID no result is returned. When I do a reindex it shows that all Sphinx collected all messages, none were left out.

Is there any way to teach Sphinx to accept negative numbers for has-Attributes? Or ideas for any work-around?


回答1:


Sphinx's integer type is unsigned, so your negative values aren't collected.

You could force the type to be a float, but don't forget to make any filters on those attributes floats as well:

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


来源:https://stackoverflow.com/questions/24493012/thinking-sphinx-and-negative-ids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!