• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MapReduceOutput类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.mongodb.MapReduceOutput的典型用法代码示例。如果您正苦于以下问题:Java MapReduceOutput类的具体用法?Java MapReduceOutput怎么用?Java MapReduceOutput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



MapReduceOutput类属于com.mongodb包,在下文中一共展示了MapReduceOutput类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: calcularLocalizaciones

import com.mongodb.MapReduceOutput; //导入依赖的package包/类
/**
 * Map reduce.
 *
 * @param mongoOperation
 *            the mongo operation
 * @param a
 *            the a
 * @param b
 *            the b
 * @param c
 *            the c
 * @param d
 *            the d
 * @throws UnknownHostException
 */
static void calcularLocalizaciones() throws UnknownHostException {

	String map = "function () { emit(this.localizacion, {count: 1}); }";
	String reduce = " function(key, values) { var result = 0; values.forEach(function(value){ result++ }); "
			+ "return result; }";

	MongoClient mongoClient = new MongoClient("localhost", 27017);
	DB db = mongoClient.getDB("craulerdb");
	DBCollection ofertas = db.getCollection("ofertas");

	MapReduceCommand cmd = new MapReduceCommand(ofertas, map, reduce, null, MapReduceCommand.OutputType.INLINE,
			null);
	MapReduceOutput out = ofertas.mapReduce(cmd);

	for (DBObject o : out.results()) {
		System.out.println(o.toString());
	}
}
 
开发者ID:acardoco,项目名称:crauler_ISI,代码行数:34,代码来源:MongoFunctions.java


示例2: testMapReduce

import com.mongodb.MapReduceOutput; //导入依赖的package包/类
@Test
public void testMapReduce() throws Exception{
   MongoClient client = new MongoClient("localhost", 27017);
   DBCollection articles = client.getDB("ensim").getCollection("articles");
   
   // Write map function as Javascript.
   String map = "function() { " +
         "    emit('note', this.note);" +
         "}";
   // Write reduc function as Javascript.
   String reduce = "function(key, values) { " +
         "    return Array.sum(values) / values.length; " +
         "}";
   
   // Execute map/reduce job without finalize function and filter query.
   MapReduceOutput out = articles.mapReduce(map, reduce, null, MapReduceCommand.OutputType.INLINE, null);
   
   try{
      for (DBObject o : out.results()){
         System.err.println(o.toString());
      }
   } catch (Exception e){
      e.printStackTrace();
   }
}
 
开发者ID:lbroudoux,项目名称:ensim-2014,代码行数:26,代码来源:MongoMapReduceTest.java


示例3: mapReduce

import com.mongodb.MapReduceOutput; //导入依赖的package包/类
/**
 * runs a map-reduce-job on the collection. The functions are read from the classpath in the folder mongodb. The systems reads them from
 * files called <name>.map.js, <name>.reduce.js and optionally <name>.finalize.js. After this the result is converted
 * using the given {@link MapReduceResultHandler}
 * 
 * @param <R> the type of the result class
 * @param name the name of the map-reduce functions
 * @param query the query to filter the elements used for the map-reduce
 * @param sort sort query to sort elements before running map-reduce
 * @param scope the global scope for the JavaScript run
 * @param conv the converter to convert the result
 * @return an {@link Iterable} with the result entries
 * @throws RuntimeException if resources cannot be read
 */
protected final <R> Iterable<R> mapReduce(String name, DBObject query, DBObject sort, Map<String, Object> scope, final MapReduceResultHandler<R> conv) {
	String map = this.getMRFunction(name, "map");
	String reduce = this.getMRFunction(name, "reduce");
	
	MapReduceCommand mrc = new MapReduceCommand(this.collection.getDBCollection(), map, reduce, null, OutputType.INLINE, query);
	String finalizeFunction = this.getMRFunction(name, "finalize");
	if (finalizeFunction != null) {
		mrc.setFinalize(finalizeFunction);
	}
	if (sort != null) {
		mrc.setSort(sort);
	}
	if (scope != null) {
		mrc.setScope(scope);
	}
	MapReduceOutput mr = this.collection.getDBCollection().mapReduce(mrc);
	return new ConverterIterable<R>(mr.results().iterator(), conv);
}
 
开发者ID:taimos,项目名称:spring-dao-mongo,代码行数:33,代码来源:AbstractMongoDAO.java


示例4: mapReduce

import com.mongodb.MapReduceOutput; //导入依赖的package包/类
private synchronized Iterable<DBObject> mapReduce(String map, String reduce, String outputTarget, MapReduceCommand.OutputType outputType, String orderBy, DBObject query) {
    MapReduceOutput output = getCollection().mapReduce(map, reduce, outputTarget, outputType, query);
    DBCollection c = output.getOutputCollection();
    DBCursor cursor;
    if(orderBy != null){
        cursor = c.find().sort(SortUtil.getSort(orderBy));
    }else{
        cursor = c.find();
    }
    List<DBObject> list = new ArrayList<DBObject>();
    for(Iterator<DBObject> it = cursor.iterator(); it.hasNext(); ){
        list.add(it.next());
    }
    return list;
}
 
开发者ID:xbwen,项目名称:bugu-mongo,代码行数:16,代码来源:AdvancedDao.java


示例5: getMovies

