当前位置: 首页>>代码示例>>Java>>正文


Java AggregationOutput.results方法代码示例

本文整理汇总了Java中com.mongodb.AggregationOutput.results方法的典型用法代码示例。如果您正苦于以下问题:Java AggregationOutput.results方法的具体用法?Java AggregationOutput.results怎么用?Java AggregationOutput.results使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.mongodb.AggregationOutput的用法示例。


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

示例1: getNumberOfDiscoveredLinks

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
/**
 * 
 * @return number of total discovered links
 */
public Double getNumberOfDiscoveredLinks() {
	Double numberOfTriples = 0.0;
	try {
		DBCollection collection = DBSuperClass2.getDBInstance().getCollection(LinksetDB.COLLECTION_NAME);

		BasicDBObject groupFields = new BasicDBObject("_id", null);

		groupFields.append("sum", new BasicDBObject("$sum", "$links"));

		DBObject group = new BasicDBObject("$group", groupFields);

		// run aggregation
		List<DBObject> pipeline = Arrays.asList(group);
		AggregationOutput output = collection.aggregate(pipeline);

		for (DBObject result : output.results()) {
			numberOfTriples = Double.valueOf(result.get("sum").toString());
		}

	} catch (Exception e) {
		e.printStackTrace();
	}
	return numberOfTriples;
}
 
开发者ID:AKSW,项目名称:LODVader,代码行数:29,代码来源:LinksetQueries.java

