1. 程式人生 > 實用技巧 >PostgreSQL 中文全文檢索 (使用zhparser) 記錄踩坑過程

PostgreSQL 中文全文檢索 (使用zhparser) 記錄踩坑過程

1: 系統已經安裝了postgresql 資料 (不管有沒有安裝全,總之已經可以建立資料庫,建立表,查詢....了)

2:檢視已安裝的資料庫版本

postgres=# select version();
version
----------------------------------------------------------------------------------------------------------
PostgreSQL 10.10 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit
(1 row)

3: 需要安裝(如果已經安裝了就不用安裝了,看好一共是3個 聯絡我QQ 820688215 可以互相學些PG)

yum -y install postgresql10-server postgresql10-contrib postgresql10-devel

4: 看一下自己的資料安裝路徑,然後配置環境變數

export PATH=/usr/pgsql-10/bin:$PATH

5:下載

安裝SCWS
因為zhparser是基於SCWS(簡易中文分詞系統)開發的。所以必須首先安裝SCWS。 ·

自行建立安裝目錄

[root@jxstar-dev home]# wget http://www.xunsearch.com/scws/down/scws-1.2.2.tar.bz2
--2020-12-22 18:13:20--  http://www.xunsearch.com/scws/down/scws-1.2.2.tar.bz2
正在解析主機 www.xunsearch.com (www.xunsearch.com)... 202.75.214.12
正在連線 www.xunsearch.com (www.xunsearch.com)|202.75.214.12|:80... 已連線。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:435267 (425K) [text/plain]
正在儲存至: “scws-1.2.2.tar.bz2”

100%[=======================================================================================================================================================>] 435,267     --.-K/s 用時 0.1s

2020-12-22 18:13:21 (2.80 MB/s) - 已儲存 “scws-1.2.2.tar.bz2” [435267/435267])

[root@jxstar-dev home]# tar xvf scws-1.2.2.tar.bz2
scws-1.2.2/
scws-1.2.2/aclocal.m4
scws-1.2.2/API.md
scws-1.2.2/AUTHORS
scws-1.2.2/ChangeLog
scws-1.2.2/cli/
scws-1.2.2/config.guess
scws-1.2.2/config.h.in
scws-1.2.2/config.sub
scws-1.2.2/configure
scws-1.2.2/configure.ac
scws-1.2.2/COPYING
scws-1.2.2/depcomp
scws-1.2.2/etc/
scws-1.2.2/INSTALL
scws-1.2.2/install-sh
scws-1.2.2/libscws/
scws-1.2.2/ltmain.sh
scws-1.2.2/Makefile.am
scws-1.2.2/Makefile.in
scws-1.2.2/missing
scws-1.2.2/NEWS
scws-1.2.2/phpext/
scws-1.2.2/README
scws-1.2.2/win32/
scws-1.2.2/win32/libscws.dsp
scws-1.2.2/win32/libscws.vcproj
scws-1.2.2/win32/readme.txt
scws-1.2.2/win32/scws.dsp
scws-1.2.2/win32/scws.dsw
scws-1.2.2/win32/scws.sln
scws-1.2.2/win32/scws.vcproj
scws-1.2.2/phpext/config.m4
scws-1.2.2/phpext/CREDITS
scws-1.2.2/phpext/php_scws.c
scws-1.2.2/phpext/php_scws.h
scws-1.2.2/phpext/README.md
scws-1.2.2/phpext/scws.php
scws-1.2.2/phpext/scws_test.php
scws-1.2.2/phpext/win32/
scws-1.2.2/phpext/win32/php_scws-1.2.2-win32.zip
scws-1.2.2/phpext/win32/README.txt
scws-1.2.2/libscws/charset.c
scws-1.2.2/libscws/charset.h
scws-1.2.2/libscws/config_win32.h
scws-1.2.2/libscws/crc32.c
scws-1.2.2/libscws/crc32.h
scws-1.2.2/libscws/darray.c
scws-1.2.2/libscws/darray.h
scws-1.2.2/libscws/lock.c
scws-1.2.2/libscws/lock.h
scws-1.2.2/libscws/Makefile.am
scws-1.2.2/libscws/Makefile.in
scws-1.2.2/libscws/pool.c
scws-1.2.2/libscws/pool.h
scws-1.2.2/libscws/rule.c
scws-1.2.2/libscws/rule.h
scws-1.2.2/libscws/scws.c
scws-1.2.2/libscws/scws.h
scws-1.2.2/libscws/version.h
scws-1.2.2/libscws/version.h.in
scws-1.2.2/libscws/xdb.c
scws-1.2.2/libscws/xdb.h
scws-1.2.2/libscws/xdict.c
scws-1.2.2/libscws/xdict.h
scws-1.2.2/libscws/xtree.c
scws-1.2.2/libscws/xtree.h
scws-1.2.2/etc/Makefile.am
scws-1.2.2/etc/Makefile.in
scws-1.2.2/etc/rules.ini
scws-1.2.2/etc/rules.utf8.ini
scws-1.2.2/etc/rules_cht.utf8.ini
scws-1.2.2/cli/gen_dict.c
scws-1.2.2/cli/Makefile.am
scws-1.2.2/cli/Makefile.in
scws-1.2.2/cli/scws_cmd.c

