> php教程 > PHP开发 > 본문

LNMP+sphinx는 빅데이터의 즉각적인 쿼리를 실현합니다.

高洛峰
풀어 주다: 2016-12-01 13:58:41
원래의
1595명이 탐색했습니다.

Sphinx는 러시아인 Andrew Aksyonoff가 개발한 전체 텍스트 검색 엔진입니다. 다른 응용 프로그램에 대해 고속, 낮은 공간 점유 및 높은 결과 관련 전체 텍스트 검색 기능을 제공하기 위한 것입니다. Sphinx는 SQL 데이터베이스 및 스크립팅 언어와 쉽게 통합될 수 있습니다. 현재 시스템에는 MySQL 및 PostgreSQL 데이터베이스 데이터 소스에 대한 지원이 내장되어 있으며 표준 입력에서 특정 형식의 XML 데이터 읽기도 지원합니다.


Sphinx의 기능은 다음과 같습니다.

a) 고속 인덱싱(최신 CPU에서는 최대 성능이 10MB/초에 도달할 수 있음);

b) 고성능 검색(2~4GB의 텍스트 데이터에 대해 검색당 평균 응답 시간은 0.1초 미만),

c) 대용량 데이터 처리 가능(현재) 100GB 이상의 텍스트 데이터를 처리할 수 있는 것으로 알려져 있으며, 단일 CPU 시스템에서 1억 개의 문서를 처리할 수 있습니다.)

d) 관련성이 뛰어난 알고리즘, 구문 유사성을 기반으로 한 복합 순위 방법 및 통계(BM25);

e) 분산 검색 지원

f) 구문 검색 지원

g) 문서 요약 생성 제공

h) 가능 MySQL 스토리지 엔진 검색 서비스로 제공;

i) 부울, 구문, 단어 유사성 등과 같은 다양한 검색 모드 지원;

j) 문서는 여러 전체 텍스트 검색 필드 지원( 최대 32);

k) 문서는 여러 추가 속성 정보(예: 그룹화 정보, 타임스탬프 등)를 지원합니다.

l) 단어 분할 지원


mysql의 MYISAM은 전체 텍스트 인덱싱을 제공하지만 성능이 그다지 좋지 않습니다. 또한 데이터베이스는 결국 이러한 작업을 잘 수행하지 못하므로 이러한 작업을 더 적합한 프로그램에 맡겨야 합니다. 데이터베이스에 대한 압박. 따라서 Sphinx를 mysql의 전체 텍스트 인덱싱 도구로 사용하는 것이 좋은 선택입니다. 이번주에는 주로 이 도구를 사용하는 방법을 배울 것입니다. 학습 과정을 간략하게 기록하고 이 도구를 배우는 다른 친구들에게 영감을 줄 수 있기를 바랍니다.


스핑크스 설치

wget http://sphinxsearch.com/files/sphinx-2.2.11-release.tar.gz
tar -xf sphinx-2.2.11-release.tar.gz  && cd sphinx-2.2.11-release
./configure  --prefix=/usr/local/spinx --with-mysql
make && make install
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
libsphinxclient 安装(PHP模块需要)
cd api/libsphinxclient
./configure –prefix=/usr/local/sphinx
make &&  make install
로그인 후 복사

php 확장 설치

wget http://pecl.php.net/get/sphinx-1.3.0.tgz
tar zxf sphinx-1.3.3.tgz && cd sphinx-1.3.3
./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinx/
make &&  make install
로그인 후 복사


3. 구성 파일 생성

cp /usr/local/sphinx/etc/sphinx-min.conf.dist  /usr/local/sphinx/etc/sphinx.conf
로그인 후 복사

#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
 
source src1
{
        type                    = mysql
 
        sql_host                = localhost
        sql_user                = root
        sql_pass                = www.123
        sql_db                  = test
        sql_port                = 3306  # optional, default is 3306
 
        sql_query               = \
                SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
                FROM documents
 
        sql_attr_uint           = group_id
        sql_attr_timestamp      = date_added
}
 
 
index test1
{
        source                  = src1
        path                    = /usr/local/spinx/var/data/test1
}
 
 
indexer
{
        mem_limit               = 32M
}
 
 
searchd
{
        listen                  = 9312
        listen                  = 9306:mysql41
        log                     = /usr/local/spinx/var/log/searchd.log
        query_log               = /usr/local/spinx/var/log/query.log
        read_timeout            = 5
        max_children            = 30
        pid_file                = /usr/local/spinx/var/log/searchd.pid
        seamless_rotate         = 1
        preopen_indexes         = 1
        unlink_old              = 1
        workers                 = threads # for RT to work
        binlog_path             = /usr/local/spinx/var/data
}
로그인 후 복사


4. 인덱스 생성 및 시작

/usr/local/spinx/bin/indexer  -c /usr/local/spinx/etc/sphinx.conf --all
/usr/local/spinx/bin/searchd  -c /usr/local/spinx/etc/sphinx.conf
로그인 후 복사

5. >

cd /root/sphinx-2.2.11-release/api
python test.py  test
DEPRECATED: Do not call this method or, even better, use SphinxQL instead of an API
Query 'test ' retrieved 3 of 3 matches in 0.000 sec
Query stats:
        'test' found 5 times in 3 documents
Matches:
1. doc_id=1, weight=2, group_id=1, date_added=2016-11-30 01:21:20
2. doc_id=2, weight=2, group_id=1, date_added=2016-11-30 01:21:20
3. doc_id=4, weight=1, group_id=2, date_added=2016-11-30 01:21:20
로그인 후 복사


mysql> select * from documents;
+----+----------+-----------+---------------------+-----------------+---------------------------------------------------------------------------+
| id | group_id | group_id2 | date_added          | title           | content                                                                   |
+----+----------+-----------+---------------------+-----------------+---------------------------------------------------------------------------+
|  1 |        1 |         5 | 2016-11-30 01:21:20 | test one        | this is my test document number one. also checking search within phrases. |
|  2 |        1 |         6 | 2016-11-30 01:21:20 | test two        | this is my test document number two                                       |
|  3 |        2 |         7 | 2016-11-30 01:21:20 | another doc     | this is another group                                                     |
|  4 |        2 |         8 | 2016-11-30 01:21:20 | doc number four | this is to test groups                                                    |
+----+----------+-----------+---------------------+-----------------+---------------------------------------------------------------------------+
로그인 후 복사



관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!