fix exact searching

pull/225/head
Aevann 2024-02-28 19:58:24 +02:00
parent be35a3d98d
commit 755a1ff60d
3 changed files with 9 additions and 4 deletions

View File

@ -229,9 +229,11 @@ def searchcomments(v):
if 'q' in criteria:
text = criteria['full_text']
if '"' in text: regconfig = "simple"
else: regconfig = "english"
comments = comments.filter(
Comment.body_ts.bool_op("@@")(
func.websearch_to_tsquery("english", text)
func.websearch_to_tsquery(regconfig, text)
)
)
@ -328,9 +330,11 @@ def searchmessages(v):
if 'q' in criteria:
text = criteria['full_text']
if '"' in text: regconfig = "simple"
else: regconfig = "english"
comments = comments.filter(
Comment.body_ts.bool_op("@@")(
func.websearch_to_tsquery("english", text)
func.websearch_to_tsquery(regconfig, text)
)
)

View File

@ -0,0 +1,2 @@
alter table comments drop column body_ts;
alter table comments add column body_ts tsvector GENERATED ALWAYS AS (to_tsvector('simple'::regconfig, (body)::text)) STORED;

View File

@ -459,7 +459,7 @@ CREATE TABLE public.comments (
queened boolean NOT NULL,
sharpened boolean NOT NULL,
num_of_pinned_children integer NOT NULL,
body_ts tsvector GENERATED ALWAYS AS (to_tsvector('english'::regconfig, (body)::text)) STORED,
body_ts tsvector GENERATED ALWAYS AS (to_tsvector('simple'::regconfig, (body)::text)) STORED,
distinguished boolean NOT NULL
);
@ -3074,4 +3074,3 @@ ALTER TABLE ONLY public.comments
--
-- PostgreSQL database dump complete
--