示例2: getSubscriptions

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
@Override
protected List<UPSSubscription> getSubscriptions(String uri) {
    List<UPSSubscription> subscriptions = new ArrayList<>();

    List<String> listenerPaths = generatePaths(uri);

    DBObject match = new BasicDBObject("$match", new BasicDBObject("subscriptions.resource-path", new BasicDBObject("$in", listenerPaths)));
    DBObject unwind = new BasicDBObject("$unwind", "$subscriptions");

    // first perform a match to get the object which contains a subscription we want [uses the index]
    // then unwind to get the individual subscriptions
    // then match again to get only the subscriptions we want.
    // NOTE: the first step is not redundant, we need to first narrow down using an index (for performance) before unwinding and ultimately getting only the results we want.
    AggregationOutput aggregate = collection.aggregate(match, unwind, match);
    for (DBObject dbObject : aggregate.results()) {
        UPSSubscription subscription = UPSSubscription.create((DBObject) dbObject.get("subscriptions"));
        if (subscription != null) {
            subscriptions.add(subscription);
        }
    }

    return subscriptions;
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:24,代码来源:AliasUPSSubscription.java

示例3: fetchAllArticleNumbers

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
@Override
public Map<String, Id> fetchAllArticleNumbers() {
    Map<String, Id> articleNumbers = new LinkedHashMap<String, Id>();

    Id attributeId = Attributes.getAttributeId(Product.class, "article_number");

    // build the $projection operation
    DBObject fields = new BasicDBObject("attributes.attr_id", 1);
    fields.put("attributes.val.val", 1);
    DBObject project = new BasicDBObject("$project", fields);

    DBObject unwind = new BasicDBObject("$unwind", "$attributes");

    // create our pipeline operations, first with the $match
    DBObject match = new BasicDBObject("$match", new BasicDBObject("attributes.attr_id", attributeId));

    // build the $projection operation
    DBObject project2 = new BasicDBObject("$project", new BasicDBObject("an", "$attributes.val.val"));

    List<DBObject> pipeline = Arrays.asList(project, unwind, match, project2);

    AggregationOutput output = db(Product.class).getCollection(COLLECTION_NAME).aggregate(pipeline);

    for (DBObject result : output.results()) {
        if (result.get("an") != null) {
            articleNumbers.put(String.valueOf(((BasicDBList) result.get("an")).get(0)).trim(),
                Id.valueOf(result.get("_id")));
        }
    }

    return articleNumbers;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:33,代码来源:DefaultProductDao.java

示例4: fetchIdArticleNumberMap

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
@Override
public Map<Id, String> fetchIdArticleNumberMap() {
    Map<Id, String> articleNumbers = new LinkedHashMap<Id, String>();

    Id attributeId = Attributes.getAttributeId(Product.class, "article_number");

    // build the $projection operation
    DBObject fields = new BasicDBObject("attributes.attr_id", 1);
    fields.put("attributes.val.val", 1);
    DBObject project = new BasicDBObject("$project", fields);

    DBObject unwind = new BasicDBObject("$unwind", "$attributes");

    // create our pipeline operations, first with the $match
    DBObject match = new BasicDBObject("$match", new BasicDBObject("attributes.attr_id", attributeId));

    // build the $projection operation
    DBObject project2 = new BasicDBObject("$project", new BasicDBObject("an", "$attributes.val.val"));

    List<DBObject> pipeline = Arrays.asList(project, unwind, match, project2);

    AggregationOutput output = db(Product.class).getCollection(COLLECTION_NAME).aggregate(pipeline);

    for (DBObject result : output.results()) {
        if (result.get("an") != null) {
            articleNumbers.put(Id.valueOf(result.get("_id")),
                String.valueOf(((BasicDBList) result.get("an")).get(0)).trim());
        }
    }

    return articleNumbers;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:33,代码来源:DefaultProductDao.java

示例5: getSuggestions

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
@Override
public List<String> getSuggestions(Id attributeId, String collectionName, String lang, String query) {
    DBObject val = new BasicDBObject("$elemMatch",
        new BasicDBObject("val", new BasicDBObject("$regex", "^" + query + ".*")));

    DBObject elemMathContent = new BasicDBObject("attr_id", attributeId);
    elemMathContent.put("val", val);

    DBObject elemMatch = new BasicDBObject("$elemMatch", elemMathContent);

    List<DBObject> alls = new ArrayList<>();
    alls.add(elemMatch);

    DBObject match = new BasicDBObject("$match", new BasicDBObject("attributes", new BasicDBObject("$all", alls)));

    DBObject matchAdditionalContent = new BasicDBObject("attributes.attr_id", attributeId);
    if (lang != null && !lang.isEmpty()) {
        matchAdditionalContent.put("attributes.val.l", lang);
    }
    matchAdditionalContent.put("attributes.val.val", new BasicDBObject("$regex", "^" + query + ".*"));

    DBObject matchAdditional = new BasicDBObject("$match", matchAdditionalContent);
    AggregationOutput output = ((DB) connections.getFirstConnection("mongodb")).getCollection(collectionName)
        .aggregate(match, new BasicDBObject("$unwind", "$attributes"),
            new BasicDBObject("$unwind", "$attributes.val"), matchAdditional,
            new BasicDBObject("$group", new BasicDBObject("_id", "$attributes.val.val")),
            new BasicDBObject("$sort", new BasicDBObject("_id", 1)));

    List<String> suggestions = new ArrayList<>();

    for (DBObject result : output.results()) {
        suggestions.add((String) result.get("_id"));
    }

    return suggestions;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:37,代码来源:DefaultAttributeService.java

示例6: getNumberOfTriples

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
/**
 * 
 * @return number of total triples read
 */
public Double getNumberOfTriples() {
	Double numberOfTriples = 0.0;
	try {
		DBCollection collection = DBSuperClass2.getDBInstance().getCollection(DistributionDB.COLLECTION_NAME);

		BasicDBObject select = new BasicDBObject("$match",
				new BasicDBObject(DistributionDB.SUCCESSFULLY_DOWNLOADED, true));

		BasicDBObject groupFields = new BasicDBObject("_id", null);

		groupFields.append("sum", new BasicDBObject("$sum", "$triples"));

		DBObject group = new BasicDBObject("$group", groupFields);

		// run aggregation
		List<DBObject> pipeline = Arrays.asList(select, group);
		AggregationOutput output = collection.aggregate(pipeline);

		for (DBObject result : output.results()) {
			numberOfTriples = Double.valueOf(result.get("sum").toString());
		}

	} catch (Exception e) {
		e.printStackTrace();
	}
	return numberOfTriples;
}
 
开发者ID:AKSW,项目名称:LODVader,代码行数:32,代码来源:DistributionQueries.java

示例7: serializeLoadTimes

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
private void serializeLoadTimes(JsonGenerator jgen) throws IOException,
		JsonProcessingException {
	jgen.writeArrayFieldStart("LoadTimes");
	/**
	 * db.hubs.aggregate([ {$project: { "loadtimes" : 1}}, {$unwind :
	 * "$loadtimes"}, {$project: { "truckType" : "$loadtimes.truckType",
	 * "loadTime" : "$loadtimes.loadTime"}}])
	 */

	AggregationOutput agg = getDB().getCollection("hubs").aggregate(
			new BasicDBObject().append("$project",
					new BasicDBObject().append("loadtimes", 1)),
			new BasicDBObject().append("$unwind", "$loadtimes"),
			new BasicDBObject().append(
					"$project",
					new BasicDBObject().append("truckType",
							"$loadtimes.truckType").append("loadTime",
							"$loadtimes.loadTime")));

	for (DBObject obj : agg.results()) {
		jgen.writeStartObject();
		jgen.writeStringField("hub", obj.get("_id").toString());
		jgen.writeStringField("truckType", obj.get("truckType").toString());
		jgen.writeNumberField("loadTime",
				((Number) obj.get("loadTime")).intValue());
		jgen.writeEndObject();
	}
	jgen.writeEndArray();
}
 
开发者ID:IBMDecisionOptimization,项目名称:DOcloud-GreenTruck-sample,代码行数:30,代码来源:TruckingJobInput.java

示例8: serializeRoutes

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
private void serializeRoutes(JsonGenerator jgen) throws IOException,
		JsonProcessingException {
	jgen.writeArrayFieldStart("Routes");
	/**
	 * db.hubs.aggregate([ {$project: { "routes" : 1}}, {$unwind :
	 * "$routes"}, {$project: { "spoke" : "$routes.spoke", "distance" :
	 * "$routes.distance"}}])
	 */

	AggregationOutput agg = getDB().getCollection("hubs").aggregate(
			new BasicDBObject().append("$project",
					new BasicDBObject().append("routes", 1)),
			new BasicDBObject().append("$unwind", "$routes"),
			new BasicDBObject().append("$project",
					new BasicDBObject().append("spoke", "$routes.spoke")
							.append("distance", "$routes.distance")));

	for (DBObject obj : agg.results()) {
		jgen.writeStartObject();
		jgen.writeStringField("spoke", obj.get("spoke").toString());
		jgen.writeStringField("hub", obj.get("_id").toString());
		jgen.writeNumberField("distance",
				((Number) obj.get("distance")).intValue());
		jgen.writeEndObject();
	}
	jgen.writeEndArray();
}
 
开发者ID:IBMDecisionOptimization,项目名称:DOcloud-GreenTruck-sample,代码行数:28,代码来源:TruckingJobInput.java

示例9: results

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
@Override
public Iterable<DBObject> results(){
    if(options == null){
        AggregationOutput output = coll.aggregate(pipeline);
        return output.results();
    }else{
        final Iterator<DBObject> it = coll.aggregate(pipeline, options);
        return new Iterable<DBObject>() {
            @Override
            public Iterator<DBObject> iterator() {
                return it;
            }
        };
    }
}
 
开发者ID:xbwen,项目名称:bugu-mongo,代码行数:16,代码来源:BuguAggregation.java

示例10: getAggregationQuery

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
public Iterable<DBObject> getAggregationQuery(String key, int min, int max) {
	DBObject match = new BasicDBObject(key, new BasicDBObject("$gt", min).append("$lt", max));
	DBObject matchOp = new BasicDBObject("$match", match);
	DBCollection fullData = mc.getCollection(type);
	DBObject groupOp = setupGroupOperation();
	AggregationOutput ao = fullData.aggregate(matchOp, groupOp);
	return ao.results();
}
 
开发者ID:nullbox,项目名称:Data-and-Information-Visualization-Project,代码行数:9,代码来源:ProcessingWorker.java

示例11: getTimeSerie

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
public TimeSeries getTimeSerie(DataType t, DBObject groupOp, String groupNameX, String groupNameY, String cName, Boolean useMovingAverage) {
	long begin = new Date().getTime();

	// Query fetches collection t
	DBCollection c = getCollection(t);
	AggregationOutput ao = c.aggregate(groupOp);
	TimeSeries timeserie = new TimeSeries(cName);

	HashMap<Integer, Integer> valueMap = new HashMap<Integer, Integer>();
	List<Integer> xVals = new ArrayList<Integer>();
	for (DBObject dbo : ao.results()) {
		int x = (Integer) dbo.get(groupNameX);
		int y = (Integer) dbo.get(groupNameY);
		xVals.add(x);
		valueMap.put(x, y);
	}

	int min = Collections.min(xVals);
	int max = Collections.max(xVals);
	for (int i = min; i <= max; i += 60) {
		timeserie.add(new Minute(new Date(i * 1000L)), valueMap.get(i));
	}

	if (useMovingAverage) {
		timeserie = MovingAverage.createMovingAverage(timeserie, cName, 50, 100);
	}

	logger.info("Fetched slider backgroud data, DataType:" + t.toString() + ", query took " + (new Date().getTime() - begin) + " ms");

	return timeserie;
}
 
开发者ID:nullbox,项目名称:Data-and-Information-Visualization-Project,代码行数:32,代码来源:MongoController.java

示例12: aggregate

import com.mongodb.AggregationOutput; //导入方法依赖的package包/类
private BasicDBList aggregate(RequestContext ctx) {
    BasicDBList queryObject = new BasicDBList();
    if (ctx.resourceParams() != null && ctx.resourceParams().contains("q")) {
        String queryString = ctx.resourceParams().value("q");
        DBObject paramObject = (DBObject) JSON.parse(queryString);

        if (paramObject instanceof BasicDBList) {
            queryObject = (BasicDBList) paramObject;
        } else {
            queryObject.add(paramObject);
        }
    }

    DBCollection dbCollection = parent().getDBCollection();

    try {
        BasicDBList result = new BasicDBList();
        AggregationOutput output = dbCollection.aggregate(
                (DBObject) queryObject.remove(0),
                queryObject.toArray(new DBObject[queryObject.size()]));
        for (DBObject dbObject : output.results()) {
            result.add(dbObject);
        }

        return result;

    } catch (Exception e) {
        logger().error("", e);
        throw new RuntimeException("Aggregation query failed: ", e);
    }
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:32,代码来源:MongoAggregationResource.java


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