added search-description to book search
This commit is contained in:
parent
4449493bbd
commit
469c4a4b41
|
@ -29,8 +29,7 @@ def suggest_book(dbconnection, tmp_file=False):
|
||||||
authors_added = {}
|
authors_added = {}
|
||||||
file_prefix = "suggestion"
|
file_prefix = "suggestion"
|
||||||
filler = ' -------------------------------------------------- '
|
filler = ' -------------------------------------------------- '
|
||||||
if not tmp_file:
|
print("# Enter ISBN number(s), end with eof <CTRL+D>")
|
||||||
print("# Enter ISBN number(s), end with eof <CTRL+D>")
|
|
||||||
for ISBN in sys.stdin:
|
for ISBN in sys.stdin:
|
||||||
if ISBN.strip() in exit_commands:
|
if ISBN.strip() in exit_commands:
|
||||||
print("aborted")
|
print("aborted")
|
||||||
|
@ -292,4 +291,4 @@ def unescape(s):
|
||||||
return es.join(list)
|
return es.join(list)
|
||||||
|
|
||||||
|
|
||||||
suggest_book(connection, tmp_file=False)
|
suggest_book(connection, tmp_file=True)
|
||||||
|
|
|
@ -263,11 +263,19 @@ def list_cmd(connection, what):
|
||||||
|
|
||||||
def search_book(connection, search_strings, search_description=False):
|
def search_book(connection, search_strings, search_description=False):
|
||||||
c = connection.cursor()
|
c = connection.cursor()
|
||||||
where_clauses = ['book.title ILIKE %s OR book.subtitle ILIKE %s OR book.series ILIKE %s OR person.lastname ILIKE %s OR person.firstname ILIKE %s']*len(search_strings)
|
if search_description:
|
||||||
|
where_clauses = ['book.title ILIKE %s OR book.subtitle ILIKE %s OR book.series ILIKE %s OR person.lastname ILIKE %s OR person.firstname ILIKE %s OR book.description ILIKE %s']*len(search_strings)
|
||||||
|
else:
|
||||||
|
where_clauses = ['book.title ILIKE %s OR book.subtitle ILIKE %s OR book.series ILIKE %s OR person.lastname ILIKE %s OR person.firstname ILIKE %s']*len(search_strings)
|
||||||
|
|
||||||
result_list = []
|
result_list = []
|
||||||
for s in search_strings:
|
for s in search_strings:
|
||||||
for i in range(5):
|
if search_description:
|
||||||
result_list.append(s)
|
for i in range(6):
|
||||||
|
result_list.append(s)
|
||||||
|
else:
|
||||||
|
for i in range(5):
|
||||||
|
result_list.append(s)
|
||||||
c.execute('SELECT * FROM book LEFT JOIN bookperson ON book.isbn=bookperson.book LEFT JOIN person ON person.id=bookperson.person WHERE ' + ' OR '.join(where_clauses), map(lambda s:'%' + s + '%',result_list))
|
c.execute('SELECT * FROM book LEFT JOIN bookperson ON book.isbn=bookperson.book LEFT JOIN person ON person.id=bookperson.person WHERE ' + ' OR '.join(where_clauses), map(lambda s:'%' + s + '%',result_list))
|
||||||
for i in xrange(c.rowcount):
|
for i in xrange(c.rowcount):
|
||||||
book = fetchone_dict(c)
|
book = fetchone_dict(c)
|
||||||
|
|
Reference in New Issue