環(huán)境
CentOS Linux release 7.2.1511 (Core)
安裝Postgres
安裝postgres很簡單
- yum安裝
sudo yum install postgresql-server postgresql-contrib postgresql-devel - 初始化數(shù)據(jù)庫
sudo postgresql-setup initdb
配置密碼和遠(yuǎn)程訪問
- 修改
/var/lib/pgsql/data/pg_hba.conf
原本的
host all all 127.0.0.1/32 ident
host all all ::1/128 ident
修改之后
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5
修改
/var/lib/pgsql/data/postgresql.conf
原本的
#listen_addresses=’localhost'
修改之后
#listen_addresses=’*'增加密碼
su - postgres
psql
alter user postgres with password '123456';
- 啟動服務(wù)
systemctl start postgresql
systemctl enable postgresql
安裝中文分詞插件zhparser
- 安裝SCWS
wget http://www.xunsearch.com/scws/down/scws-1.2.3.tar.bz2
tar xf scws-1.2.3.tar.bz2
cd scws-1.2.3
./configure
make install
- 安裝zhparser
git clone https://github.com/amutu/zhparser.git
make && make install
實驗
-- create the extension
CREATE EXTENSION zhparser;
-- make test configuration using parser
CREATE TEXT SEARCH CONFIGURATION testzhcfg (PARSER = zhparser);
-- add token mapping
ALTER TEXT SEARCH CONFIGURATION testzhcfg ADD MAPPING FOR n,v,a,i,e,l WITH simple;
-- ts_parse
SELECT * FROM ts_parse('zhparser', 'hello world! 2010年保障房建設(shè)在全國范圍內(nèi)獲全面啟動,從中央到地方紛紛加大 了保障房的建設(shè)和投入力度 。2011年,保障房進(jìn)入了更大規(guī)模的建設(shè)階段。住房城鄉(xiāng)建設(shè)部黨組書記、部長姜偉新去年底在全國住房城鄉(xiāng)建設(shè)工作會議上表示,要繼續(xù)推進(jìn)保障性安居工程建設(shè)。');
----------------------------------------------------------------------------
結(jié)果
----------------------------------------------------------------------------
tokid | token
-------+----------
101 | hello
101 | world
117 | !
101 | 2010
113 | 年
118 | 保障
110 | 房建
-- test to_tsvector
SELECT to_tsvector('testzhcfg','“今年保障房新開工數(shù)量雖然有所下調(diào),但實際的年度在建規(guī)模以及竣工規(guī)模會超以往年份,相對應(yīng)的對資金的需求也會創(chuàng)歷>史紀(jì)錄?!标悋鴱?qiáng)說。在他看來,與2011年相比,2012年的保障房建設(shè)在資金配套上的壓力將更為嚴(yán)峻。') as result;
----------------------------------------------------------------------------
結(jié)果
----------------------------------------------------------------------------
'2011':27 '2012':29 '上':35 '下調(diào)':7 '嚴(yán)峻':37 '會':14 '會創(chuàng)':20 '保障':1,30 '壓力':36 '史':21 '國強(qiáng)'
:24 '在建':10 '實際':8 '對應(yīng)':17 '年份':16 '年度':9 '開工':4 '房':2 '房建':31 '數(shù)量':5 '新':3 '有所':6
'相比':28 '看來':26 '竣工':12 '紀(jì)錄':22 '規(guī)模':11,13 '設(shè)在':32 '說':25 '資金':18,33 '超':15 '配套':34
'陳':23 '需求':19
(1 row)
-- test to_tsquery
SELECT to_tsquery('testzhcfg', '保障房資金壓力');
----------------------------------------------------------------------------
結(jié)果
----------------------------------------------------------------------------
'保障' & '房' & '資金' & '壓力'
(1 row)