//1>報錯了!!!!!

[root@jxstar-dev scws-1.2.2]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... no  ////////////////////////////////////////
checking for cc... no   ////////////////////////////////////////這三個沒有安裝 需要yum install gcc cc cl.exe
checking for cl.exe... no ////////////////////////////////////////
configure: error: in `/home/scws-1.2.2':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

再次執行正確

[root@jxstar-dev scws-1.2.2]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for a sed that does not truncate output... /usr/bin/sed
checking whether ln -s works... yes
checking whether make sets $(MAKE)... (cached) yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking for /usr/bin/ld option to reload object files... -r
checking how to recognize dependent libraries... pass_all
checking for ar... ar
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC -DPIC
checking if gcc PIC flag -fPIC -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking for logf in -lm... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking netinet/in.h usability... yes
checking netinet/in.h presence... yes
checking for netinet/in.h... yes
checking math.h usability... yes
checking math.h presence... yes
checking for math.h... yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking sys/file.h usability... yes
checking sys/file.h presence... yes
checking for sys/file.h... yes
checking sys/param.h usability... yes
checking sys/param.h presence... yes
checking for sys/param.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking for inline... inline
checking whether time.h and sys/time.h may both be included... yes
checking size of int... 4
checking size of float... 4
checking for struct flock...
checking whether lstat correctly handles trailing slash... yes
checking whether lstat accepts an empty string... no
checking whether lstat correctly handles trailing slash... (cached) yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... (cached) yes
checking for getpagesize... yes
checking for working mmap... yes
checking for working memcmp... yes
checking for flock... yes
checking for gettimeofday... yes
checking for malloc... yes
checking for memset... yes
checking for munmap... yes
checking for pow... yes
checking for realpath... yes
checking for strcasecmp... yes
checking for strchr... yes
checking for strdup... yes
checking for strrchr... yes
checking for strndup... yes
checking for strtok_r... yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating cli/Makefile
config.status: creating etc/Makefile
config.status: creating libscws/Makefile
config.status: creating libscws/version.h
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands

繼續報錯!!

[root@jxstar-dev scws-1.2.2]# make isntall
make: *** 沒有規則可以建立目標“isntall”。 停止。///////////////輸錯單詞了install

再次執行

[root@jxstar-dev scws-1.2.2]# make install
Making install in .
make[1]: 進入目錄“/home/scws-1.2.2”
make[2]: 進入目錄“/home/scws-1.2.2”
make[2]: 對“install-exec-am”無需做任何事。
make[2]: 對“install-data-am”無需做任何事。
make[2]: 離開目錄“/home/scws-1.2.2”
make[1]: 離開目錄“/home/scws-1.2.2”
Making install in libscws
make[1]: 進入目錄“/home/scws-1.2.2/libscws”
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT charset.lo -MD -MP -MF .deps/charset.Tpo -c -o charset.lo charset.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT charset.lo -MD -MP -MF .deps/charset.Tpo -c charset.c  -fPIC -DPIC -o .libs/charset.o
mv -f .deps/charset.Tpo .deps/charset.Plo
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT crc32.lo -MD -MP -MF .deps/crc32.Tpo -c -o crc32.lo crc32.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT crc32.lo -MD -MP -MF .deps/crc32.Tpo -c crc32.c  -fPIC -DPIC -o .libs/crc32.o
mv -f .deps/crc32.Tpo .deps/crc32.Plo
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT pool.lo -MD -MP -MF .deps/pool.Tpo -c -o pool.lo pool.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT pool.lo -MD -MP -MF .deps/pool.Tpo -c pool.c  -fPIC -DPIC -o .libs/pool.o
mv -f .deps/pool.Tpo .deps/pool.Plo
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT scws.lo -MD -MP -MF .deps/scws.Tpo -c -o scws.lo scws.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT scws.lo -MD -MP -MF .deps/scws.Tpo -c scws.c  -fPIC -DPIC -o .libs/scws.o
mv -f .deps/scws.Tpo .deps/scws.Plo
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT xdict.lo -MD -MP -MF .deps/xdict.Tpo -c -o xdict.lo xdict.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT xdict.lo -MD -MP -MF .deps/xdict.Tpo -c xdict.c  -fPIC -DPIC -o .libs/xdict.o
mv -f .deps/xdict.Tpo .deps/xdict.Plo
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT darray.lo -MD -MP -MF .deps/darray.Tpo -c -o darray.lo darray.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT darray.lo -MD -MP -MF .deps/darray.Tpo -c darray.c  -fPIC -DPIC -o .libs/darray.o
mv -f .deps/darray.Tpo .deps/darray.Plo
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT rule.lo -MD -MP -MF .deps/rule.Tpo -c -o rule.lo rule.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT rule.lo -MD -MP -MF .deps/rule.Tpo -c rule.c  -fPIC -DPIC -o .libs/rule.o
mv -f .deps/rule.Tpo .deps/rule.Plo
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT lock.lo -MD -MP -MF .deps/lock.Tpo -c -o lock.lo lock.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT lock.lo -MD -MP -MF .deps/lock.Tpo -c lock.c  -fPIC -DPIC -o .libs/lock.o
mv -f .deps/lock.Tpo .deps/lock.Plo
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT xdb.lo -MD -MP -MF .deps/xdb.Tpo -c -o xdb.lo xdb.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT xdb.lo -MD -MP -MF .deps/xdb.Tpo -c xdb.c  -fPIC -DPIC -o .libs/xdb.o
mv -f .deps/xdb.Tpo .deps/xdb.Plo
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I..     -g -O2 -MT xtree.lo -MD -MP -MF .deps/xtree.Tpo -c -o xtree.lo xtree.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -MT xtree.lo -MD -MP -MF .deps/xtree.Tpo -c xtree.c  -fPIC -DPIC -o .libs/xtree.o
mv -f .deps/xtree.Tpo .deps/xtree.Plo
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=link gcc  -g -O2 -no-undefined -version-info 2:0:1  -o libscws.la -rpath /usr/local/lib charset.lo crc32.lo pool.lo scws.lo xdict.lo darray.lo rule.lo lock.lo xdb.lo xtree.lo  -lm
libtool: link: gcc -shared  .libs/charset.o .libs/crc32.o .libs/pool.o .libs/scws.o .libs/xdict.o .libs/darray.o .libs/rule.o .libs/lock.o .libs/xdb.o .libs/xtree.o   -lm    -Wl,-soname -Wl,libscws.so.1 -o .libs/libscws.so.1.1.0
libtool: link: (cd ".libs" && rm -f "libscws.so.1" && ln -s "libscws.so.1.1.0" "libscws.so.1")
libtool: link: (cd ".libs" && rm -f "libscws.so" && ln -s "libscws.so.1.1.0" "libscws.so")
libtool: link: ( cd ".libs" && rm -f "libscws.la" && ln -s "../libscws.la" "libscws.la" )
make[2]: 進入目錄“/home/scws-1.2.2/libscws”
test -z "/usr/local/lib" || /usr/bin/mkdir -p "/usr/local/lib"
 /bin/sh ../libtool --preserve-dup-deps  --mode=install /usr/bin/install -c  'libscws.la' '/usr/local/lib/libscws.la'
libtool: install: /usr/bin/install -c .libs/libscws.so.1.1.0 /usr/local/lib/libscws.so.1.1.0
libtool: install: (cd /usr/local/lib && { ln -s -f libscws.so.1.1.0 libscws.so.1 || { rm -f libscws.so.1 && ln -s libscws.so.1.1.0 libscws.so.1; }; })
libtool: install: (cd /usr/local/lib && { ln -s -f libscws.so.1.1.0 libscws.so || { rm -f libscws.so && ln -s libscws.so.1.1.0 libscws.so; }; })
libtool: install: /usr/bin/install -c .libs/libscws.lai /usr/local/lib/libscws.la
libtool: finish: PATH="/usr/pgsql-10/bin:/usr/pgsql-10/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/java/jdk1.8.0_221/bin:/root/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/usr/local/include/scws" || /usr/bin/mkdir -p "/usr/local/include/scws"
 /usr/bin/install -c -m 644 'charset.h' '/usr/local/include/scws/charset.h'
 /usr/bin/install -c -m 644 'crc32.h' '/usr/local/include/scws/crc32.h'
 /usr/bin/install -c -m 644 'pool.h' '/usr/local/include/scws/pool.h'
 /usr/bin/install -c -m 644 'scws.h' '/usr/local/include/scws/scws.h'
 /usr/bin/install -c -m 644 'xdict.h' '/usr/local/include/scws/xdict.h'
 /usr/bin/install -c -m 644 'darray.h' '/usr/local/include/scws/darray.h'
 /usr/bin/install -c -m 644 'rule.h' '/usr/local/include/scws/rule.h'
 /usr/bin/install -c -m 644 'xdb.h' '/usr/local/include/scws/xdb.h'
 /usr/bin/install -c -m 644 'xtree.h' '/usr/local/include/scws/xtree.h'
 /usr/bin/install -c -m 644 'version.h' '/usr/local/include/scws/version.h'
make[2]: 離開目錄“/home/scws-1.2.2/libscws”
make[1]: 離開目錄“/home/scws-1.2.2/libscws”
Making install in cli
make[1]: 進入目錄“/home/scws-1.2.2/cli”
gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../libscws    -g -O2 -MT scws_cmd.o -MD -MP -MF .deps/scws_cmd.Tpo -c -o scws_cmd.o scws_cmd.c
mv -f .deps/scws_cmd.Tpo .deps/scws_cmd.Po
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=link gcc  -g -O2   -o scws scws_cmd.o ../libscws/libscws.la -lm
libtool: link: gcc -g -O2 -o .libs/scws scws_cmd.o  ../libscws/.libs/libscws.so -lm -Wl,-rpath -Wl,/usr/local/lib
gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I../libscws    -g -O2 -MT gen_dict.o -MD -MP -MF .deps/gen_dict.Tpo -c -o gen_dict.o gen_dict.c
mv -f .deps/gen_dict.Tpo .deps/gen_dict.Po
/bin/sh ../libtool --preserve-dup-deps  --tag=CC   --mode=link gcc  -g -O2   -o scws-gen-dict gen_dict.o ../libscws/libscws.la -lm
libtool: link: gcc -g -O2 -o .libs/scws-gen-dict gen_dict.o  ../libscws/.libs/libscws.so -lm -Wl,-rpath -Wl,/usr/local/lib
make[2]: 進入目錄“/home/scws-1.2.2/cli”
test -z "/usr/local/bin" || /usr/bin/mkdir -p "/usr/local/bin"
  /bin/sh ../libtool --preserve-dup-deps  --mode=install /usr/bin/install -c 'scws' '/usr/local/bin/scws'
libtool: install: /usr/bin/install -c .libs/scws /usr/local/bin/scws
  /bin/sh ../libtool --preserve-dup-deps  --mode=install /usr/bin/install -c 'scws-gen-dict' '/usr/local/bin/scws-gen-dict'
libtool: install: /usr/bin/install -c .libs/scws-gen-dict /usr/local/bin/scws-gen-dict
make[2]: 對“install-data-am”無需做任何事。
make[2]: 離開目錄“/home/scws-1.2.2/cli”
make[1]: 離開目錄“/home/scws-1.2.2/cli”
Making install in etc
make[1]: 進入目錄“/home/scws-1.2.2/etc”
make[2]: 進入目錄“/home/scws-1.2.2/etc”
test -z "/usr/local/etc" || /usr/bin/mkdir -p "/usr/local/etc"
 /usr/bin/install -c -m 644 'rules.ini' '/usr/local/etc/rules.ini'
 /usr/bin/install -c -m 644 'rules.utf8.ini' '/usr/local/etc/rules.utf8.ini'
 /usr/bin/install -c -m 644 'rules_cht.utf8.ini' '/usr/local/etc/rules_cht.utf8.ini'
make[2]: 對“install-data-am”無需做任何事。
make[2]: 離開目錄“/home/scws-1.2.2/etc”
make[1]: 離開目錄“/home/scws-1.2.2/etc”

是否安裝成功

檢視 scws 安裝目錄

[root@db1 scws-1.2.2]# ls /usr/local/include/scws/
charset.h crc32.h darray.h pool.h rule.h scws.h version.h xdb.h xdict.h xtree.h

6:安裝zhparser

https://github.com/amutu/zhparser/archive/master.zip

[root@jxstar-dev home]# unzip zhparser-master.zip
Archive:  zhparser-master.zip
127a31b39db1b4ccc851f254683ced9a1fa837bd
   creating: zhparser-master/
  inflating: zhparser-master/CHANGELOG
  inflating: zhparser-master/COPYRIGHT
  inflating: zhparser-master/META.json
  inflating: zhparser-master/Makefile
  inflating: zhparser-master/README.md
  inflating: zhparser-master/check.sh
  inflating: zhparser-master/dict.utf8.xdb
  inflating: zhparser-master/dict_extra.txt
   creating: zhparser-master/expected/
  inflating: zhparser-master/expected/zhparser.out
  inflating: zhparser-master/rules.utf8.ini
   creating: zhparser-master/sql/
  inflating: zhparser-master/sql/zhparser.sql
  inflating: zhparser-master/zhparser--1.0--2.0.sql
  inflating: zhparser-master/zhparser--1.0.sql
  inflating: zhparser-master/zhparser--2.0--2.1.sql
  inflating: zhparser-master/zhparser--2.0.sql
  inflating: zhparser-master/zhparser--2.1.sql
  inflating: zhparser-master/zhparser--unpackaged--1.0.sql
  inflating: zhparser-master/zhparser.c
  inflating: zhparser-master/zhparser.control
  inflating: zhparser-master/zhparser.h

開始報錯:

[root@jxstar-dev home]# cd zhparser-master/
[root@jxstar-dev zhparser-master]# SCWS_HOME=/usr/local make&&make install
make: pg_config:命令未找到
make: *** 無目標。 停止。

需要找到你pg_config 如果沒有的話

yum install postgresql-devel

安裝完畢後察看
/usr/bin/pg_config 可以檢視到了
繼續執行
[root@jxstar-dev zhparser-master]# SCWS_HOME=/usr/local make&&make install
gcc -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -DLINUX_OOM_SCORE_ADJ=0 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -fPIC -I/usr/local/include/scws  -I. -I. -I/usr/include/pgsql/server -I/usr/include/pgsql/internal -D_GNU_SOURCE -I/usr/include/libxml2   -c -o zhparser.o zhparser.c
zhparser.c:15:27: 致命錯誤:utils/varlena.h:沒有那個檔案或目錄
 #include "utils/varlena.h"
                           ^
編譯中斷。
make: *** [zhparser.o] 錯誤 1

重新配置一下環境變數就好了,不知道為什麼,可以評論解釋或者加QQ820688215 交流
[root@jxstar-dev zhparser-master]#  export PATH=/usr/pgsql-10/bin:$PATH
[root@jxstar-dev zhparser-master]# pg_config=/usr/bin/pg_config make && make install  //////////////或者執行SCWS_HOME=/usr/local make&&make install 一樣的
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -I/usr/local/include/scws  -I. -I./ -I/usr/pgsql-10/include/server -I/usr/pgsql-10/include/internal  -D_GNU_SOURCE -I/usr/include/libxml2  -I/usr/include  -c -o zhparser.o zhparser.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC -shared -o zhparser.so zhparser.o -L/usr/pgsql-10/lib  -Wl,--as-needed  -L/usr/lib64 -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-10/lib',--enable-new-dtags  -lscws -L/usr/local/lib -Wl,-rpath -Wl,/usr/local/lib
/bin/mkdir -p '/usr/pgsql-10/lib'
/bin/mkdir -p '/usr/pgsql-10/share/extension'
/bin/mkdir -p '/usr/pgsql-10/share/extension'
/bin/mkdir -p '/usr/pgsql-10/share/tsearch_data'
/bin/install -c -m 755  zhparser.so '/usr/pgsql-10/lib/zhparser.so'
/bin/install -c -m 644 .//zhparser.control '/usr/pgsql-10/share/extension/'
/bin/install -c -m 644 .//zhparser--1.0.sql .//zhparser--unpackaged--1.0.sql .//zhparser--1.0--2.0.sql .//zhparser--2.0.sql .//zhparser--2.0--2.1.sql .//zhparser--2.1.sql  '/usr/pgsql-10/share/extension/'
/bin/install -c -m 644 .//dict.utf8.xdb .//rules.utf8.ini '/usr/pgsql-10/share/tsearch_data/'

到此安裝完畢!

開始使用一下:

切換到postgres賬戶

建立extension
整理好這些檔案後,就可以繼續建立extension了。
切換到postgres賬戶

	su - postgres


·3.2.2 安裝擴充套件(每新建一個數據庫都需要執行這一步;這裡我直接使用的已有的一個測試資料庫)

#查詢已有的解析器
knowledge=# \dFp
[root@jxstar-dev zhparser-master]# su postgres
bash-4.2$ psql -Upostgres
psql (10.15)
輸入 "help" 來獲取幫助資訊.

postgres=# \dFp
               文字剖析器列表
  架構模式  |  名稱   |        描述
------------+---------+---------------------
 pg_catalog | default | default word parser
(1 行記錄)

postgres=#

postgres=# create extension zhparser;
CREATE EXTENSION
postgres=# \dFp
               文字剖析器列表
  架構模式  |   名稱   |        描述
------------+----------+---------------------
 pg_catalog | default  | default word parser
 public     | zhparser |
(2 行記錄)

postgres=# CREATE TEXT SEARCH CONFIGURATION testzhcfg (PARSER = zhparser);
CREATE TEXT SEARCH CONFIGURATION
postgres=# ALTER TEXT SEARCH CONFIGURATION testzhcfg ADD MAPPING FOR n,v,a,i,e,l WITH simple;
ALTER TEXT SEARCH CONFIGURATION

建立名為testzhcfg的 可以在sql中使用的解析器

-- make test configuration using parser

//這樣解析器就新增到當前資料庫了。但是此時還是不能用,還需要建立使用zhparser作為解析器的全文搜尋的配置,也就是需要給zhparser解析器

取一個在sql裡面可以使用的名字。這裡測試取的是(‘testzhcfg ’)。

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;

//#查詢已有的解析器
knowledge=# \dFp

/////////////測試
-- ts_parse

SELECT * FROM ts_parse('zhparser', 'hello world! 2010年保障房建設在全國範圍內獲全面啟動,從中央到地方紛紛加大 了保障房的建設和投入

力度 。2011年,保障房進入了更大規模的建設階段。住房城鄉建設部黨組書記、部長姜偉新去年底在全國住房城鄉建設工作會議上表示,要繼續推

進保障性安居工程建設。');

-- test to_tsvector

SELECT to_tsvector('testzhcfg','“今年保障房新開工數量雖然有所下調,但實際的年度在建規模以及竣工規模會超以往年份,相對應的對資金的

需求也會創歷>史紀錄。”陳國強說。在他看來,與2011年相比,2012年的保障房建設在資金配套上的壓力將更為嚴峻。');

-- test to_tsquery

SELECT to_tsquery('testzhcfg', '保障房資金壓力');