Coreseek Sphinx statements that create tables and indexes

Source: Internet
Author: User

Said earlier, Coreseek Sphinx mmseg MySQL and so on installation, below say how to use.
One, the Coreseek Sphinx boot, will have one more port, and can login like MySQL, but not login MySQL

The code is as follows Copy Code
[Root@localhost tank]# mysql-h 127.0.0.1-p 9306//is not really connected to MySQL, while the Sphinx index is connected
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), 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark the Oracle Corporation and/or its
Affiliates. Names may 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 (' tank '); This type of writing, the root of the original Sphinx is not the same
+------+--------+------------+------+
| 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; Last retrieved information
+---------------+-------+
| 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; The table here is actually not a real table, it's not created table, it's a Sphinx index.
+--------------+-------------+
| Index | Type |
+--------------+-------------+
| Dist1 | Distributed |
| Myorder | Local |
| RT | RT |
| Tank_test | RT |
| Test1 | Local |
| test1stemmed | Local |
+--------------+-------------+
6 rows in Set (0.00 sec)

Second, create Sphinx index
1, modify/usr/local/sphinx/etc/sphinx.conf

The code is as follows Copy Code
# vim/usr/local/sphinx/etc/sphinx.conf//Add the following

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
}

Notice here that Rt_field is the Retrieve field, Rt_attr_uint is the return field
2, restart Sphinx

The code is as follows Copy Code
# 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, insert the data and view

The code is as follows Copy Code

Mysql> Show tables;
+--------------+-------------+
| Index | Type |
+--------------+-------------+
| Dist1 | Distributed |
| RT | RT |
| Tank_test |      RT | Newly added index
| 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 ', ' tank is tank ', ' technical director ', 1311895260,33);

mysql> INSERT INTO tank_test values (4, ' Tank Zhang ', ' tank is tank ', ' technical director ', 1311895262,34);

Mysql> SELECT * from Tank_test where match (' tank '); The field that matches the search is Rt_field
+------+--------+------------+------+
| ID | Weight | user_id |                 u_id | The field returned is Rt_attr_uint
+------+--------+------------+------+
|   3 | 2230 |   1311895260 | 33 |
|   4 | 1304 |   1311895262 | 34 |
+------+--------+------------+------+
2 rows in Set (0.00 sec)

IDs and weight are returned fields from the system
Here the index is created, show tables can see the new tank_test, with phpMyAdmin or other MySQL database connection tools are not visible, because he is not a real table. Can sphinx actually use a real watch?
Third, create a table and add an index
1, create the real table, insert the data

The code is as follows Copy Code
create TABLE IF Not EXISTS ' orders ' ( 
  ' id ' int (one) not null auto_increment, 
  ' user_id ' int (one) not NULL,  
  ' username ' varchar not null, 
  ' create_time ' datetime not null, 
  ' Pro Duct_name ' varchar not null, 
  ' summary ' text not null, 
 primary KEY (' id ')  
) Engine=innodb DEFAULT Charset=utf8 auto_increment=1; 
 
INSERT into  ' orders ' (' user_id ', ' use Rname ', ' create_time ', ' product_name ', ' summary ') values 
(' 1311895262 ', ' John ', ' 2014-08-01 00:24:54 ', ' tank is Tank ', ' technical director '], 
(' 1311895263 ', ' Tank Zhang Yi ', ' 2014-08-01 00:24:54 ', ' tank is tank ', ' Technical manager '), 
(' 1311895264 ', ' Tank Zhang ', ' 2014-08-01 00:24:54 ', ' tank is Tank ', ' DNB manager '], 
(' 1311895265 ', ' tank ', ' 2014-08-01 ', ', ', ', ' 00:24:54 ') Tank ', ' operational director '); 

Notice here that the 3306 port connected to MySQL is not connected to the Coreseek Sphinx 9306
2, modify/usr/local/sphinx/etc/sphinx.conf, add the following content

The code is as follows Copy Code
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, restart Sphinx

The code is as follows Copy Code
# 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, switch to 9306, retrieve the test

The code is as follows Copy Code
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 (' tank ');
+------+--------+------------+-------------+
| 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)
0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.