我有 3 个不同的集合,在我的脚本中有不同的内容:图像、音频和视频。
在我放入数据库的每个元素中,我添加了一个标签。
当我尝试搜索标签(我添加每个集合的文件)时,我只能找到图像集合的标签:
- - - - - - - - - - - - - - - -代码 - - - - - - - - - ---------------------------------
受保护的无效搜索(字符串术语){
tagCounter = 0;
DBCollection image = db.getCollection("p");
DBCollection audio = db.getCollection("a");
DBCollection video = db.getCollection("video");
String search = searchField.getText();
search.trim().toLowerCase();
BasicDBObject tagQuery= new BasicDBObject();
tagQuery.put("tags", search);
DBCursor cursor = collection.find(tagQuery);
tagQuery.put("tags", search);
cursor = image.find(tagQuery);
while(cursor.hasNext()) {
results.addElement( cursor.next().toString());
tagCounter++;
searchField.setText(null);
}
cursor = audio.find(tagQuery);
while(cursor.hasNext()) {
results.addElement(cursor.next());
tagCounter++;
searchField.setText(null);
}
cursor = video.find(tagQuery);
while(cursor.hasNext()) {
results.addElement( cursor.next().toString()) ;
tagCounter++;
searchField.setText(null);
}
JOptionPane counter = new JOptionPane();
counter.showMessageDialog(resultList, "Search gave " + tagCounter + " files");
}
任何人都可以帮助新手吗?:)