tags:

views:

69

answers:

3

Hello,

I used Sphinx plugin for searching and configure it

define_index do
  indexes First_name, :sortable => true
  set_property :min_prefix_len => 1
end

Here First_name is column name.

But I was getting error of "search daemon fails to run". And when I made the column name as symbol it runs perfectly.

define_index do
  indexes :First_name, :sortable => true
  set_property :min_prefix_len => 1
end

Please make it clear to me.

+4  A: 

http://www.robertsosinski.com/2009/01/11/the-difference-between-ruby-symbols-and-strings/

I think your example don't work because in first variant First_name is not a string. It's variable

"First_name" - will be a string

Falcon
A: 

indexes First_name, :sortable => true

here rails treat First_name as a constant variable not the column.

so you can use

indexes :First_name, :sortable => true

or

indexes "First_name", :sortable => true

or

change the column First_name to first_name and then you can do this

indexes first_name, :sortable => true

Mayank Jaimini
+1  A: 

BTW , the difference between string and a symbol is that multiple symbols representing a single value are unique whereas this is not true with strings. For example:

irb(term)> :symbol.object_id
=> 746921
irb(term)> :symbol.object_id
=> 746921


irb(term)> "string".object_id
=> 298788231
irb(main):011:0> "string".object_id
=> 297533890

Also, symbol equality comparison is faster then String equality comparison since they are the same object whereas in a strings the values need to be compared instead the object id.

NM