restore exact searching for posts

pull/150/head
Aevann 2023-05-15 01:52:15 +03:00
parent ca7db123b2
commit 36d4aed1f5
2 changed files with 13 additions and 1 deletions

View File

@ -19,6 +19,7 @@ valid_params = [
'post',
'before',
'after',
'exact',
'title',
'sentto',
search_operator_hole,
@ -91,7 +92,14 @@ def searchposts(v:User):
), 403
posts = posts.filter(Submission.author_id == author.id)
if 'q' in criteria:
if 'exact' in criteria and 'full_text' in criteria:
regex_str = '[[:<:]]'+criteria['full_text']+'[[:>:]]' # https://docs.oracle.com/cd/E17952_01/mysql-5.5-en/regexp.html "word boundaries"
if 'title' in criteria:
words = [Submission.title.regexp_match(regex_str)]
else:
words = [or_(Submission.title.regexp_match(regex_str), Submission.body.regexp_match(regex_str))]
posts = posts.filter(*words)
elif 'q' in criteria:
if('title' in criteria):
words = [or_(Submission.title.ilike('%'+x+'%')) \
for x in criteria['q']]

View File

@ -78,6 +78,10 @@
<div style="display: inline-block; width: 150px; text-align: center;">Post Title Only:</div>
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">title:true</button>
</div>
<div>
<div style="display: inline-block; width: 150px; text-align: center;">Exact Match Only:</div>
<button type="button" data-nonce="{{g.nonce}}" data-onclick="addParam()" class="searchparam mb-1">exact:true</button>
</div>
{% endif %}
{% endif %}
</div>