Projects/worblehat-old
Projects
/
worblehat-old
Archived
12
0
Fork 0

added search-description to book search

This commit is contained in:
Péter Henrik Gombos 2011-10-09 13:18:36 +00:00
parent 4449493bbd
commit 469c4a4b41
2 changed files with 13 additions and 6 deletions

View File

@ -29,7 +29,6 @@ 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:
@ -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)

View File

@ -263,9 +263,17 @@ 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()
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) 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:
if search_description:
for i in range(6):
result_list.append(s)
else:
for i in range(5): for i in range(5):
result_list.append(s) 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))