Better search.
The input keywords, combined as a single tag, are used to match against tags for each bookmark entry. Partial matches (but in same sequence) are accepted. The same input keywords are also used to search title metadata. Even if a single keyword is found in URL or title metadata the bookmark is shown in results. Signed-off-by: Arun Prakash Jana <engineerarun@gmail.com>
This commit is contained in:
parent
3a89429079
commit
6df582db2a
19
markit
19
markit
@ -48,7 +48,7 @@ def usage():
|
||||
print(" -i N add entry at index N, works with -a, use to fill deleted index")
|
||||
print(" -o fetch title info from web, works with -a or -u")
|
||||
print(" -p print all bookmarks, shows real index from database")
|
||||
print(" -s string(s) search all bookmarks for a (partial) tag or keyword")
|
||||
print(" -s keyword(s) search all bookmarks for a (partial) tag or keywords")
|
||||
print(" -u N update entry at index N (from output of -p)")
|
||||
print(" you can either add or update or delete in one instance")
|
||||
print(" any other input shows help and exits markit\n")
|
||||
@ -186,18 +186,23 @@ def AddUpdateEntry(conn, cur, keywords, entry):
|
||||
|
||||
def searchdb(cur, keywords):
|
||||
searchtag = ''
|
||||
searchkey = keywords[0]
|
||||
for token in keywords:
|
||||
searchtag += token + " "
|
||||
searchtag = searchtag[0:-1]
|
||||
|
||||
searchtag = ',' + searchtag[0:-1] + ','
|
||||
arguments = []
|
||||
arguments.append(searchtag)
|
||||
placeholder = "'%' || ? || '%'"
|
||||
query = "SELECT url, metadata FROM bookmarks WHERE tags LIKE (%s)" % placeholder
|
||||
for token in keywords:
|
||||
query += " OR URL LIKE (%s) OR metadata LIKE (%s)" % (placeholder, placeholder)
|
||||
arguments.append(token)
|
||||
arguments.append(token)
|
||||
print("%s, (%s)" % (query, arguments))
|
||||
|
||||
count = 0
|
||||
results = []
|
||||
for row in cur.execute("SELECT url, metadata FROM bookmarks WHERE tags LIKE ('%' || ? || '%') \
|
||||
OR tags LIKE ('%' || ? || '%') \
|
||||
OR URL LIKE ('%' || ? || '%') \
|
||||
OR metadata LIKE ('%' || ? || '%')", (searchtag, searchkey, searchkey, searchkey,)):
|
||||
for row in cur.execute(query, arguments):
|
||||
results.append(row[0])
|
||||
count += 1
|
||||
print("\x1B[1m\x1B[93m%d. \x1B[0m\x1B[92m%s\x1B[0m\n\t%s" % (count, row[0], row[1]))
|
||||
|
Loading…
x
Reference in New Issue
Block a user