찾다
데이터 베이스MySQL 튜토리얼coreseek sphinx 创建表和索引

前面说了,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

[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)

二,创建sphinx索引

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

# 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
}

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

2,重启sphinx

# 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

3,插入数据,并查看

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)

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

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

三,创建表,并添加索引

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

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 坦克','运维总监');

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

2,修改/usr/local/sphinx/etc/sphinx.conf,添加以下内容

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
}

3,重启sphinx

# 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

4,切换到9306,检索测试

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)
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 创建表和索引
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
使用PHP和coreseek开发智能推荐系统的关键技术使用PHP和coreseek开发智能推荐系统的关键技术Aug 08, 2023 pm 11:37 PM

使用PHP和coreseek开发智能推荐系统的关键技术智能推荐系统是现代互联网应用中广泛使用的一种技术,它能够根据用户的兴趣和行为,为用户提供个性化的推荐内容。在本文中,我们将介绍如何使用PHP和coreseek开发一个基于关键技术的智能推荐系统。首先,我们需要了解一下coreseek是什么。coreseek是一个开源的全文检索引擎,它基于sphinx全文检

构建基于PHP和coreseek的播客内容搜索工具构建基于PHP和coreseek的播客内容搜索工具Aug 07, 2023 am 10:40 AM

构建基于PHP和coreseek的播客内容搜索工具随着数字媒体的迅猛发展,播客(podcast)已经成为人们获取信息、娱乐和学习的重要渠道之一。然而,随着越来越多的播客内容产生,如何快速准确地找到感兴趣的内容成为了一个亟待解决的问题。本文将介绍如何使用PHP和coreseek构建一个高效的播客内容搜索工具,并提供相关的代码示例。首先,我们需要明确corese

利用PHP和coreseek实现精准的食谱搜索功能利用PHP和coreseek实现精准的食谱搜索功能Aug 05, 2023 pm 01:16 PM

利用PHP和coreseek实现精准的食谱搜索功能概述:在现如今的快节奏生活中,越来越多的人开始注重自己的饮食健康。找到合适的食谱成为了一种需求。本文将介绍如何利用PHP和coreseek搜索引擎实现精准的食谱搜索功能,帮助用户轻松查找到符合自己需求的食谱。准备工作:在开始之前,我们需要准备一些工具:PHP环境:在本地或者服务器上搭建PHP环境,确保可以运行

使用PHP和coreseek开发强大的电商平台商品搜索引擎使用PHP和coreseek开发强大的电商平台商品搜索引擎Aug 07, 2023 am 08:31 AM

使用PHP和coreseek开发强大的电商平台商品搜索引擎随着电子商务的快速发展,商品搜索引擎成为电商平台中不可或缺的一环。一个强大的商品搜索引擎可以帮助用户快速找到他们想要的商品,提升用户体验,从而增加销售量。本文将介绍如何使用PHP和coreseek开发一个强大的电商平台商品搜索引擎,并提供一些代码示例。一、coreseek简介coreseek是一个基于

利用PHP和coreseek实现精准的用户画像分析功能利用PHP和coreseek实现精准的用户画像分析功能Aug 07, 2023 am 08:57 AM

利用PHP和coreseek实现精准的用户画像分析功能摘要:随着互联网的普及和发展,人们在网络上留下了大量的个人信息,包括浏览历史、购买记录、社交网络等。利用这些数据可以对用户进行精准的画像分析,为企业提供更好的个性化推荐和定制化服务。本文将介绍如何利用PHP和coreseek实现这个功能,并提供代码示例。一、什么是用户画像分析功能?用户画像分析功能是指通过

使用PHP和coreseek打造人才招聘网站的职位搜索功能使用PHP和coreseek打造人才招聘网站的职位搜索功能Aug 06, 2023 pm 04:29 PM

使用PHP和coreseek打造人才招聘网站的职位搜索功能人才招聘网站在现代社会中扮演着重要的角色,为企业提供了一个便捷的方式来寻找合适的员工。而对于求职者来说,拥有一个高效的职位搜索功能也是非常重要的。本文将介绍如何使用PHP和coreseek,一个开源的全文搜索引擎,来为人才招聘网站构建一个功能强大的职位搜索功能。首先,我们需要确保PHP和coresee

使用PHP和coreseek实现智能化的图片搜索功能使用PHP和coreseek实现智能化的图片搜索功能Aug 08, 2023 pm 04:05 PM

使用PHP和coreseek实现智能化的图片搜索功能摘要:本文将介绍如何使用PHP和coreseek开源搜索引擎库来实现智能化的图片搜索功能。通过对图片的特征提取和相似度比较,我们可以在大量图片中快速找到相似的图片。此外,我们还将利用coreseek的全文搜索功能,实现根据关键词搜索图片的功能。关键词:PHP,coreseek,图片搜索,特征提取,相

使用PHP和coreseek构建高效的全文搜索引擎使用PHP和coreseek构建高效的全文搜索引擎Aug 05, 2023 pm 11:06 PM

使用PHP和coreseek构建高效的全文搜索引擎在现代的web应用中,全文搜索引擎是不可或缺的一个组件。它提供了快速和准确的搜索结果,使用户能够轻松地找到所需的信息。本文将介绍如何使用PHP和coreseek构建高效的全文搜索引擎。一、什么是coreseek?coreseek是一个开源的全文搜索引擎。它是由中国的一个开发团队开发的,基于Sphinx引擎的开

See all articles

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

AI Hentai Generator

AI Hentai Generator

AI Hentai를 무료로 생성하십시오.

뜨거운 도구

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse용 SAP NetWeaver 서버 어댑터

Eclipse를 SAP NetWeaver 애플리케이션 서버와 통합합니다.

mPDF

mPDF

mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기