import com.mongodb.MapReduceOutput; //导入依赖的package包/类
@GET
@Path("movies/{id}")
@Produces(MediaType.APPLICATION_JSON)
public static String getMovies(@PathParam("id") String userId) {
    Logger.getLogger(XPostWS.class.getName()).log(Level.INFO, "retrieving movies for " + userId);

    final JsonObject result = new JsonObject();

    Mongo mongo = getActionMongo();
    final DB db = mongo.getDB("mydb");
    final DBCollection moviesCol = db.getCollection("movies");

    String map = "function () {" + "if (this.userId != this.friendId)" + "{emit(this.id, this);}" + "};";
    String reduce = "function (key, values) {" +
                        "var res = {};" +
                        "res.name = values[0].name;" +
                        "res.id = key;" +
                        "res.userId = values[0].userId;" +
                        "res.poster = values[0].poster;" +
                        "res.rating = values[0].rating;" +
                        "res.imdbId = values[0].imdbId;" +
                        "res.friendId = [];" +
                        "for (var i = 0; i<values.length; ++i) {" +
                            "res.friendId.push(String(values[i].friendId));" +
                        "}" +
                        "return res;}";

    final BasicDBObject searchObject = new BasicDBObject("userId", userId);
    MapReduceCommand mapReduceComand = new MapReduceCommand(moviesCol, map, reduce, null,
            MapReduceCommand.OutputType.INLINE, searchObject);
    final MapReduceOutput moviesReduced = moviesCol.mapReduce(mapReduceComand);
    JsonArray moviesInfo = new JsonArray();
    for (DBObject movie : moviesReduced.results()) {
        moviesInfo.put(new JsonObject(movie.toString()));
    }
    Logger.getLogger(XPostWS.class.getName()).log(Level.INFO,
            "retrieved " + moviesInfo.length() + " movies for user " + userId);
    if (moviesInfo.length() == 0) {
        result.put("movies", new JsonArray().toString());
    } else {
        sortMovies(moviesInfo, userId);
        result.put("movies", moviesInfo);
    }

    try {
        return new String(result.toString().getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        Logger.getLogger(TAG).severe(e.getMessage());
        return result.toString();
    }
}
 
开发者ID:milenchechev,项目名称:RecommendedStream,代码行数:52,代码来源:XPostWS.java


示例6: getComments

import com.mongodb.MapReduceOutput; //导入依赖的package包/类
public List<JSONObject> getComments(String word) throws UnknownHostException, MongoException, SQLException, ClassNotFoundException, JSONException {
	// TODO Auto-generated method stub
	List<JSONObject> listeComments = new ArrayList<JSONObject>();

	Mongo mongoClient = new Mongo();
	DB db = mongoClient.getDB("social");
	DBCollection coll = db.getCollection("comments");	

	String m="function wordMap(){"+
			"var text = this.comment;"+
			"var words = text.match(/\\w+/g);"+
			"var tf = new Array();"+
			"for( var i=0; i< words.length ; i++ ){"+
			"if( tf[words[i]] == null){"+
			"tf[words[i]]=1;"+
			"}"+
			"else{"+	
			"tf[words[i]]++;"+
			"}"+
			"}"+
			"for( var i=0; i< words.length ; i++ ){"+
			"emit(this._id, { word : words[i], tf : tf[words[i]] } )}};";

	String r="function wordReduce(key, values){"+
			"return ( { \"tfs\" : values } )};";

	MapReduceOutput out = coll.mapReduce(m,r,null,MapReduceCommand.OutputType.INLINE,null);

	String[] tabWords = word.split(" ");
	SortedMap<String,String> map = new TreeMap<String,String>();


	for ( DBObject obj : out.results()){

		JSONObject jsonObj = new JSONObject(obj.toMap());


		String idObj = jsonObj.get("_id").toString();
		JSONObject jsonValue = new JSONObject(jsonObj.get("value").toString());
		JSONArray tfsTab = new JSONArray(jsonValue.get("tfs").toString());


		for(int i=0; i<tfsTab.length();i++){
			JSONObject tfsObj = tfsTab.getJSONObject(i);
			for(String w : tabWords){
				if(tfsObj.get("word").equals(w)){
					String nbtf = tfsObj.get("tf").toString();
					map.put(idObj,nbtf);
				}
			}
		}



	}

	mongoClient.close();


	Iterator iterator = map.keySet().iterator();
	while (iterator.hasNext()) {
		Object key = iterator.next();
		JSONObject objToAdd = new JSONObject();
		objToAdd.put("_id",key.toString());
		listeComments.add(objToAdd);
	}


	return listeComments;
}
 
开发者ID:Mag-Stellon,项目名称:li328,代码行数:71,代码来源:SearchMapReduceCommentBD.java


示例7: MapreduceResults

import com.mongodb.MapReduceOutput; //导入依赖的package包/类
/**
 * Creates a results instance for the given output
 *
 * @param output the output of the operation
 */
public MapreduceResults(final MapReduceOutput output) {
    this.output = output;
    outputCollectionName = output.getCollectionName();
}
 
开发者ID:mongodb,项目名称:morphia,代码行数:10,代码来源:MapreduceResults.java



注:本文中的com.mongodb.MapReduceOutput类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CHECKCAST类代码示例发布时间:2022-05-23
下一篇:
Java HttpHeader类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap