Home Database Mysql Tutorial coreseek sphinx 创建表和索引

coreseek sphinx 创建表和索引

Jun 07, 2016 pm 04:38 PM
co coreseek sphinx create index

前面说了,coreseek sphinx mmseg mysql等的安装,下面说一下怎么使用。 一,coreseek sphinx启动后,会多出一个端口,并且可以像mysql一样登录,但不是登录mysql [root@localhost tank]# mysql -h 127.0.0.1 -P 9306 //不是真的连接mysql,而连接了sphinx in

前面说了,coreseek sphinx mmseg mysql等的安装,下面说一下怎么使用。

一,coreseek sphinx启动后,会多出一个端口,并且可以像mysql一样登录,但不是登录mysql

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

[root@localhost tank]# mysql -h 127.0.0.1 -P 9306      //不是真的连接mysql,而连接了sphinx index

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 1.11-id64-dev (r2540)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select * from tank_test where match('坦克') ;   //这种写法,根原装的sphinx不一样

+------+--------+------------+------+

| id   | weight | user_id    | u_id |

+------+--------+------------+------+

|    3 |   2230 | 1311895260 |   62 |

|    5 |   2230 | 1311895260 |   33 |

|    4 |   1304 | 1311895262 |    0 |

|    6 |   1304 | 1311895262 |   34 |

+------+--------+------------+------+

4 rows in set (0.00 sec)

mysql> show META;     //上次检索的信息

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| total         | 3     |

| total_found   | 3     |

| time          | 0.000 |

| keyword[0]    | test  |

| docs[0]       | 3     |

| hits[0]       | 5     |

+---------------+-------+

6 rows in set (0.00 sec)

mysql> show tables;    //这里的表其实不是真表,也不是create table创建出来的,是sphinx索引

+--------------+-------------+

| Index        | Type        |

+--------------+-------------+

| dist1        | distributed |

| myorder      | local       |

| rt           | rt          |

| tank_test    | rt          |

| test1        | local       |

| test1stemmed | local       |

+--------------+-------------+

6 rows in set (0.00 sec)

Copy after login

二,创建sphinx索引

1,修改/usr/local/sphinx/etc/sphinx.conf

1

2

3

4

5

6

7

8

9

10

11

12

13

14

# vim /usr/local/sphinx/etc/sphinx.conf   //添加以下内容

index tank_test

{

 type            = rt

 path            = /usr/local/sphinx/var/data/rt

 charset_dictpath     = /usr/local/mmseg3/etc/

 charset_type         = zh_cn.utf-8

 ngram_len            = 0

 rt_field        = name

 rt_field        = title

 rt_field        = sub_title

 rt_attr_uint        = user_id

 rt_attr_uint        = uid

}

Copy after login

在这里要注意,rt_field是检索字段,rt_attr_uint是返回字段

2,重启sphinx

1

2

3

# pkill -9 searchd

# /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all

# /usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf

Copy after login
Copy after login

3,插入数据,并查看

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

mysql> show tables;

+--------------+-------------+

| Index        | Type        |

+--------------+-------------+

| dist1        | distributed |

| rt           | rt          |

| tank_test    | rt          |      //新增加的索引

| test1        | local       |

| test1stemmed | local       |

+--------------+-------------+

5 rows in set (0.00 sec)

mysql> desc tank_test;

+-----------+---------+

| Field     | Type    |

+-----------+---------+

| id        | bigint  |

| name      | field   |

| title     | field   |

| sub_title | field   |

| user_id   | integer |

| u_id      | integer |

+-----------+---------+

6 rows in set (0.00 sec)

mysql> insert into tank_test values (3,'坦克','tank is 坦克','技术总监',1311895260,33);

mysql> insert into tank_test values (4,'tank张','tank is 坦克','技术总监',1311895262,34);

mysql> select * from tank_test where match('坦克');    //匹配搜索的字段是rt_field

+------+--------+------------+------+

| id   | weight | user_id    | u_id |                 //返回的字段是rt_attr_uint

+------+--------+------------+------+

|    3 |   2230 | 1311895260 |   33 |

|    4 |   1304 | 1311895262 |   34 |

+------+--------+------------+------+

2 rows in set (0.00 sec)

Copy after login

id和weight是系统自带的返回字段

