Mongo 2.4 full text search with Moped?

1,066 views
Skip to first unread message

Tal Atlas

unread,
Apr 16, 2013, 1:33:20 PM4/16/13
to mon...@googlegroups.com
Is there any way to use the new full text search feature of mongo 2.4? When i try this i get an error:

>> UserSearch.mongo_session.command('search',{search: "green", filter: { dept: "kitchen" }})
ArgumentError: wrong number of arguments (2 for 1)
    from /Users/tal/.rvm/gems/ruby-1.9.3-p392@delight/gems/moped-1.4.5/lib/moped/session.rb:77:in `command'
    from (irb):7
    from /Users/tal/.rvm/gems/ruby-1.9.3-p392@delight/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
    from /Users/tal/.rvm/gems/ruby-1.9.3-p392@delight/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
    from /Users/tal/.rvm/gems/ruby-1.9.3-p392@delight/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Durran Jordan

unread,
Apr 17, 2013, 3:20:33 AM4/17/13
to Mongoid
Try:

UserSearch.with(database: "text").mongo_session.command({search: "green", filter: { dept: "kitchen" }})


2013/4/16 Tal Atlas <swimmi...@gmail.com>

--
 
---
You received this message because you are subscribed to the Google Groups "Mongoid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoid+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

ara howard

unread,
May 20, 2013, 5:02:39 PM5/20/13
to mon...@googlegroups.com
with this i get

MOPED: 127.0.0.1:27017 COMMAND      database=text command={:text=>{:search=>"cat"}} (4.4558ms)
Moped::Errors::OperationFailure: The operation: #<Moped::Protocol::Command
  @length=70
  @request_id=15
  @response_to=0
  @op_code=2004
  @flags=[:slave_ok]
  @full_collection_name="text.$cmd"
  @skip=0
  @limit=-1
  @selector={:text=>{:search=>"cat"}}
  @fields=nil>
failed with error 13111: "exception: wrong type for field (text) 3 != 2"


the model


class A
  include Mongoid::Document

  field(:title)
  field(:text)

  index(

    {:title => 'text', :text => 'text'},

    {:weights => { :title => 10 }}

  )
end


in the console i've run


a:~/git/dojo4/rails_app_m $ rake db:mongoid:create_indexes|head 
MONGOID: Created indexes on A:
MONGOID: Index: {:title=>"text", :text=>"text"}, Options: {:weights=>{:title=>10}}
....


any thoughts?

ara howard

unread,
May 20, 2013, 5:09:44 PM5/20/13
to mon...@googlegroups.com
i've also run this in the js console


> db.adminCommand( { setParameter : "*", textSearchEnabled : true } );
{ "was" : true, "ok" : 1 }
> as = db.as
> as.dropIndexes()
{
        "nIndexesWas" : 2,
        "msg" : "non-_id indexes dropped for collection",
        "ok" : 1
}
> as.ensureIndex( { "title": "text", "text": "text" } );

Durran Jordan

unread,
May 21, 2013, 8:15:32 AM5/21/13
to Mongoid
Model.mongo_session.command(text: "collection_name", search: "my search string", filter: { ... }, project: { ... }, limit: 10, language: "english")

You can see how it's implemented in master here: https://github.com/mongoid/mongoid/blob/master/lib/mongoid/contextual/text_search.rb


2013/5/20 ara howard <ara.t....@gmail.com>

ara howard

unread,
Jun 12, 2013, 7:51:52 PM6/12/13
to mon...@googlegroups.com
just for people searching: i've had luck with *only* this

::Mongoid::Sessions.default.command(:text => collection_name.to_s, :search => search.to_s)


note: it's important that both arguments are *strings*
Reply all
Reply to author
Forward
0 new messages