|
long id = obj.getLong("_id");
ArrayList tagList = (ArrayList) obj.get("tag"); // tag
ArrayList keywordList = (ArrayList)obj.get("keyword"); // keyword
ArrayList copyrightList = (ArrayList)obj.get("copyright"); // copyright
MediaEntity mediaEntity = new MediaEntity();
mediaEntity.setId(id);
// tag
for(int j=0; j actorsObjList = (ArrayList)obj.get("actors"); // actors
for(int j=0; j directorObjList = (ArrayList)obj.get("director"); // director
for(int j=0; j 100) {
break;
}
System.out.println(index + " --- mediaEntity : " + mediaEntity.toString());
}
long costTime = System.currentTimeMillis() - startTime;
System.out.println("load data costTime = " + index + "; costTime = " + costTime/1000f);
} catch (Exception e) {
e.printStackTrace();
}
}
public static int getTagInt(String tag) {
int tagIntId = -1;
try {
MongoClient mongo = new MongoClient(CosineCluster.gMongo_HOST, CosineCluster.gMongo_PORT);
DB db = mongo.getDB(CosineCluster.gMongo_DB);
DBCollection tagmapCollection = db.getCollection("recommend_tag_map");
DBCursor cursor = tagmapCollection.find(new BasicDBObject("name", tag));
if(cursor == null || cursor.toArray().size() <= 0) { // 处理小于2或n的映射关键字,下同
return tagIntId;
}
DBObject obj = cursor.toArray().get(0);
String name = tag;
tagIntId = (Integer) obj.get("id");
int num = (Integer) obj.get("num");
mongo.close();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return tagIntId;
}
public static int getActorInt(String actor) {
int actorIntId = -1;
try {
MongoClient mongo = new MongoClient(CosineCluster.gMongo_HOST, CosineCluster.gMongo_PORT);
DB db = mongo.getDB(CosineCluster.gMongo_DB);
DBCollection tagmapCollection = db.getCollection("recommend_actor_map");
DBCursor cursor = tagmapCollection.find(new BasicDBObject("name", actor));
if(cursor == null || cursor.toArray().size() <= 0) {
return actorIntId;
}
DBObject obj = cursor.toArray().get(0);
String name = actor;
actorIntId = (Integer) obj.get("id");
int num = (Integer) obj.get("num");
mongo.close();
} catch (UnknownHostException e) {
e.printStackTrace();
}
return actorIntId;
}
|