diff --git a/htroot/Bookmarks.html b/htroot/Bookmarks.html
index 22701bf1f..d983920a2 100644
--- a/htroot/Bookmarks.html
+++ b/htroot/Bookmarks.html
@@ -251,6 +251,7 @@ To see a list of all APIs, please visit the #[title]#
#[description]#
+ #(hasquery)#::query=#[query]#
#(/hasquery)#
Tagged with | #{tags}##[tag]# | #{/tags}#
Edit
@@ -258,6 +259,10 @@ To see a list of all APIs, please visit the Delete
/
Info
+ #(hasquery)#::
+ /
+ search
+ #(/hasquery)#
#{/bookmarks}#
diff --git a/htroot/Bookmarks.java b/htroot/Bookmarks.java
index d7fc531e6..097f59f97 100644
--- a/htroot/Bookmarks.java
+++ b/htroot/Bookmarks.java
@@ -152,7 +152,7 @@ public class Bookmarks {
}
tagsString = tagsString + "," + pathString;
final Set tags=ListManager.string2set(BookmarkHelper.cleanTagsString(tagsString));
- final BookmarksDB.Bookmark bookmark = sb.bookmarksDB.createBookmark(url, username);
+ final BookmarksDB.Bookmark bookmark = sb.bookmarksDB.createorgetBookmark(url, username);
if (bookmark != null) {
bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_TITLE, title);
@@ -326,6 +326,12 @@ public class Bookmarks {
}
prop.putHTML("display_bookmarks_"+count+"_title", bookmark.getTitle());
prop.putHTML("display_bookmarks_"+count+"_description", bookmark.getDescription());
+ if (bookmark.getQuery() == null) {
+ prop.put("display_bookmarks_"+count+"_hasquery", false);
+ } else {
+ prop.put("display_bookmarks_"+count+"_hasquery", true);
+ prop.put("display_bookmarks_"+count+"_hasquery_query", bookmark.getQuery());
+ }
prop.put("display_bookmarks_"+count+"_date", ISO8601Formatter.FORMATTER.format(new Date(bookmark.getTimeStamp())));
prop.put("display_bookmarks_"+count+"_rfc822date", HeaderFramework.formatRFC1123(new Date(bookmark.getTimeStamp())));
prop.put("display_bookmarks_"+count+"_public", (bookmark.getPublic() ? "1" : "0"));
@@ -477,7 +483,7 @@ public class Bookmarks {
bookmark = sb.bookmarksDB.getBookmark(bit.next());
} catch (final IOException e) {
}
- if (bookmark == null) break;
+ if (bookmark == null) break;
prop.put("display_folderlist_" + count + "_folder", "" + bookmark.getTitle() + "");
count++;
}
diff --git a/htroot/api/bookmarks/posts/add_p.java b/htroot/api/bookmarks/posts/add_p.java
index 0fd74debd..d41a4357c 100644
--- a/htroot/api/bookmarks/posts/add_p.java
+++ b/htroot/api/bookmarks/posts/add_p.java
@@ -47,7 +47,7 @@ public class add_p {
final String pathString = post.get("path","/unsorted");
tagsString= tagsString + "," + pathString;
final Set tags = ListManager.string2set(BookmarkHelper.cleanTagsString(tagsString));
- final BookmarksDB.Bookmark bookmark = sb.bookmarksDB.createBookmark(url, username);
+ final BookmarksDB.Bookmark bookmark = sb.bookmarksDB.createorgetBookmark(url, username);
if(bookmark != null){
bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_TITLE, title);
bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_DESCRIPTION, description);
diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java
index 8494ab05e..31740bcdb 100644
--- a/htroot/yacysearch.java
+++ b/htroot/yacysearch.java
@@ -594,9 +594,8 @@ public class yacysearch {
final String urlstr = crypt.simpleDecode(post.get("bookmarkurl"));
if (urlstr != null) {
try {
- final Bookmark bmk = sb.bookmarksDB.createBookmark(urlstr, YMarkTables.USER_ADMIN);
- bmk.setProperty(Bookmark.BOOKMARK_DESCRIPTION, "query="+querystring);
- //bmk.setProperty(Bookmark.BOOKMARK_QUERY, originalquerystring);
+ final Bookmark bmk = sb.bookmarksDB.createorgetBookmark(urlstr, YMarkTables.USER_ADMIN);
+ bmk.setProperty(Bookmark.BOOKMARK_QUERY, querystring);
bmk.addTag("/search"); // add to bookmark folder
bmk.addTag("searchresult"); // add tag
String urlhash = post.get("bookmarkref");
diff --git a/source/net/yacy/data/BookmarksDB.java b/source/net/yacy/data/BookmarksDB.java
index f6a394afd..8560dd5f3 100644
--- a/source/net/yacy/data/BookmarksDB.java
+++ b/source/net/yacy/data/BookmarksDB.java
@@ -35,6 +35,8 @@ import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import net.yacy.cora.document.encoding.ASCII;
import net.yacy.cora.document.encoding.UTF8;
@@ -126,11 +128,25 @@ public class BookmarksDB {
// bookmarksDB's functions for bookmarksTable / bookmarkCache
// -----------------------------------------------------------
- public Bookmark createBookmark(final String url, final String user){
+ /**
+ * create or get existing bookmark
+ * @param url
+ * @param user
+ * @return
+ */
+ public Bookmark createorgetBookmark(final String url, final String user){
if (url == null || url.isEmpty()) return null;
Bookmark bk;
try {
- bk = new Bookmark(url);
+ try {
+ DigestURL durl = new DigestURL((url.indexOf("://") < 0) ? "http://" + url : url);
+ bk = this.getBookmark(ASCII.String(durl.hash()));
+ } catch (IOException ex) {
+ bk = null;
+ }
+ if (bk == null) {
+ bk = new Bookmark(url);
+ }
bk.setOwner(user);
return (bk.getUrlHash() == null || bk.toMap() == null) ? null : bk;
} catch (final MalformedURLException e) {
@@ -461,6 +477,7 @@ public class BookmarksDB {
private static final String BOOKMARK_TIMESTAMP = "bookmarkTimestamp";
private static final String BOOKMARK_OWNER = "bookmarkOwner";
private static final String BOOKMARK_IS_FEED = "bookmarkIsFeed";
+ public static final String BOOKMARK_QUERY = "bookmarkQuery"; // tag for original search string if bookmark was created from search result
private final String urlHash;
private Set tagNames;
private long timestamp;
@@ -587,6 +604,18 @@ public class BookmarksDB {
return false;
}
+ /**
+ * get the original query string (if bookmark was created from a search result original query is stored as a bookmark property)
+ * or null if not exist
+ * @return query-string or null
+ */
+ public String getQuery() {
+ if (this.entry.containsKey(BOOKMARK_QUERY)) {
+ return this.entry.get(BOOKMARK_QUERY);
+ }
+ return null;
+ }
+
public void setPublic(final boolean isPublic){
if(isPublic){
this.entry.put(BOOKMARK_PUBLIC, "public");
diff --git a/source/net/yacy/search/AutoSearch.java b/source/net/yacy/search/AutoSearch.java
index bd0a071de..2f42ac65e 100644
--- a/source/net/yacy/search/AutoSearch.java
+++ b/source/net/yacy/search/AutoSearch.java
@@ -166,12 +166,12 @@ public class AutoSearch extends AbstractBusyThread {
if (bmk.getFoldersString().startsWith("/search")) {
// take only new created or edited bookmarks
if (bmk.getTimeStamp() >= this.lastInitTime) {
- final String query = bmk.getDescription();
- if (!query.isEmpty() && query.startsWith("query=")) {
+ final String query = bmk.getQuery();
+ if (query != null && !query.isEmpty()) {
{
- querystack.add(query.substring(6));
+ querystack.add(query);
added++;
- ConcurrentLog.info(AutoSearch.class.getName(), "add query from Bookmarks " + query);
+ ConcurrentLog.info(AutoSearch.class.getName(), "add query from Bookmarks: query=" + query);
}
}
}
diff --git a/source/net/yacy/search/Switchboard.java b/source/net/yacy/search/Switchboard.java
index a26cd725c..404cf574b 100644
--- a/source/net/yacy/search/Switchboard.java
+++ b/source/net/yacy/search/Switchboard.java
@@ -3113,11 +3113,10 @@ public final class Switchboard extends serverSwitch {
if (tagStr.length() > 2 && tagStr.startsWith("[") && tagStr.endsWith("]")) tagStr = tagStr.substring(1, tagStr.length() - 2);
// we will create always a bookmark to use this to track crawled hosts
- final BookmarksDB.Bookmark bookmark = this.bookmarksDB.createBookmark(url.toNormalform(true), "admin");
+ final BookmarksDB.Bookmark bookmark = this.bookmarksDB.createorgetBookmark(url.toNormalform(true), "admin");
if (bookmark != null) {
bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_TITLE, title);
bookmark.setProperty(BookmarksDB.Bookmark.BOOKMARK_DESCRIPTION, description);
- bookmark.setOwner("admin");
bookmark.setPublic(false);
bookmark.setTags(tags, true);
this.bookmarksDB.saveBookmark(bookmark);