wiki pages: change tsvector update trigger to not use test_parser.
Change the wiki_pages tsvector_update_trigger to use `pg_catalog.english` instead of `public.danbooru`. This changes how wiki page text is parsed for full-text search to use the standard English parser instead of test_parser. This is to prepare for dropping test_parser. Using test_parser here was wrong anyway because it meant that punctuation wasn't removed from words when indexing wiki pages for full-text search.
This commit is contained in:
@@ -194,7 +194,7 @@ module Searchable
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def text_attribute_matches(attribute, value, index_column: nil, ts_config: "english")
|
def text_attribute_matches(attribute, value, index_column: nil)
|
||||||
return all unless value.present?
|
return all unless value.present?
|
||||||
|
|
||||||
column = column_for_attribute(attribute)
|
column = column_for_attribute(attribute)
|
||||||
@@ -203,9 +203,9 @@ module Searchable
|
|||||||
if value =~ /\*/
|
if value =~ /\*/
|
||||||
where("lower(#{qualified_column}) LIKE :value ESCAPE E'\\\\'", value: value.mb_chars.downcase.to_escaped_for_sql_like)
|
where("lower(#{qualified_column}) LIKE :value ESCAPE E'\\\\'", value: value.mb_chars.downcase.to_escaped_for_sql_like)
|
||||||
elsif index_column.present?
|
elsif index_column.present?
|
||||||
where("#{table_name}.#{index_column} @@ plainto_tsquery(:ts_config, :value)", ts_config: ts_config, value: value)
|
where("#{table_name}.#{index_column} @@ plainto_tsquery('english', :value)", value: value)
|
||||||
else
|
else
|
||||||
where("to_tsvector(:ts_config, #{qualified_column}) @@ plainto_tsquery(:ts_config, :value)", ts_config: ts_config, value: value)
|
where("to_tsvector('english', #{qualified_column}) @@ plainto_tsquery('english', :value)", value: value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class WikiPage < ApplicationRecord
|
|||||||
|
|
||||||
def search(params = {})
|
def search(params = {})
|
||||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_locked, :is_deleted, :body, :title, :other_names, :tag, :artist, :dtext_links)
|
q = search_attributes(params, :id, :created_at, :updated_at, :is_locked, :is_deleted, :body, :title, :other_names, :tag, :artist, :dtext_links)
|
||||||
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index, ts_config: "danbooru")
|
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index)
|
||||||
|
|
||||||
if params[:title_normalize].present?
|
if params[:title_normalize].present?
|
||||||
q = q.where_like(:title, normalize_title(params[:title_normalize]))
|
q = q.where_like(:title, normalize_title(params[:title_normalize]))
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
class ChangeTsVectorTriggerOnWikiPages < ActiveRecord::Migration[6.1]
|
||||||
|
def up
|
||||||
|
execute("DROP TRIGGER trigger_wiki_pages_on_update ON wiki_pages")
|
||||||
|
execute("CREATE TRIGGER trigger_wiki_pages_on_update BEFORE INSERT OR UPDATE ON public.wiki_pages FOR EACH ROW EXECUTE FUNCTION tsvector_update_trigger('body_index', 'pg_catalog.english', 'body', 'title')")
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
execute("DROP TRIGGER trigger_wiki_pages_on_update ON wiki_pages")
|
||||||
|
execute("CREATE TRIGGER trigger_wiki_pages_on_update BEFORE INSERT OR UPDATE ON public.wiki_pages FOR EACH ROW EXECUTE FUNCTION tsvector_update_trigger('body_index', 'public.danbooru', 'body', 'title')")
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -4801,7 +4801,7 @@ CREATE TRIGGER trigger_posts_on_tag_index_update BEFORE INSERT OR UPDATE ON publ
|
|||||||
-- Name: wiki_pages trigger_wiki_pages_on_update; Type: TRIGGER; Schema: public; Owner: -
|
-- Name: wiki_pages trigger_wiki_pages_on_update; Type: TRIGGER; Schema: public; Owner: -
|
||||||
--
|
--
|
||||||
|
|
||||||
CREATE TRIGGER trigger_wiki_pages_on_update BEFORE INSERT OR UPDATE ON public.wiki_pages FOR EACH ROW EXECUTE FUNCTION tsvector_update_trigger('body_index', 'public.danbooru', 'body', 'title');
|
CREATE TRIGGER trigger_wiki_pages_on_update BEFORE INSERT OR UPDATE ON public.wiki_pages FOR EACH ROW EXECUTE FUNCTION tsvector_update_trigger('body_index', 'pg_catalog.english', 'body', 'title');
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -5059,6 +5059,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||||||
('20210926123414'),
|
('20210926123414'),
|
||||||
('20210926125826'),
|
('20210926125826'),
|
||||||
('20211008091234'),
|
('20211008091234'),
|
||||||
('20211010181657');
|
('20211010181657'),
|
||||||
|
('20211011044400');
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user