mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
fixed /cerca to search literal string
This commit is contained in:
parent
0a46cbeade
commit
5bdacf9496
1 changed files with 4 additions and 4 deletions
|
@ -300,13 +300,13 @@ def cmd_cerca(bot: Bot, update: Update):
|
||||||
session = db.Session()
|
session = db.Session()
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
text = update.message.text.split(" ", 1)[1]
|
queryText = update.message.text.split(" ", 1)[1]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
bot.send_message(update.message.chat.id, s(strings.DIARIO_SEARCH.ERRORS.INVALID_SYNTAX))
|
bot.send_message(update.message.chat.id, s(strings.DIARIO_SEARCH.ERRORS.INVALID_SYNTAX))
|
||||||
return
|
return
|
||||||
text = text.replace('%', '\\%').replace('_', '\\_')
|
queryText = queryText.replace('%', '\\%').replace('_', '\\_')
|
||||||
entries = session.query(db.Diario).filter(db.Diario.text.ilike('%'+text+'%')).order_by(db.Diario.id).all()
|
entries = session.query(db.Diario).filter(f"text ~* '(?:[^\w\d]+{queryText}[^\w\d]+|^{queryText}[^\w\d]+|^{queryText}$|[^\w\d]+{queryText}$)'").order_by(db.Diario.id).all()
|
||||||
msg = f"Risultati della ricerca di {text}:\n"
|
msg = f"Risultati della ricerca di {queryText}:\n"
|
||||||
for entry in entries[:5]:
|
for entry in entries[:5]:
|
||||||
msg += f'<a href="https://ryg.steffo.eu/diario#entry-{entry.id}">#{entry.id}</a> di {entry.author or "Anonimo"}\n{entry.text}\n\n'
|
msg += f'<a href="https://ryg.steffo.eu/diario#entry-{entry.id}">#{entry.id}</a> di {entry.author or "Anonimo"}\n{entry.text}\n\n'
|
||||||
if len(entries) > 5:
|
if len(entries) > 5:
|
||||||
|
|
Loading…
Reference in a new issue