zhparser
zhparser copied to clipboard
当 zhparser 自定义词库 2.1 添加新词之后,Postgresql stored generated column 中自动重新生成的分词,在 Update 之后却没有生效。
维护者,您好。
这个 issue 虽然其实不确定是 zhparser 的问题,但是也许你们可以帮忙查找问题在哪里。
请看这个例子。
https://gist.github.com/zw963/212654fc1180d39be1d818392c96bb68
以及这个相关的讨论
https://groups.google.com/g/sequel-talk/c/iVVbSH10X1g
如果您看了上面的讨论,也许会认为这个问题跟 zhparser 相关性不大。
不过,我又做了一个是实验,但是这次,没有用 zhparser, 而是使用了一个新的从 simple 派生出来的 config, 但是无法复现这个问题,这至少说明,这个问题是跟 zhparser 相关的。
system("sudo -u postgres dropdb --if-exists check_sequel_db")
system("sudo -u postgres createdb check_sequel_db")
DB_URL="postgres://postgres:postgres@localhost:5432/check_sequel_db"
DB = Sequel.connect(DB_URL)
DB.create_table(:investing_latest_news, :ignore_index_errors=>true) do
primary_key :id
String :title, :text=>true, :null=>false
end
DB.run "CREATE TEXT SEARCH CONFIGURATION public.pg ( COPY = pg_catalog.simple );"
ALTER TABLE investing_latest_news
ADD COLUMN textsearchable_index_col tsvector GENERATED ALWAYS
AS
(
to_tsvector(
'pg',
coalesce(title, '')
)
)
STORED;
HEREDOC
DB.run 'CREATE INDEX investing_latest_news_textsearch_idx_index ON investing_latest_news USING GIN (textsearchable_index_col);'
class InvestingLatestNews < Sequel::Model
end
InvestingLatestNews.create(
title: 'Top 5 Things to Watch in Markets in the Week Ahead, [email protected]',
)
ap InvestingLatestNews.all
# [
# [0] #<InvestingLatestNews:0x00005616ae83c190> {
# :id => 1,
# :textsearchable_index_col => "'5':2 'ahead':11 '[email protected]':12 'in':6,8 'markets':7 'the':9 'things':3 'to':4 'top':1 'watch':5 'week':10",
# :title => "Top 5 Things to Watch in Markets in the Week Ahead, [email protected]"
# }
# ]
DB.run('ALTER TEXT SEARCH CONFIGURATION pg DROP MAPPING FOR email')
DB.run(Sequel.lit("update investing_latest_news set title=title"))
# 你可以看到,改变 config 之后,立即生效了。
# 但是正如前一个例子那样,如果增加新的 token 到 zhparser 自定义词库, 并不会。
ap InvestingLatestNews.all
# [
# [0] #<InvestingLatestNews:0x00005616ae914fb8> {
# :id => 1,
# :textsearchable_index_col => "'5':2 'ahead':11 'in':6,8 'markets':7 'the':9 'things':3 'to':4 'top':1 'watch':5 'week':10",
# :title => "Top 5 Things to Watch in Markets in the Week Ahead, [email protected]"
# }
# ]