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

developed book search with possibility for more than one word, and search for authors

This commit is contained in:
Péter Henrik Gombos 2011-10-08 19:32:30 +00:00
parent ba14cc09b6
commit 3c911d3131
1 changed files with 9 additions and 3 deletions

View File

@ -265,10 +265,16 @@ 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()
c.execute('SELECT * FROM book WHERE book.title LIKE %(search_strings)s', {"search_strings": '%' + search_strings[0] + '%'}) 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 = []
for s in search_strings:
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))
for i in xrange(c.rowcount): for i in xrange(c.rowcount):
cat = fetchone_dict(c) book = fetchone_dict(c)
print cat['title'] print book['isbn'], book['title'], book['person']
def search_person(connection, search_strings): def search_person(connection, search_strings):
pass pass