在MySQL中使用Sphinx实现多线程搜索的方法

2019-01-05 09:49:45丽君

 


source src1
{
    type = mysql
    sql_query = SELECT id, text FROM table
}
 
source src1p0 : src1
{
    sql_query = SELECT id, text FROM table WHERE id % 3 = 0;
}
 
source src1p1 : src1
{
    sql_query = SELECT id, text FROM table WHERE id % 3 = 1;
}
 
source src1p2 : src1
{
    sql_query = SELECT id, text FROM table WHERE id % 3 = 2;
}
 
index idx1_template
{
    type = plain
    source = src1
}
 
index idx1p0 : idx1_template
{
    source = src0
}
 
index idx1p1 : idx1_template
{
    source = src1
}
 
index idx1p2 : idx1_template
{
    source = src2
}
 
index idx1
{
    type = distributed
    local = idx1p0
    local = idx1p1
    local = idx1p2
}
 
searchd
{
    dist_threads = 3
}

做完这些后,你需要重建索引. 但是现在idx1p0到idx1p2的索引indexer命令可以同步进行.

另外,用不同的操作来分离数据不是最好的办法, 你可以在MYSQL中用一个辅助表来区分它们的范围, 配合 sql_query_range使用或是别的什么, 具体根据你的数据来决定.

写在最后

我一直都很喜欢 Sphinx,Sphinx可以如此容易的扩展到你所需要的足够多的机器上,并且这种方式在很多年前就已经在被使用了。然后,我想,我并没有和我往常一样,利用这个特性来使得在一台机器上的查询变得更快。嗯,这并不是在说它很慢或者其实什么,只是,查询永远不会太快,不是吗?

您可能感兴趣的文章:

Mysql全文搜索match against的用法mysql 模糊搜索的方法介绍Mysql Binlog快速遍历搜索记录及binlog数据查看的方法mysql全文搜索 sql命令的写法mysql 搜索之简单应用php利用scws实现mysql全文搜索功能的方法php mysql like 实现多关键词搜索的方法详细介绍基于MySQL的搜索引擎MySQL-Fullltextmysql 全文搜索 技巧MySQL多层级结构-树搜索介绍mysql中使用sphinx搜索子域名需注意的问题MySQL高效模糊搜索之内置函数locate instr position find_in_set使用详解