mongodb - Mongo 2.4 Text Command/ full text search using mongo-ruby-driver -


i want perform full text search on collection. since using mongo 2.4 mongodb's text command

the way in mongo's console (as per mongo's official docs.)

db.collection.runcommand( "text", { search: <string> }) 

it returns expected results.

now, want achieve same in ruby/rails. using mongo gem version 1.8.4

as per change log/history there support new mongodb 2.4 index types

but how can run text command on collection ruby.

i went through blog post. did'nt

update:

i tried,

  command = bson::orderedhash.new   command['find'] = collection   command['text'] = {'search' => 'string'}   result = @db.command(command) 

but gives

database command 'find' failed: (ok: '0.0'; errmsg: 'no such cmd: find'; bad cmd: '{"find"=>"project", "text"=>{"search"=>"string"}}'). 

update 2:

similar exists php. looking ruby's equivalent same.

you need use bson::orderedhash ruby 1.8. if you're running ruby 1.9 or greater can use following syntax create/query on text index.

require 'mongo' include mongo  client = mongoclient.new db = client['my_database'] coll = db['my_collection']  # create text index coll.ensure_index({:field_name => mongo::text})  # run text query db.command({:text => 'my_collection', :search => 'search string'}) db.command({:text => 'my_collection', :search => 'search string', :filter => {:foo => 'bar'}}) 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -