sphinx3.1.1 window php

1. 下载地址

http://sphinxsearch.com/downloads/current/

2. 解压文件放到盘内

3. 根目录创建 data 和 log 文件夹

4. 复制 etc 目录下的 min.conf 到 bin 目录 并修改成 后缀.conf 文件

5. 修改.conf 内容

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

Minimal Sphinx configuration sample (clean, simple, functional)

source src1

{

type            = mysql

sql_host        = 127.0.0.1

sql_user        = root

sql_pass        = root

sql_db          = test

sql_port        = 3306  # optional, default is 3306

sql_query_pre   = SET NAMES utf8

sql_query       = \

    SELECT id,question \

    FROM questions



#sql_attr_uint      = group_id

#sql_attr_timestamp = date_added

}

index test1

{

source          = src1

path            = E:/sphinx-3.1.1/data/test1

ngram_len = 1

ngram_chars = U+3000..U+2FA1F

}

indexer

{

mem_limit       = 128M

}

searchd

{

listen          = 9312

listen          = 9306:mysql41

log         = E:/sphinx-3.1.1/log/searchd.log

query_log       = E:/sphinx-3.1.1/log/query.log

read_timeout        = 5

max_children        = 30

pid_file        = E:/sphinx-3.1.1/log/searchd.pid

seamless_rotate     = 1

preopen_indexes     = 1

unlink_old      = 1

workers         = threads # for RT to work

binlog_path     = E:/sphinx-3.1.1/data

}

6. 生成文件

indexer –config demo.conf test1

7. 开启 sphinx 服务

1

searchd –config demo.conf

8.mysql 查询 创建的数据

1

mysql -h127.0.0.1 -P9306

9.PHP 查询数据

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

setServer('127.0.0.1',9312); $k = '酶'; // 搜索的关键字 $sphinx->_limit = 100000; $res = $sphinx->Query($k,'test1'); $ids = array_keys($res['matches']); $ids = implode(',', $ids); $m = mysqli_connect('127.0.0.1','root','root','test','3306'); mysqli_query($m,'set names utf8'); $sql = "select * from questions where id in($ids)"; $res = mysqli_query($m,$sql); while ($row=mysqli_fetch_assoc($res)) {$data[] = $row; } $_arr = []; foreach ($data as $key => $value) {$val = str_replace($k, "{$k}", $value['question']); $arr['id'] = $value['id']; $arr['question'] = $val; $_arr[] = $arr;} $t2 = microtime(true); echo '耗时'.round($t2-$t1,3).'秒'; echo '
';

var_dump($_arr); 


10. 效果



11. 对比 mysql 查询