dbalmain / ferret

Ferret: the extensible information retrieval library for ruby.
http://ferret.davebalmain.com
MIT License
279 stars 59 forks source link

Indexing hashes using ruby #1

Closed manolopm closed 12 years ago

manolopm commented 15 years ago

Hi:

I'm trying to index a Hash in ruby and this is what I get:

irb(main):211:0> indexer << {:test => { :test1 => "hola", :test2=> 23}} => nil irb(main):212:0> indexer[0][:test] => "{:test1=>\"hi\", :test2=>23}"

I take a look to the code of index.rb and I found that add_document method don't take into account if something is a Hash and convert it to string. Can this be patched to take into account this case?

Regards from Canary Islands

Manuel Padrón Martínez

dbalmain commented 15 years ago

Are you saying that is what you want to get? This is what I get.

irb(main):004:0> index << {:test => { :test1 => "hola", :test2=> 23}}
=> nil
irb(main):005:0> index[0][:test]
=> "test1holatest223"

To get what you have I would have to do this;

irb(main):006:0> index << {:test => { :test1 => "hola", :test2=> 23}.inspect}
=> nil
irb(main):007:0> index[1][:test]
=> "{:test1=>\"hola\", :test2=>23}"

If this is what you want, it shouldn't be too hard to write a wrapper to do this. I don't really think it is an issue though.

woahdae commented 12 years ago

Yeah, I would find it surprising if ferret took responsibility of serialization/typecasting. Seems like that's the job of something higher level.

To that end, if you used a json serializer, ex. JSON.dump & JSON.load, you would get what you're looking for.