rebuildTags to rebuild the tags.db from the bookmarks.db

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1257 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
allo 19 years ago
parent 2982715a04
commit 867573de71

@ -56,31 +56,47 @@ import de.anomic.kelondro.kelondroDyn;
import de.anomic.kelondro.kelondroException; import de.anomic.kelondro.kelondroException;
import de.anomic.kelondro.kelondroMap; import de.anomic.kelondro.kelondroMap;
import de.anomic.plasma.plasmaURL; import de.anomic.plasma.plasmaURL;
import de.anomic.server.logging.serverLog;
public class bookmarksDB { public class bookmarksDB {
kelondroMap tagsTable; kelondroMap tagsTable;
kelondroMap bookmarksTable; kelondroMap bookmarksTable;
public bookmarksDB(File bookmarksFile, File tagsFile, int bufferkb){ public bookmarksDB(File bookmarksFile, File tagsFile, int bufferkb){
if(bookmarksFile.exists() && tagsFile.exists()){ //check if database exists
if(bookmarksFile.exists()){
try { try {
//open it
this.bookmarksTable=new kelondroMap(new kelondroDyn(bookmarksFile, 1024*bufferkb)); this.bookmarksTable=new kelondroMap(new kelondroDyn(bookmarksFile, 1024*bufferkb));
this.tagsTable=new kelondroMap(new kelondroDyn(tagsFile, 1024*bufferkb));
} catch (IOException e) { } catch (IOException e) {
//TODO: check if both are corrupted //database reset :-((
bookmarksFile.delete(); bookmarksFile.delete();
bookmarksFile.getParentFile().mkdirs(); bookmarksFile.getParentFile().mkdirs();
this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true)); this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true));
}
}else{
//new database
bookmarksFile.getParentFile().mkdirs();
this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true));
}
//check if database exists
if(tagsFile.exists()){
try {
//open it
this.tagsTable=new kelondroMap(new kelondroDyn(tagsFile, 1024*bufferkb));
} catch (IOException e) {
//reset database
tagsFile.delete(); tagsFile.delete();
tagsFile.getParentFile().mkdirs(); tagsFile.getParentFile().mkdirs();
this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true)); this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true));
rebuildTags();
} }
}else{ }else{
bookmarksFile.getParentFile().mkdirs(); //new database
this.bookmarksTable = new kelondroMap(new kelondroDyn(bookmarksFile, bufferkb * 1024, 128, 256, true));
tagsFile.getParentFile().mkdirs(); tagsFile.getParentFile().mkdirs();
this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true)); this.tagsTable = new kelondroMap(new kelondroDyn(tagsFile, bufferkb * 1024, 128, 256, true));
rebuildTags();
} }
} }
public void close(){ public void close(){
@ -130,6 +146,27 @@ public class bookmarksDB {
} }
return ret; return ret;
} }
public void rebuildTags(){
serverLog.logInfo("BOOKMARKS", "rebuilding tags.db from bookmarks.db...");
Iterator it=bookmarkIterator(true);
Bookmark bookmark;
Tag tag;
String[] tags;
while(it.hasNext()){
bookmark=(Bookmark) it.next();
tags = bookmark.getTags().split(",");
tag=null;
for(int i=0;i<tags.length;i++){
tag=getTag(tags[i]);
if(tag==null){
tag=new Tag(tags[i]);
}
tag.add(bookmark.getUrlHash());
tag.setTagsTable();
}
}
serverLog.logInfo("BOOKMARKS", "Rebuilt "+tagsTable.size()+" tags using your "+bookmarksTable.size()+" bookmarks.");
}
public Tag getTag(String tagName){ public Tag getTag(String tagName){
Map map; Map map;
try { try {
@ -183,12 +220,14 @@ public class bookmarksDB {
Bookmark bookmark = getBookmark(urlHash); Bookmark bookmark = getBookmark(urlHash);
if(bookmark == null) return; //does not exist if(bookmark == null) return; //does not exist
String[] tags = bookmark.getTags().split(","); String[] tags = bookmark.getTags().split(",");
bookmarksDB.Tag tag; bookmarksDB.Tag tag=null;
for(int i=0;i<tags.length;i++){ for(int i=0;i<tags.length;i++){
tag=getTag(tags[i]); tag=getTag(tags[i]);
if(tag !=null){
tag.delete(urlHash); tag.delete(urlHash);
tag.setTagsTable(); tag.setTagsTable();
} }
}
try { try {
bookmarksTable.remove(urlHash); bookmarksTable.remove(urlHash);
} catch (IOException e) {} } catch (IOException e) {}

Loading…
Cancel
Save