You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a fairly small database from which I would like to return all records that contain a value (query) that is within author or title or tags even if only partially (so if I were to search for “tom” it should return “tommy, thomas, tomino”, etc).
Unfortunately, I don't understand where I'm going wrong for it to return what I expect.
This is the function (BTW during the tests I just remove the tags query)
defsearch_books(self, query: str) ->List[Book]:
""" Cerca libri nel database in base a una query. La ricerca viene effettuata su author, title e tags. :param query: La stringa di ricerca. :return: Una lista di dizionari rappresentanti i libri che corrispondono alla query. """query=query.lower()
BookQuery=Query()
try:
# Cerca libri dove il titolo o l'autore contiene la stringa della query (case insensitive)results=self.db.search(
(BookQuery.title.test(lambdatitle: queryintitle.lower())) |
(BookQuery.author.test(lambdaauthor: queryinauthor.lower()))
)
returnresultsexceptExceptionase:
print(f"Errore durante la ricerca dei libri: {e}")
return []
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I have a fairly small database from which I would like to return all records that contain a value (query) that is within author or title or tags even if only partially (so if I were to search for “tom” it should return “tommy, thomas, tomino”, etc).
Unfortunately, I don't understand where I'm going wrong for it to return what I expect.
This is the function (BTW during the tests I just remove the tags query)
Beta Was this translation helpful? Give feedback.
All reactions