到这儿索引就创建好了,show tables的时候是可以看新建的tank_test,用phpmyadmin或者其他mysql数据库连接工具根本看不到,原因是他根本不是真实的表。sphinx到底能不能用真实的表呢?

三,创建表,并添加索引

1,创建真实的表,插入数据

1

2

3

4

5

6

7

8

9

10

11

12

13

14

CREATE TABLE IF NOT EXISTS `orders` (

 `id` int(11) NOT NULL AUTO_INCREMENT,

 `user_id` int(11) NOT NULL ,

 `username` varchar(20) NOT NULL,

 `create_time` datetime NOT NULL,

 `product_name` varchar(20) NOT NULL,

 `summary` text NOT NULL,

 PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

INSERT INTO  `orders` (`user_id` ,`username` ,`create_time` ,`product_name` ,`summary`) VALUES

('1311895262','张三','2014-08-01 00:24:54','tank is 坦克','技术总监'),

('1311895263','tank张二','2014-08-01 00:24:54','tank is 坦克','技术经理'),

('1311895264','tank张一','2014-08-01 00:24:54','tank is 坦克','DNB经理'),

('1311895265','tank张','2014-08-01 00:24:54','tank is 坦克','运维总监');

Copy after login

在这里要注意,是连接mysql的3306端口,不是连接coreseek sphinx的9306

2,修改/usr/local/sphinx/etc/sphinx.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

source order

{

 type            = mysql

 sql_host        = localhost

 sql_user        = root

 sql_pass        =

 sql_db            = test

 sql_query_pre        = SET NAMES utf8

 sql_query        = \

 SELECT id, user_id, username, UNIX_TIMESTAMP(create_time) AS create_time, product_name, summary  \

 FROM orders

 sql_attr_uint        = user_id

 sql_attr_timestamp    = create_time

 sql_ranged_throttle    = 0

 sql_query_info    = SELECT * FROM orders WHERE id=$id

}

index myorder

{

 source            = order

 path            = /usr/local/sphinx/var/data/myorder

 docinfo        = extern

 mlock            = 0

 morphology        = none

 min_word_len        = 1

 charset_dictpath    = /usr/local/mmseg3/etc/

 charset_type        = zh_cn.utf-8

 ngram_len            = 0

 html_strip        = 0

}

Copy after login

3,重启sphinx

1

2

3

# pkill -9 searchd

# /usr/local/sphinx/bin/indexer --config /usr/local/sphinx/etc/sphinx.conf --all

# /usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf

Copy after login
Copy after login

4,切换到9306,检索测试

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

mysql> show tables;

+--------------+-------------+

| Index        | Type        |

+--------------+-------------+

| dist1        | distributed |

| myorder      | local       |

| rt           | rt          |

| tank_test    | rt          |

| test1        | local       |

| test1stemmed | local       |

+--------------+-------------+

6 rows in set (0.00 sec)

mysql> desc myorder;

+--------------+-----------+

| Field        | Type      |

+--------------+-----------+

| id           | bigint    |

| username     | field     |

| product_name | field     |

| summary      | field     |

| user_id      | integer   |

| create_time  | timestamp |

+--------------+-----------+

6 rows in set (0.00 sec)

mysql> select * from myorder where match('坦克');

+------+--------+------------+-------------+

| id   | weight | user_id    | create_time |

+------+--------+------------+-------------+

|    5 |   1304 | 1311895262 |  1407081600 |

|    6 |   1304 | 1311895263 |  1406823894 |

|    7 |   1304 | 1311895264 |  1406823894 |

|    8 |   1304 | 1311895265 |  1406823894 |

+------+--------+------------+-------------+

4 rows in set (0.00 sec)

Copy after login
coreseek sphinx 创建表和索引 前面说了,coreseek sphinx mmseg mysql等的安装,下面说一下怎么使用。 一,coreseek sphinx启动后,会多出一个端口,并且可以像mysql一样登录,但不是登录mysql [root@localhost tank]# mysql -h 127.0.0.1 -P 9306 //不是真的连接mysql,而连接了sphinx index Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 1.11-id64-dev (r2540) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or [...]coreseek sphinx 创建表和索引
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to create a folder on Realme Phone? How to create a folder on Realme Phone? Mar 23, 2024 pm 02:30 PM

Title: Realme Phone Beginner’s Guide: How to Create Folders on Realme Phone? In today's society, mobile phones have become an indispensable tool in people's lives. As a popular smartphone brand, Realme Phone is loved by users for its simple and practical operating system. In the process of using Realme phones, many people may encounter situations where they need to organize files and applications on their phones, and creating folders is an effective way. This article will introduce how to create folders on Realme phones to help users better manage their phone content. No.

How to create pixel art in GIMP How to create pixel art in GIMP Feb 19, 2024 pm 03:24 PM

This article will interest you if you are interested in using GIMP for pixel art creation on Windows. GIMP is a well-known graphics editing software that is not only free and open source, but also helps users create beautiful images and designs easily. In addition to being suitable for beginners and professional designers alike, GIMP can also be used to create pixel art, a form of digital art that utilizes pixels as the only building blocks for drawing and creating. How to Create Pixel Art in GIMP Here are the main steps to create pixel pictures using GIMP on a Windows PC: Download and install GIMP, then launch the application. Create a new image. Resize width and height. Select the pencil tool. Set the brush type to pixels. set up

How to create a family with Gree+ How to create a family with Gree+ Mar 01, 2024 pm 12:40 PM

Many friends expressed that they want to know how to create a family in Gree+ software. Here is the operation method for you. Friends who want to know more, come and take a look with me. First, open the Gree+ software on your mobile phone and log in. Then, in the options bar at the bottom of the page, click the "My" option on the far right to enter the personal account page. 2. After coming to my page, there is a "Create Family" option under "Family". After finding it, click on it to enter. 3. Next jump to the page to create a family, enter the family name to be set in the input box according to the prompts, and click the "Save" button in the upper right corner after entering it. 4. Finally, a "save successfully" prompt will pop up at the bottom of the page, indicating that the family has been successfully created.

How to create a Gantt chart using Highcharts How to create a Gantt chart using Highcharts Dec 17, 2023 pm 07:23 PM

How to use Highcharts to create a Gantt chart requires specific code examples. Introduction: The Gantt chart is a chart form commonly used to display project progress and time management. It can visually display the start time, end time and progress of the task. Highcharts is a powerful JavaScript chart library that provides rich chart types and flexible configuration options. This article will introduce how to use Highcharts to create a Gantt chart and give specific code examples. 1. Highchart

What are the Oracle index types? What are the Oracle index types? Nov 16, 2023 am 09:59 AM

Oracle index types include: 1. B-Tree index; 2. Bitmap index; 3. Function index; 4. Hash index; 5. Reverse key index; 6. Local index; 7. Global index; 8. Domain index ; 9. Bitmap connection index; 10. Composite index. Detailed introduction: 1. B-Tree index is a self-balancing tree data structure that can efficiently support concurrent operations. In Oracle database, B-Tree index is the most commonly used index type; 2. Bit Graph index is an index type based on bitmap algorithm and so on.

A first look at Django: Create your first Django project using the command line A first look at Django: Create your first Django project using the command line Feb 19, 2024 am 09:56 AM

Start the journey of Django project: start from the command line and create your first Django project. Django is a powerful and flexible web application framework. It is based on Python and provides many tools and functions needed to develop web applications. This article will lead you to create your first Django project starting from the command line. Before starting, make sure you have Python and Django installed. Step 1: Create the project directory First, open the command line window and create a new directory

How to Create a Contact Poster for Your iPhone How to Create a Contact Poster for Your iPhone Mar 02, 2024 am 11:30 AM

In iOS17, Apple has added a contact poster feature to its commonly used Phone and Contacts apps. This feature allows users to set personalized posters for each contact, making the address book more visual and personal. Contact posters can help users identify and locate specific contacts more quickly, improving user experience. Through this feature, users can add specific pictures or logos to each contact according to their preferences and needs, making the address book interface more vivid. Apple in iOS17 provides iPhone users with a novel way to express themselves, and added a personalizable contact poster. The Contact Poster feature allows you to display unique, personalized content when calling other iPhone users. you

How to create mdf file How to create mdf file Feb 18, 2024 pm 01:36 PM

MDF file is a common database file format and it is one of the main files of Microsoft SQL Server database. In database management systems, MDF files are used to save the main data of the database, including tables, indexes, stored procedures, etc. Creating an MDF file is one of the key steps in creating a database. Some common methods will be introduced below. Using SQLServerManagementStudio(SSMS)SQLServerManag

See all articles