diff --git a/digimarks.py b/digimarks.py index fbae8f4..41fad78 100644 --- a/digimarks.py +++ b/digimarks.py @@ -482,6 +482,14 @@ def make_external(url): return urljoin(request.url_root, url) +def _find_bookmarks(userkey, filter_text): + return Bookmark.select().where( + Bookmark.userkey == userkey, + (Bookmark.title.contains(filter_text) | Bookmark.url.contains(filter_text) | Bookmark.note.contains(filter_text)), + Bookmark.status == Bookmark.VISIBLE + ).order_by(Bookmark.created_date.desc()) + + @app.errorhandler(404) def page_not_found(e): theme = themes[DEFAULT_THEME] @@ -524,11 +532,7 @@ def get_bookmarks(userkey, filtermethod=None, sortmethod=None): filter_note = True if filter_text: - bookmarks = Bookmark.select().where( - Bookmark.userkey == userkey, - (Bookmark.title.contains(filter_text) | Bookmark.url.contains(filter_text) | Bookmark.note.contains(filter_text)), - Bookmark.status == Bookmark.VISIBLE - ).order_by(Bookmark.created_date.desc()) + bookmarks = _find_bookmarks(userkey, filter_text) elif filter_starred: bookmarks = Bookmark.select().where(Bookmark.userkey == userkey, Bookmark.starred).order_by(Bookmark.created_date.desc()) @@ -595,6 +599,16 @@ def bookmark_json(userkey, urlhash): return jsonify(bookmark.to_dict()) +@app.route('/api/v1//search/') +def search_bookmark_titles_json(userkey, filter_text): + """ Serialise bookmark to json """ + bookmarks = _find_bookmarks(userkey, filter_text) + result = [] + for bookmark in bookmarks: + result.append(bookmark.to_dict()) + return jsonify(result) + + @app.route('//') @app.route('///edit') def editbookmark(userkey, urlhash):