java - How to use text-search in mongo-spring aggregate -
how translate simple mongo shell $match phrase, it's equivelent in mongo-spring in java - using aggregation?
$match: { $text: { $search: "read" } }
spring-data has inbuilt support text search.
i have used following dependency :
<dependency> <groupid>org.springframework.data</groupid> <artifactid>spring-data-mongodb</artifactid> <version>1.8.2.release</version> </dependency>
try following syntax :
textcriteria criteria = textcriteria.fordefaultlanguage().matchingany("read"); query query = textquery.querytext(criteria); list<klass> list = mongotemplate.find(query, klass, "collection_name");
for more detail refer this.
to same in aggregation use following syntax :
basicdbobject match = new basicdbobject("$match", new basicdbobject("$text", new basicdbobject("$search", "cost"))); list<dbobject> aggregationlist = new arraylist<dbobject>(); aggregationlist.add(match); aggregationoutput aggregationoutput = mongotemplate.getcollection("categorymaster") .aggregate(aggregationlist); list<dbobject> dbobjects = (list<dbobject>) aggregationoutput.results();
convert dbobjects
in klass
below :
for(dbobject dbobject : dbobjects) { mongotemplate.getconverter().read(klass, dbobject); }
Comments
Post a Comment