Java full text search

74 views
Skip to first unread message

Felix Gao

unread,
Mar 10, 2013, 8:21:37 PM3/10/13
to mongod...@googlegroups.com
Hello,

I am playing around with my db on mongohq and I have created my index as 
key: { _fts"text"_ftsx1 }, v1ns"test_full_text.Location"name"FullTextIndexOnAddressAndName"weights: { a1n10 }, default_language"english"language_override:"language"textIndexVersion1 }

Now I am not sure how to query it.  Does anyone have an example on how to query the data in Java?  I am using the 2.10.1 driver. 

Thanks,

Felix

Rob Moore

unread,
Mar 10, 2013, 9:18:56 PM3/10/13
to mongod...@googlegroups.com

You will need to construct the command manually.  I'm typing this in without the benefit of an editor so likely to have typos.

DB db = ...;
String collectionName = "...";
String terms = "...";

db.command(new BasicDBObject("text" : collectionName).append("search", terms)); 

You can also append a "filter", "project", "limit", and/or "language" field.  As documented here: http://docs.mongodb.org/manual/release-notes/2.4/#text-queries

Note that the "text" field must be the first field in the DBObject.

Not sure if the driver will get a helper method post 2.4 release or not.

Rob.
Reply all
Reply to author
Forward
0 new messages