postgresql创建简单搜索视图

--创建search_company
CREATE MATERIALIZED VIEW search_company AS SELECT DISTINCT a.company_id,
a.ticker,
a.company_status_id,
a.company_name_cn,
a.company_name_en,
a.company_shortname_cn,
a.company_shortname_en,
b.brand_name,
a.year_founded,
c.name_cn AS company_status_name_cn,
c.name_en AS company_status_name_en
FROM ((company_profile a
LEFT JOIN brand_info b ON (((a.company_id)::text = (b.company_id)::text)))
LEFT JOIN config.dictionary c ON (((a.company_status_id)::text = (c.id)::text)))
WHERE a.company_status_id!='3.3'
ORDER BY a.ticker;

--导入自定义函数(扩展包)
CREATE EXTENSION zhparser;
CREATE TEXT SEARCH CONFIGURATION zhcfg (PARSER = zhparser);
ALTER TEXT SEARCH CONFIGURATION zhcfg ADD MAPPING FOR n,v,a,i,e,l WITH simple;
create extension pg_trgm;
create or replace function record_to_text(anyelement) returns text as $$
select $1::text;
$$ language sql strict immutable;

--创建全文索引
create index idx_search_company_gist on search_company using gist (record_to_text(search_company) gist_trgm_ops);
create index idx_search_company_gin on search_company using gin (record_to_text(search_company) gin_trgm_ops);

--检测索引是否正常
/*+ BitmapScan(search_company idx_search_company_gin) */ select * from search_company where record_to_text(search_company) ~ '经纬' and company_status_id like'3%' limit 99;

同步同一个表中的相关字段

--创建函数

CREATE OR REPLACE FUNCTION updateItemDDL(center_show varchar,item_ddl VARCHAR,table_name varchar,item varchar)
RETURNS
void as $$
UPDATE schema_table set center_show=$1,item_ddl=$2 WHERE "table_name"=$3 AND item=$4 AND "version"='v2';
$$ LANGUAGE 'sql' VOLATILE;

--执行函数

SELECT updateItemDDL(center_show,item_ddl,"table_name",item) from schema_table WHERE "version"='v1' AND item_ddl!='';

查询是否执行成功

SELECT "table_name",item,center_show,item_ddl from schema_table WHERE "version"='v2' AND item_ddl!=''

Linux常用命令记录

运行

/alidata/soft/analysis-pdf# java -jar analysis-pdf.jar

查看文件 ls

cd 进入文件,切换目录

navicat注册码
NAVC-OP7Y-6OMV-XO4S

查看正在执行的程序
ps -ef|grep analysis-pdf

结束程序运行(14729程序前的代号)
kill -9 14729

查看日志
tail -f analysis....out

查看最后一千行
tail -f -n 1000 analysis-pdf-nohup.out

查看全部日志
cat analysis-pdf-nohup.out

退出(退出查看日志或退出程序)
Ctrl+C

暂停进程
kill -stop 1234

恢复到后台
kill -cont 1234

查询暂停的进程
jobs

如果只有一个暂停的进程:fg
如果有多个就fg 2(进程前的编号)

后台运行程序
nohup java -jar api-regular.jar >api-regular-nohup.out &

重启solr
buntu:/alidata/solr-6.6.0# bin/solr restart
root@ubuntu:/alidata/solr-6.6.0# bin/solr restart -force

新建文件夹 mkdir search

给用户jyd加权限使其能够访问elasticsearch
chown -R jyd elasticsearch

切换用户
su jyd

elasticsearch运行
bin下 ./elasticsearch