developed book search with possibility for more than one word, and search for authors
This commit is contained in:
parent
ba14cc09b6
commit
3c911d3131
|
@ -265,10 +265,16 @@ def list_cmd(connection, what):
|
|||
|
||||
def search_book(connection, search_strings, search_description=False):
|
||||
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):
|
||||
cat = fetchone_dict(c)
|
||||
print cat['title']
|
||||
book = fetchone_dict(c)
|
||||
print book['isbn'], book['title'], book['person']
|
||||
|
||||
|
||||
def search_person(connection, search_strings):
|
||||
pass
|
||||
|
|
Reference in New Issue